Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

terraform test: Disallow version constraints within test files #35161

Merged
merged 1 commit into from
May 16, 2024

Conversation

liamcervante
Copy link
Member

This PR fixes a bug in which non-hashicorp providers defined within test files and referenced within alternate testing modules were wrongly being assumed as hashicorp providers and were failing to install.

We do this by no longer actually looking at test files for provider information. Since test files don't actually use providers directly and just hand them off to the main files, we don't need to consider the provider blocks in test files when calculating provider address and version constraints. This simplifies the provider constraint gathering and solves the underlying bug since the provider types don't need to be assumed within the test file at all now. It does mean that version constraints within provider blocks within test files will no longer be consulted. As such, I've updated the configuration parsing so that it errors if test files contain version constraints. (as an aside, I wish I'd done this when we first launched the test framework but oh well should have been braver)

Unfortunately, this is a breaking change so I won't backport this change. Instead, we should launch it in 1.9.0 with warnings in the changelog and upgrade guide. There is a fairly simple workaround in 1.8 currently so there is no urgency requiring a quick backport.

I did notice that it's been 4 years since we deprecated the version constraint within provider blocks at all, so maybe we could remove it entirely? I suspect this is a bad idea, as modules with embedded version constraints will just start completely failing to load and there would generally nothing a user could do to fix this as the module maybe downloaded remotely. Note, that the testing framework doesn't have this issue as it doesn't recursively load testing files from linked modules, so there will never be a case where the user can't fix this simply by updating their own configuration.

Fixes #35160

Target Release

1.9.0

Draft CHANGELOG entry

BUG FIXES

  • terraform test: Fix bug in which non-Hashicorp providers required by testing modules and initialised within the test files were assigned incorrect registry addresses.

UPGRADE NOTES

  • terraform test: It is no longer valid to specify version constraints within provider blocks within .tftest.hcl files. Instead, version constraints must be supplied within the main configuration where the provider is in use.

@liamcervante liamcervante requested a review from a team May 15, 2024 14:04
@liamcervante liamcervante merged commit 48fc2d3 into main May 16, 2024
6 checks passed
@liamcervante liamcervante deleted the liamcervante/35160 branch May 16, 2024 11:15
Copy link

Reminder for the merging maintainer: if this is a user-visible change, please update the changelog on the appropriate release branch.

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.

Tf test 1.8.3 - Cannot resolve properly provider definition "Provider type mismatch"
2 participants