diff --git a/command/init.go b/command/init.go index 1614a604f..e8a8c24e1 100644 --- a/command/init.go +++ b/command/init.go @@ -257,6 +257,24 @@ func (c *InitCommand) Run(args []string) int { } } + // With modules now installed, we should be able to load the whole + // configuration and check the core version constraints. + config, confDiags := c.loadConfig(path) + diags = diags.Append(confDiags) + if confDiags.HasErrors() { + // Since this may be the user's first ever interaction with Terraform, + // we'll provide some additional context in this case. + c.Ui.Error(strings.TrimSpace(errInitConfigError)) + c.showDiagnostics(diags) + return 1 + } + confDiags = terraform.CheckCoreVersionRequirements(config) + diags = diags.Append(confDiags) + if confDiags.HasErrors() { + c.showDiagnostics(diags) + return 1 + } + if back == nil { // If we didn't initialize a backend then we'll try to at least // instantiate one. This might fail if it wasn't already initalized diff --git a/command/init_test.go b/command/init_test.go index 41e0d0ec6..d50baebd6 100644 --- a/command/init_test.go +++ b/command/init_test.go @@ -959,7 +959,7 @@ func TestInit_getProviderHaveLegacyVersion(t *testing.T) { } } -func TestInit_getProviderCheckRequiredVersion(t *testing.T) { +func TestInit_checkRequiredVersion(t *testing.T) { // Create a temporary working directory that is empty td := tempDir(t) copy.CopyDir(testFixturePath("init-check-required-version"), td)