6 "github.com/hashicorp/go-version"
7 "github.com/hashicorp/terraform/config"
8 "github.com/hashicorp/terraform/config/module"
10 tfversion "github.com/hashicorp/terraform/version"
13 // CheckRequiredVersion verifies that any version requirements specified by
14 // the configuration are met.
16 // This checks the root module as well as any additional version requirements
17 // from child modules.
19 // This is tested in context_test.go.
20 func CheckRequiredVersion(m *module.Tree) error {
22 for _, c := range m.Children() {
23 if err := CheckRequiredVersion(c); err != nil {
28 var tf *config.Terraform
29 if c := m.Config(); c != nil {
33 // If there is no Terraform config or the required version isn't set,
35 if tf == nil || tf.RequiredVersion == "" {
41 if path := normalizeModulePath(m.Path()); len(path) > 1 {
42 module = modulePrefixStr(path)
45 // Check this version requirement of this module
46 cs, err := version.NewConstraint(tf.RequiredVersion)
49 "%s: terraform.required_version %q syntax error: %s",
51 tf.RequiredVersion, err)
54 if !cs.Check(tfversion.SemVer) {
56 "The currently running version of Terraform doesn't meet the\n"+
57 "version requirements explicitly specified by the configuration.\n"+
58 "Please use the required version or update the configuration.\n"+
59 "Note that version requirements are usually set for a reason, so\n"+
60 "we recommend verifying with whoever set the version requirements\n"+
61 "prior to making any manual changes.\n\n"+
63 " Required version: %s\n"+
64 " Current version: %s",