Skip to content

Improve missing Terraform config errors#12070

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

Improve missing Terraform config errors#12070
preko-p wants to merge 1 commit 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.

Signed-off-by: preko-p <278021202+preko-p@users.noreply.github.com>
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
}
}
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