Skip to content

Support referencing modules with dynamic sources in Terraform Test - #38950

Open
dbanck wants to merge 6 commits into
mainfrom
dbanck/dynamic-test-support
Open

Support referencing modules with dynamic sources in Terraform Test#38950
dbanck wants to merge 6 commits into
mainfrom
dbanck/dynamic-test-support

Conversation

@dbanck

@dbanck dbanck commented Jul 30, 2026

Copy link
Copy Markdown
Member

This PR updates the way we load modules in Terraform Test. Instead of calling buildTestModules as part of FinalizeConfig, we now do this as part of the init graph. This allows us to reuse the existing module resolution logic for test modules as well.

We gather the values for the const variables from *.tfvars and CLI sources. This approach currently does NOT support supplying values for const variables via variables blocks inside test files. Supporting these would require another resolution step, since the variable expressions can contain references. As const variables need to remain constant throughout all test runs (otherwise you would need to run init again), it needs to be assessed whether supporting variables is necessary.

There is still some legacy code around BuildConfig in place and I'm planning to remove it in a follow-up PR.

Fixes #38788

Target Release

1.16.x

Rollback Plan

  • If a change needs to be reverted, we will roll out an update to the code within 7 days.

Changes to Security Controls

Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.

CHANGELOG entry

  • This change is user-facing and I added a changelog entry.
  • This change is not user-facing.

@dbanck dbanck added the 1.16-backport If you add this label to a PR before merging, backport-assistant will open a new PR once merged label Jul 30, 2026
@dbanck
dbanck force-pushed the dbanck/dynamic-test-support branch from 81585da to 5087006 Compare July 30, 2026 14:14
@dbanck dbanck changed the title Support dynamic module sources in Terraform test modules Support referencing modules with dynamic sources in Terraform Test Jul 30, 2026
@dbanck
dbanck marked this pull request as ready for review July 30, 2026 14:29
@dbanck
dbanck requested a review from a team as a code owner July 30, 2026 14:29
@dbanck
dbanck force-pushed the dbanck/dynamic-test-support branch from 5087006 to 1d6d7eb Compare July 30, 2026 14:30
dbanck added 6 commits July 31, 2026 17:37
This prefix can be used to install test configurations under specific
paths.
Instead of calling buildTestModules as part of FinalizeConfig, we now do
this as part of the init graph. This allows us to reuse the existing
module resolution logic for test modules as well.

The legacy finalize config method can be removed as part of removing
BuildConfig.
This slowly gets rid of the legacy module installer calls without an
initializer. Which will allow us to remove installDescendantModules at
some point.
@dbanck
dbanck force-pushed the dbanck/dynamic-test-support branch from 1d6d7eb to f608c50 Compare July 31, 2026 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1.16-backport If you add this label to a PR before merging, backport-assistant will open a new PR once merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Terraform fails for const=true variables in module source when .tftest.hcl files are present

1 participant