states/statefile: upgrade legacy dependency syntax (#21159)

We used to allow "foo.1" etc as a reference, but now it's "foo[1]".
This commit is contained in:
Kristin Laemmert 2019-04-30 14:34:01 -04:00 committed by GitHub
parent 02850111b9
commit d7dda4e436
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 5 deletions

View File

@ -20,7 +20,8 @@
"type": "null_resource", "type": "null_resource",
"depends_on": [ "depends_on": [
"null_resource.foo.*", "null_resource.foo.*",
"null_resource.foobar" "null_resource.foobar",
"null_resource.foobar.1"
], ],
"primary": { "primary": {
"id": "5388490630832483079", "id": "5388490630832483079",

View File

@ -25,7 +25,8 @@
}, },
"depends_on": [ "depends_on": [
"null_resource.foo", "null_resource.foo",
"null_resource.foobar" "null_resource.foobar",
"null_resource.foobar[1]"
] ]
} }
] ]

View File

@ -301,7 +301,7 @@ func upgradeInstanceObjectV3ToV4(rsOld *resourceStateV2, isOld *instanceStateV2,
dependencies := make([]string, len(rsOld.Dependencies)) dependencies := make([]string, len(rsOld.Dependencies))
for i, v := range rsOld.Dependencies { for i, v := range rsOld.Dependencies {
dependencies[i] = strings.TrimSuffix(v, ".*") dependencies[i] = parseLegacyDependency(v)
} }
return &instanceObjectStateV4{ return &instanceObjectStateV4{
@ -413,3 +413,19 @@ func simplifyImpliedValueType(ty cty.Type) cty.Type {
return ty return ty
} }
} }
func parseLegacyDependency(s string) string {
parts := strings.Split(s, ".")
ret := parts[0]
for _, part := range parts[1:] {
if part == "*" {
break
}
if i, err := strconv.Atoi(part); err == nil {
ret = ret + fmt.Sprintf("[%d]", i)
break
}
ret = ret + "." + part
}
return ret
}