Skip to content

Improve missing Terraform config errors#12070

Open
preko-p wants to merge 2 commits into
radius-project:mainfrom
preko-p:9477-terraform-missing-config-error
Open

Improve missing Terraform config errors#12070
preko-p wants to merge 2 commits into
radius-project:mainfrom
preko-p:9477-terraform-missing-config-error

Conversation

@preko-p

@preko-p preko-p commented Jun 8, 2026

Copy link
Copy Markdown

Description

This improves Terraform recipe inspection so a missing downloaded module directory, missing subdirectory, or module directory without Terraform configuration files returns an actionable error:

The Terraform configuration in location <templatePath> is not found.

Malformed Terraform configuration still flows through the existing tfconfig.LoadModule diagnostics as error loading the module: ....

Type of change

  • This pull request fixes a bug in Radius and has an approved issue (issue link required).

Fixes: #9477

Contributor checklist

Please verify that the PR meets the following requirements, where applicable:

  • An overview of proposed schema changes is included in a linked GitHub issue.
    • Yes
    • Not applicable
  • A design document is added or updated under eng/design-notes/ in this repository, if new APIs are being introduced.
    • Yes
    • Not applicable
  • The design document has been reviewed and approved by Radius maintainers/approvers.
    • Yes
    • Not applicable
  • A PR for resource-types-contrib is created, if resource types or recipes are affected by the changes in this PR.
    • Yes
    • Not applicable
  • A PR for dashboard is created, if the Radius Dashboard is affected by the changes in this PR.
    • Yes
    • Not applicable
  • A PR for the documentation repository is created, if the changes in this PR affect the documentation or any user facing updates are made.
    • Yes
    • Not applicable

Verification

  • git diff --check
  • docker run --rm golang:1.26.4 go version
  • docker run --rm --user "$(id -u):$(id -g)" -v "$PWD":/repo -w /repo golang:1.26.4 gofmt -w pkg/recipes/terraform/module.go pkg/recipes/terraform/module_test.go
  • docker run --rm --user "$(id -u):$(id -g)" -v "$PWD":/repo -w /repo -e HOME=/tmp -e GOCACHE=/tmp/gocache -e GOMODCACHE=/tmp/gomodcache golang:1.26.4 go test ./pkg/recipes/terraform -run Test_InspectTFModuleConfig
  • docker run --rm --user "$(id -u):$(id -g)" -v "$PWD":/repo -w /repo -e HOME=/tmp -e GOCACHE=/tmp/gocache -e GOMODCACHE=/tmp/gomodcache golang:1.26.4 go test ./pkg/recipes/terraform ./pkg/recipes/driver/terraform

AI assistance disclosure

This PR was prepared with AI assistance and reviewed locally before submission.

Copilot AI review requested due to automatic review settings June 8, 2026 17:36
@preko-p preko-p requested review from a team as code owners June 8, 2026 17:36
@preko-p preko-p requested a deployment to external-contributor-approval June 8, 2026 17:37 — with GitHub Actions Waiting

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR tightens Terraform module inspection by detecting missing Terraform configuration files up front and improving test coverage for missing/invalid module scenarios.

Changes:

  • Added a pre-check for presence of .tf / .tf.json files before calling tfconfig.LoadModule.
  • Introduced a standardized error message for missing module configuration.
  • Expanded unit tests to cover missing submodules, missing config, and invalid config cases with optional exact error matching.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
pkg/recipes/terraform/module.go Adds hasTerraformConfigFiles and returns a clearer “config not found” error before attempting module load.
pkg/recipes/terraform/module_test.go Extends table-driven tests with setup hooks and exact error assertions for new failure modes.

Comment on lines +160 to +162
moduleDir := filepath.Join(workingDir, moduleRootDir, "test-module-no-config")
require.NoError(t, os.MkdirAll(filepath.Join(moduleDir, "main.tf"), 0755))
require.NoError(t, os.WriteFile(filepath.Join(moduleDir, "README.md"), []byte("no terraform configuration"), 0644))
Comment on lines +187 to +204
entries, err := os.ReadDir(moduleDir)
if err != nil {
return false, err
}
for _, entry := range entries {
info, err := entry.Info()
if err != nil {
return false, err
}
if !info.Mode().IsRegular() {
continue
}

name := entry.Name()
if strings.HasSuffix(name, ".tf") || strings.HasSuffix(name, ".tf.json") {
return true, nil
}
}
Signed-off-by: preko-p <278021202+preko-p@users.noreply.github.com>
@preko-p preko-p force-pushed the 9477-terraform-missing-config-error branch from 6d225dc to 03c5165 Compare June 9, 2026 19:04
@preko-p preko-p requested a deployment to external-contributor-approval June 9, 2026 19:04 — with GitHub Actions Waiting
@preko-p preko-p requested a deployment to external-contributor-approval June 10, 2026 16:24 — with GitHub Actions Waiting
@preko-p

preko-p commented Jun 10, 2026

Copy link
Copy Markdown
Author

Thanks, addressed both review comments in a follow-up push.

What changed:

  • Fixed the no-config test setup so it creates the module directory, not a directory named main.tf.
  • Switched the file scan to entry.Type().IsRegular() to avoid the extra Info() stat.
  • Added an explicit regression case for a directory named main.tf, so directory entries are still ignored even if their name looks like Terraform config.

Verification run locally through the Go 1.26.4 Docker image:

  • gofmt on the changed Go files
  • git diff --check
  • go test ./pkg/recipes/terraform -run Test_InspectTFModuleConfig
  • go test ./pkg/recipes/terraform ./pkg/recipes/driver/terraform

Signed-off-by: preko-p <278021202+preko-p@users.noreply.github.com>
@preko-p preko-p force-pushed the 9477-terraform-missing-config-error branch from 1b8c09b to 89ad95a Compare June 10, 2026 16:29
@preko-p preko-p temporarily deployed to external-contributor-approval June 10, 2026 16:29 — with GitHub Actions Inactive
@radius-functional-tests

radius-functional-tests Bot commented Jun 10, 2026

Copy link
Copy Markdown

Radius functional test overview

🔍 Go to test action run

Click here to see the test run details
Name Value
Repository preko-p/radius
Commit ref 89ad95a
Unique ID funced606d2c0b
Image tag pr-funced606d2c0b
  • gotestsum 1.13.0
  • KinD: v0.29.0
  • Dapr: 1.14.4
  • Azure KeyVault CSI driver: 1.4.2
  • Azure Workload identity webhook: 1.3.0
  • Bicep recipe location ghcr.io/radius-project/dev/test/testrecipes/test-bicep-recipes/<name>:pr-funced606d2c0b
  • Terraform recipe location http://tf-module-server.radius-test-tf-module-server.svc.cluster.local/<name>.zip (in cluster)
  • applications-rp test image location: ghcr.io/radius-project/dev/applications-rp:pr-funced606d2c0b
  • dynamic-rp test image location: ghcr.io/radius-project/dev/dynamic-rp:pr-funced606d2c0b
  • controller test image location: ghcr.io/radius-project/dev/controller:pr-funced606d2c0b
  • ucp test image location: ghcr.io/radius-project/dev/ucpd:pr-funced606d2c0b
  • deployment-engine test image location: ghcr.io/radius-project/deployment-engine:latest

Test Status

⌛ Building Radius and pushing container images for functional tests...
✅ Container images build succeeded
⌛ Publishing Bicep Recipes for functional tests...
✅ Recipe publishing succeeded
⌛ Starting corerp-cloud functional tests...
⌛ Starting ucp-cloud functional tests...
✅ ucp-cloud functional tests succeeded
✅ corerp-cloud functional tests succeeded

@DariuszPorowski DariuszPorowski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good, targeted fix! thank you

@willtsai @zachcasper @nicolejms The hardcoded .terraform/modules breaks if TF_DATA_DIR is set (tfexec inherits the pod env). Pre-existing, out of scope here, but flagging as latent tech debt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong error when Terraform configuration is not found

3 participants