6 "github.com/hashicorp/go-version"
7 "github.com/hashicorp/terraform/config"
8 "github.com/hashicorp/terraform/config/module"
11 // checkRequiredVersion verifies that any version requirements specified by
12 // the configuration are met.
14 // This checks the root module as well as any additional version requirements
15 // from child modules.
17 // This is tested in context_test.go.
18 func checkRequiredVersion(m *module.Tree) error {
20 for _, c := range m.Children() {
21 if err := checkRequiredVersion(c); err != nil {
26 var tf *config.Terraform
27 if c := m.Config(); c != nil {
31 // If there is no Terraform config or the required version isn't set,
33 if tf == nil || tf.RequiredVersion == "" {
39 if path := normalizeModulePath(m.Path()); len(path) > 1 {
40 module = modulePrefixStr(path)
43 // Check this version requirement of this module
44 cs, err := version.NewConstraint(tf.RequiredVersion)
47 "%s: terraform.required_version %q syntax error: %s",
49 tf.RequiredVersion, err)
52 if !cs.Check(SemVersion) {
54 "The currently running version of Terraform doesn't meet the\n"+
55 "version requirements explicitly specified by the configuration.\n"+
56 "Please use the required version or update the configuration.\n"+
57 "Note that version requirements are usually set for a reason, so\n"+
58 "we recommend verifying with whoever set the version requirements\n"+
59 "prior to making any manual changes.\n\n"+
61 " Required version: %s\n"+
62 " Current version: %s",