Skip to content

[TF-38853] Validate provider versions in config match the lock file - #38829

Merged
austinvalle merged 17 commits into
mainfrom
arunatibm/TF-38853
Aug 5, 2026
Merged

[TF-38853] Validate provider versions in config match the lock file#38829
austinvalle merged 17 commits into
mainfrom
arunatibm/TF-38853

Conversation

@arunatibm

@arunatibm arunatibm commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes issue TF-38853

For a Stack configuration, if there is a discrepancy between the provider version declared in the component configuration and the the version in the .terraform.lock.hcl, the Stack will execute deployment runs. This is a problem since we have a split between the preferred version and the locked version and leads to confusion and inconsistency.
What is desired is that when the configured version and locked version differ, an error diagnostic must be generated. This will allow the practitioner to inspect, decide and fix the provider versions and then recreate the lock before executing a deployment run.

To recreate this issue, edit the provider version in the configuration file but do not regenerate the lock file. Then create a stack with this configuration. The deployment run will complete successfully.

The bulk of the functional changes are in these files, and the remaining are to fix test inputs because the new validations will fail.

- internal/stacks/stackconfig/provider_requirements.go
- internal/stacks/stackruntime/internal/stackeval/provider_config.go
- internal/stacks/stackruntime/internal/stackeval/provider_expressions.go
- internal/stacks/stackruntime/internal/stackeval/stack_config.go
- internal/stacks/stackruntime/internal/stackeval/walk_static.go

Testing

Created a mismatch between the lock and the configuration and ran $ terraform stacks validate and we see the validation errors in the command response.

╷
│ Error: Provider version doesn't match the lockfile
│
│   on ./components.tfcomponent.hcl line 15:
│   15: provider "random" "this" {}
│
│ Provider "registry.terraform.io/hashicorp/random" is locked at version 3.5.1 in the dependency lockfile, but the configuration's version constraints (~> 3.6.0) do not allow that version. This usually means the version constraints were changed after the lockfile was generated. Please run `terraform stacks providers lock` to update the lockfile and run this operation again with an updated configuration.
╵
╷
│ Error: Provider version doesn't match the lockfile
│
│   on ./components.tfcomponent.hcl line 16:
│   16: provider "random" "random-app-cache" {}
│
│ Provider "registry.terraform.io/hashicorp/random" is locked at version 3.5.1 in the dependency lockfile, but the configuration's version constraints (~> 3.6.0) do not allow that version. This usually means the version constraints were changed after the lockfile was generated. Please run `terraform stacks providers lock` to update the lockfile and run this operation again with an updated configuration.
╵
╷
│ Error: Provider version doesn't match the lockfile
│
│   on ./components.tfcomponent.hcl line 17:
│   17: provider "random" "random-app-rev-proxy" {}
│
│ Provider "registry.terraform.io/hashicorp/random" is locked at version 3.5.1 in the dependency lockfile, but the configuration's version constraints (~> 3.6.0) do not allow that version. This usually means the version constraints were changed after the lockfile was generated. Please run `terraform stacks providers lock` to update the lockfile and run this operation again with an updated configuration.
╵
╷
│ Error: Provider version doesn't match the lockfile
│
│   on ./components.tfcomponent.hcl line 18:
│   18: provider "random" "random-app-payment" {}
│
│ Provider "registry.terraform.io/hashicorp/random" is locked at version 3.5.1 in the dependency lockfile, but the configuration's version constraints (~> 3.6.0) do not allow that version. This usually means the version constraints were changed after the lockfile was generated. Please run `terraform stacks providers lock` to update the lockfile and run this operation again with an updated configuration.
╵
Failure! Terraform Stacks configuration is not valid, please check and fix the errors printed above.

Snippet of the configuration with the provider declarations

required_providers {
  random = {
    source  = "hashicorp/random"
    version = "~> 3.6.0"
  }
}

provider "random" "this" {}
provider "random" "random-app-cache" {}
provider "random" "random-app-rev-proxy" {}
provider "random" "random-app-payment" {}

Snippet from the lock file

provider "registry.terraform.io/hashicorp/random" {
  version = "3.5.1"

Target Release

Next upcoming minor release

1.17.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

N/A

CHANGELOG entry

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

@arunatibm
arunatibm marked this pull request as ready for review July 28, 2026 18:12
@arunatibm
arunatibm requested a review from a team as a code owner July 28, 2026 18:12
@NicoletaPopoviciu

Copy link
Copy Markdown

@tommyokeefe please assist w a review when core team has the capacity; thank you

@austinvalle austinvalle 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.

Thanks for the PR @arunatibm 👋🏻 !

These changes are looking good, I just left some minor comments to consider 👍🏻

Comment thread .changes/v1.17/BUG FIXES-20260728-105047.yaml Outdated
Comment thread internal/stacks/stackconfig/provider_requirements.go Outdated
Comment thread internal/stacks/stackruntime/internal/stackeval/provider_config.go Outdated
Comment thread internal/stacks/stackruntime/validate_test.go
@arunatibm

Copy link
Copy Markdown
Contributor Author

Addressed changes from the review.

@arunatibm
arunatibm requested a review from austinvalle August 4, 2026 21:28
austinvalle
austinvalle previously approved these changes Aug 5, 2026
@austinvalle austinvalle added skip-changelog-check 1.16-backport If you add this label to a PR before merging, backport-assistant will open a new PR once merged and removed skip-changelog-check labels Aug 5, 2026
@austinvalle
austinvalle merged commit 53cb118 into main Aug 5, 2026
9 checks passed
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.

3 participants