mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 18:01:01 -06:00
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:
parent
2d66eee872
commit
d31631675b
@ -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:
|
||||
|
19
internal/command/jsonformat/differ/tuple.go
Normal file
19
internal/command/jsonformat/differ/tuple.go
Normal 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())
|
||||
}
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user