]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blame - vendor/github.com/hashicorp/terraform/terraform/version_required.go
Upgrade to 0.12
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / hashicorp / terraform / terraform / version_required.go
CommitLineData
bae9f6d2
JC
1package terraform
2
3import (
4 "fmt"
5
107c1cdb
ND
6 "github.com/hashicorp/hcl2/hcl"
7 "github.com/hashicorp/terraform/tfdiags"
8
9 "github.com/hashicorp/terraform/configs"
15c0b25d
AP
10
11 tfversion "github.com/hashicorp/terraform/version"
bae9f6d2
JC
12)
13
107c1cdb
ND
14// CheckCoreVersionRequirements visits each of the modules in the given
15// configuration tree and verifies that any given Core version constraints
16// match with the version of Terraform Core that is being used.
bae9f6d2 17//
107c1cdb
ND
18// The returned diagnostics will contain errors if any constraints do not match.
19// The returned diagnostics might also return warnings, which should be
20// displayed to the user.
21func CheckCoreVersionRequirements(config *configs.Config) tfdiags.Diagnostics {
22 if config == nil {
bae9f6d2
JC
23 return nil
24 }
25
107c1cdb
ND
26 var diags tfdiags.Diagnostics
27 module := config.Module
28
29 for _, constraint := range module.CoreVersionConstraints {
30 if !constraint.Required.Check(tfversion.SemVer) {
31 switch {
32 case len(config.Path) == 0:
33 diags = diags.Append(&hcl.Diagnostic{
34 Severity: hcl.DiagError,
35 Summary: "Unsupported Terraform Core version",
36 Detail: fmt.Sprintf(
37 "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.",
38 tfversion.String(),
39 ),
40 Subject: &constraint.DeclRange,
41 })
42 default:
43 diags = diags.Append(&hcl.Diagnostic{
44 Severity: hcl.DiagError,
45 Summary: "Unsupported Terraform Core version",
46 Detail: fmt.Sprintf(
47 "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.",
48 config.Path, config.SourceAddr, tfversion.String(),
49 ),
50 Subject: &constraint.DeclRange,
51 })
52 }
53 }
bae9f6d2
JC
54 }
55
107c1cdb
ND
56 for _, c := range config.Children {
57 childDiags := CheckCoreVersionRequirements(c)
58 diags = diags.Append(childDiags)
bae9f6d2
JC
59 }
60
107c1cdb 61 return diags
bae9f6d2 62}