From 634430ebb2149d0dbb8fb44acd46554688d101e2 Mon Sep 17 00:00:00 2001 From: Sander van Harmelen Date: Thu, 15 Nov 2018 13:17:15 +0100 Subject: [PATCH] Fix wildcard dependencies when upgrading states Fixes #19347 --- .../testdata/roundtrip/v3-simple.in.tfstate | 19 ++++++++++++++++- .../testdata/roundtrip/v3-simple.out.tfstate | 21 ++++++++++++++++++- states/statefile/version3_upgrade.go | 7 ++++++- terraform/valuesourcetype_string.go | 15 +++++++------ 4 files changed, 53 insertions(+), 9 deletions(-) diff --git a/states/statefile/testdata/roundtrip/v3-simple.in.tfstate b/states/statefile/testdata/roundtrip/v3-simple.in.tfstate index f4c5bde36..b9d9889ef 100644 --- a/states/statefile/testdata/roundtrip/v3-simple.in.tfstate +++ b/states/statefile/testdata/roundtrip/v3-simple.in.tfstate @@ -19,7 +19,8 @@ "null_resource.bar": { "type": "null_resource", "depends_on": [ - "null_resource.foo" + "null_resource.foo.*", + "null_resource.foobar" ], "primary": { "id": "5388490630832483079", @@ -65,6 +66,22 @@ }, "deposed": [], "provider": "" + }, + "null_resource.foobar": { + "type": "null_resource", + "depends_on": [], + "primary": { + "id": "7388490630832483079", + "attributes": { + "id": "7388490630832483079", + "triggers.%": "1", + "triggers.whaaat": "0,1" + }, + "meta": {}, + "tainted": false + }, + "deposed": [], + "provider": "" } }, "depends_on": [] diff --git a/states/statefile/testdata/roundtrip/v3-simple.out.tfstate b/states/statefile/testdata/roundtrip/v3-simple.out.tfstate index 0d45bd97d..38f325d66 100644 --- a/states/statefile/testdata/roundtrip/v3-simple.out.tfstate +++ b/states/statefile/testdata/roundtrip/v3-simple.out.tfstate @@ -23,7 +23,10 @@ "triggers.%": "1", "triggers.whaaat": "0,1" }, - "depends_on": ["null_resource.foo"] + "depends_on": [ + "null_resource.foo", + "null_resource.foobar" + ] } ] }, @@ -53,6 +56,22 @@ } } ] + }, + { + "mode": "managed", + "type": "null_resource", + "name": "foobar", + "provider": "provider.null", + "instances": [ + { + "schema_version": 0, + "attributes_flat": { + "id": "7388490630832483079", + "triggers.%": "1", + "triggers.whaaat": "0,1" + } + } + ] } ] } diff --git a/states/statefile/version3_upgrade.go b/states/statefile/version3_upgrade.go index da6dd2958..7ec1c9465 100644 --- a/states/statefile/version3_upgrade.go +++ b/states/statefile/version3_upgrade.go @@ -299,12 +299,17 @@ func upgradeInstanceObjectV3ToV4(rsOld *resourceStateV2, isOld *instanceStateV2, } } + dependencies := make([]string, len(rsOld.Dependencies)) + for i, v := range rsOld.Dependencies { + dependencies[i] = strings.TrimSuffix(v, ".*") + } + return &instanceObjectStateV4{ IndexKey: instKeyRaw, Status: status, Deposed: string(deposedKey), AttributesFlat: attributes, - Dependencies: rsOld.Dependencies, + Dependencies: dependencies, SchemaVersion: schemaVersion, PrivateRaw: privateJSON, }, nil diff --git a/terraform/valuesourcetype_string.go b/terraform/valuesourcetype_string.go index e3218b414..1380c851f 100644 --- a/terraform/valuesourcetype_string.go +++ b/terraform/valuesourcetype_string.go @@ -8,14 +8,15 @@ const ( _ValueSourceType_name_0 = "ValueFromUnknown" _ValueSourceType_name_1 = "ValueFromCLIArg" _ValueSourceType_name_2 = "ValueFromConfig" - _ValueSourceType_name_3 = "ValueFromEnvVarValueFromFile" + _ValueSourceType_name_3 = "ValueFromEnvVarValueFromAutoFile" _ValueSourceType_name_4 = "ValueFromInput" - _ValueSourceType_name_5 = "ValueFromPlan" - _ValueSourceType_name_6 = "ValueFromCaller" + _ValueSourceType_name_5 = "ValueFromNamedFile" + _ValueSourceType_name_6 = "ValueFromPlan" + _ValueSourceType_name_7 = "ValueFromCaller" ) var ( - _ValueSourceType_index_3 = [...]uint8{0, 15, 28} + _ValueSourceType_index_3 = [...]uint8{0, 15, 32} ) func (i ValueSourceType) String() string { @@ -31,10 +32,12 @@ func (i ValueSourceType) String() string { return _ValueSourceType_name_3[_ValueSourceType_index_3[i]:_ValueSourceType_index_3[i+1]] case i == 73: return _ValueSourceType_name_4 - case i == 80: + case i == 78: return _ValueSourceType_name_5 - case i == 83: + case i == 80: return _ValueSourceType_name_6 + case i == 83: + return _ValueSourceType_name_7 default: return "ValueSourceType(" + strconv.FormatInt(int64(i), 10) + ")" }