Merge pull request #25898 from hashicorp/alisdair/fix-required-version-diags

terraform: Fix required version constraint diags
This commit is contained in:
Alisdair McDiarmid 2020-08-19 11:26:03 -04:00 committed by GitHub
commit 30c7dfca62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 2 deletions

View File

@ -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) {

View File

@ -1,3 +1,7 @@
terraform {
required_version = "~> 0.9.0"
}
terraform {
required_version = ">= 0.13.0"
}

View File

@ -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{
@ -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(),
})
}
}