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: Fix required version constraint diags #25898

Merged
merged 1 commit into from
Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions command/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1343,6 +1343,13 @@ func TestInit_checkRequiredVersion(t *testing.T) {
if code := c.Run(args); code != 1 {
t.Fatalf("got exit status %d; want 1\nstderr:\n%s\n\nstdout:\n%s", code, ui.ErrorWriter.String(), ui.OutputWriter.String())
}
errStr := ui.ErrorWriter.String()
if !strings.Contains(errStr, `required_version = "~> 0.9.0"`) {
t.Fatalf("output should point to unmet version constraint, but is:\n\n%s", errStr)
}
if strings.Contains(errStr, `required_version = ">= 0.13.0"`) {
t.Fatalf("output should not point to met version constraint, but is:\n\n%s", errStr)
}
}

func TestInit_providerLockFile(t *testing.T) {
Expand Down
4 changes: 4 additions & 0 deletions command/testdata/init-check-required-version/main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
terraform {
required_version = "~> 0.9.0"
}

terraform {
required_version = ">= 0.13.0"
}
4 changes: 2 additions & 2 deletions terraform/version_required.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func CheckCoreVersionRequirements(config *configs.Config) tfdiags.Diagnostics {
"This configuration does not support Terraform version %s. To proceed, either choose another supported Terraform version or update this version constraint. Version constraints are normally set for good reason, so updating the constraint may lead to other errors or unexpected behavior.",
tfversion.String(),
),
Subject: &constraint.DeclRange,
Subject: constraint.DeclRange.Ptr(),
})
default:
diags = diags.Append(&hcl.Diagnostic{
Expand All @@ -47,7 +47,7 @@ func CheckCoreVersionRequirements(config *configs.Config) tfdiags.Diagnostics {
"Module %s (from %s) does not support Terraform version %s. To proceed, either choose another supported Terraform version or update this version constraint. Version constraints are normally set for good reason, so updating the constraint may lead to other errors or unexpected behavior.",
config.Path, config.SourceAddr, tfversion.String(),
),
Subject: &constraint.DeclRange,
Subject: constraint.DeclRange.Ptr(),
})
}
}
Expand Down