Add support for Tuples into the structured plan renderer (#32479)

* add support for tuples to the structured plan renderer

* update after latest main changes
This commit is contained in:
Liam Cervante 2023-01-09 17:39:13 +01:00 committed by GitHub
parent 2d66eee872
commit d31631675b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 0 deletions

View File

@ -58,6 +58,8 @@ func (v Value) computeChangeForType(ctype cty.Type) change.Change {
return v.computeAttributeChangeAsMap(ctype.ElementType())
case ctype.IsListType():
return v.computeAttributeChangeAsList(ctype.ElementType())
case ctype.IsTupleType():
return v.computeAttributeChangeAsTuple(ctype.TupleElementTypes())
case ctype.IsSetType():
return v.computeAttributeChangeAsSet(ctype.ElementType())
default:

View File

@ -0,0 +1,19 @@
package differ
import (
"github.com/hashicorp/terraform/internal/command/jsonformat/change"
"github.com/zclconf/go-cty/cty"
)
func (v Value) computeAttributeChangeAsTuple(elementTypes []cty.Type) change.Change {
var elements []change.Change
current := v.getDefaultActionForIteration()
sliceValue := v.asSlice()
for ix, elementType := range elementTypes {
childValue := sliceValue.getChild(ix, ix, false)
element := childValue.computeChangeForType(elementType)
elements = append(elements, element)
current = compareActions(current, element.Action())
}
return change.New(change.List(elements), current, v.replacePath())
}

View File

@ -1965,6 +1965,28 @@ func TestValue_CollectionAttributes(t *testing.T) {
},
validateChange: change.ValidateComputed(change.ValidateSet(nil, plans.Delete, false), plans.Update, false),
},
"tuple_primitive": {
input: Value{
Before: []interface{}{
"one",
2.0,
"three",
},
After: []interface{}{
"one",
4.0,
"three",
},
},
attribute: &jsonprovider.Attribute{
AttributeType: unmarshalType(t, cty.Tuple([]cty.Type{cty.String, cty.Number, cty.String})),
},
validateChange: change.ValidateList([]change.ValidateChangeFunc{
change.ValidatePrimitive(strptr("\"one\""), strptr("\"one\""), plans.NoOp, false),
change.ValidatePrimitive(strptr("2"), strptr("4"), plans.Update, false),
change.ValidatePrimitive(strptr("\"three\""), strptr("\"three\""), plans.NoOp, false),
}, plans.Update, false),
},
}
for name, tc := range tcs {