Skip to content

Commit

Permalink
Use path-based get and set for property transform
Browse files Browse the repository at this point in the history
  • Loading branch information
guineveresaenger committed Sep 11, 2024
1 parent 0cc64ea commit db34262
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions provider/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -1762,21 +1762,36 @@ func Provider() tfbridge.ProviderInfo {
// `port` is an object type in the current version of this provider.
// But in a previous version, it was nested as a MaxItemsOne item, `ports`
// For correct updating, we extract the array item and re-write its content to the new `port` object.
if template, ok := pMap["template"]; ok {
tplObj := template.ObjectValue()
if containers, ok := tplObj["containers"]; ok {
contAry := containers.ArrayValue()
for _, container := range contAry {
contObj := container.ObjectValue()
if ports, ok := contObj["ports"]; ok {
if ports.IsArray() {
pMap["template"].ObjectValue()["containers"].ArrayValue()[0].ObjectValue()["ports"] = ports.ArrayValue()[0]
}
}
pValue := resource.NewProperty(pMap)
containersPath := resource.PropertyPath{"template", "containers"}

if containers, ok := containersPath.Get(pValue); ok {
contAry := containers.ArrayValue()
for i, _ := range contAry {
portsPath := resource.PropertyPath{"template", "containers", i, "ports"}
if val, ok := portsPath.Get(pValue); ok && val.IsArray() {
portsPath.Set(pValue, val.ArrayValue()[0])
}
}
}
return pMap, nil
return pValue.ObjectValue(), nil

//if template, ok := pMap["template"]; ok {
// tplObj := template.ObjectValue()
// if containers, ok := tplObj["containers"]; ok {
// contAry := containers.ArrayValue()
// for i, container := range contAry {
// contObj := container.ObjectValue()
// if ports, ok := contObj["ports"]; ok {
// if ports.IsArray() {
// pMap["template"].ObjectValue()["containers"].ArrayValue()[i].ObjectValue()["ports"] = ports.ArrayValue()[0]
// }
// }
// }
// }
//}
//return pMap, nil

},
},

Expand Down

0 comments on commit db34262

Please sign in to comment.