From 544c2932ce75ed8d4754b57211a46c1daa5e8dca Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Fri, 9 Nov 2018 15:08:39 -0800 Subject: [PATCH] command: Fix TestInit_checkRequiredVersion In prior refactoring we lost the required core version check from "terraform init", which we restore here. Additionally, this test used to have an incorrect name that suggested it was testing something in the "getProvider" codepath, but version checking happens regardless of what other options are selected. --- command/init.go | 18 ++++++++++++++++++ command/init_test.go | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) 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)