command: Fix TestInit_getProvider

After all of the refactoring we were no longer checking the Terraform
version field in a state file, causing this test to fail.

This restores that check, though with a slightly different error message.
This commit is contained in:
Martin Atkins 2018-11-09 15:06:00 -08:00
parent f6d468ffd5
commit 9ba399bca8
2 changed files with 10 additions and 1 deletions

View File

@ -691,7 +691,7 @@ func TestInit_getProvider(t *testing.T) {
}
errMsg := ui.ErrorWriter.String()
if !strings.Contains(errMsg, "future Terraform version") {
if !strings.Contains(errMsg, "which is newer than current") {
t.Fatal("unexpected error:", errMsg)
}
})

View File

@ -62,6 +62,15 @@ func Read(r io.Reader) (*File, error) {
panic("readState returned nil state with no errors")
}
if state.TerraformVersion != nil && state.TerraformVersion.GreaterThan(tfversion.SemVer) {
return state, fmt.Errorf(
"state snapshot was created by Terraform v%s, which is newer than current v%s; upgrade to Terraform v%s or greater to work with this state",
state.TerraformVersion,
tfversion.SemVer,
state.TerraformVersion,
)
}
return state, diags.Err()
}