Skip to content

Commit

Permalink
builtin: Disable Terraform provider version checks
Browse files Browse the repository at this point in the history
The builtin Terraform provider's remote state data source uses a
configured backend to fetch a given state, in order to allow access to
its root module outputs. Until this commit, this was only possible
with remote states which are from the current Terraform version or
older, forcing multi-state users to carefully orchestrate Terraform
upgrades.

Building on previous commits in this branch, we now disable this version
check, and allow any Terraform state file that the current Terraform
version can parse. Since we are only ever accessing root module outputs,
this is very likely to be safe for the foreseeable future.
  • Loading branch information
alisdair committed Oct 23, 2020
1 parent 6d577f6 commit 1dd2abd
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
4 changes: 2 additions & 2 deletions builtin/providers/terraform/data_source_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func dataSourceRemoteStateRead(d cty.Value) (cty.Value, tfdiags.Diagnostics) {
workspaceName = workspaceVal.AsString()
}

state, err := b.StateMgr(workspaceName)
state, err := b.StateMgrWithoutCheckVersion(workspaceName)
if err != nil {
diags = diags.Append(tfdiags.AttributeValue(
tfdiags.Error,
Expand All @@ -118,7 +118,7 @@ func dataSourceRemoteStateRead(d cty.Value) (cty.Value, tfdiags.Diagnostics) {
return cty.NilVal, diags
}

if err := state.RefreshState(); err != nil {
if err := state.RefreshStateWithoutCheckVersion(); err != nil {
diags = diags.Append(err)
return cty.NilVal, diags
}
Expand Down
20 changes: 20 additions & 0 deletions builtin/providers/terraform/data_source_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,26 @@ func TestState_basic(t *testing.T) {
}),
false,
},
"future version": {
cty.ObjectVal(map[string]cty.Value{
"backend": cty.StringVal("local"),
"config": cty.ObjectVal(map[string]cty.Value{
"path": cty.StringVal("./testdata/future.tfstate"),
}),
}),
cty.ObjectVal(map[string]cty.Value{
"backend": cty.StringVal("local"),
"config": cty.ObjectVal(map[string]cty.Value{
"path": cty.StringVal("./testdata/future.tfstate"),
}),
"outputs": cty.ObjectVal(map[string]cty.Value{
"foo": cty.StringVal("bar"),
}),
"defaults": cty.NullVal(cty.DynamicPseudoType),
"workspace": cty.NullVal(cty.String),
}),
false,
},
"missing": {
cty.ObjectVal(map[string]cty.Value{
"backend": cty.StringVal("local"),
Expand Down
12 changes: 12 additions & 0 deletions builtin/providers/terraform/testdata/future.tfstate
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 4,
"terraform_version": "999.0.0",
"serial": 0,
"lineage": "",
"outputs": {
"foo": {
"value": "bar",
"type": "string"
}
}
}

0 comments on commit 1dd2abd

Please sign in to comment.