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:
parent
02850111b9
commit
d7dda4e436
|
@ -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",
|
||||||
|
|
|
@ -25,7 +25,8 @@
|
||||||
},
|
},
|
||||||
"depends_on": [
|
"depends_on": [
|
||||||
"null_resource.foo",
|
"null_resource.foo",
|
||||||
"null_resource.foobar"
|
"null_resource.foobar",
|
||||||
|
"null_resource.foobar[1]"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue