Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix manifest object type mutation #2368

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions manifest/morph/scaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ func DeepUnknown(t tftypes.Type, v tftypes.Value, p *tftypes.AttributePath) (tft
if !v.IsKnown() {
return tftypes.NewValue(t, tftypes.UnknownValue), nil
}
switch {
case t.Is(tftypes.Object{}):
atts := t.(tftypes.Object).AttributeTypes
switch x := t.(type) {
case tftypes.Object:
atts := x.AttributeTypes
var vals map[string]tftypes.Value
ovals := make(map[string]tftypes.Value, len(atts))
err := v.As(&vals)
Expand All @@ -39,7 +39,7 @@ func DeepUnknown(t tftypes.Type, v tftypes.Value, p *tftypes.AttributePath) (tft
}
}
return tftypes.NewValue(tftypes.Object{AttributeTypes: atts}, ovals), nil
case t.Is(tftypes.Map{}):
case tftypes.Map:
if v.IsNull() {
return tftypes.NewValue(t, tftypes.UnknownValue), nil
}
Expand All @@ -50,18 +50,18 @@ func DeepUnknown(t tftypes.Type, v tftypes.Value, p *tftypes.AttributePath) (tft
}
for name, el := range vals {
np := p.WithElementKeyString(name)
nv, err := DeepUnknown(t.(tftypes.Map).ElementType, el, np)
nv, err := DeepUnknown(x.ElementType, el, np)
if err != nil {
return tftypes.Value{}, np.NewError(err)
}
vals[name] = nv
}
return tftypes.NewValue(t, vals), nil
case t.Is(tftypes.Tuple{}):
case tftypes.Tuple:
if v.IsNull() {
return tftypes.NewValue(t, tftypes.UnknownValue), nil
}
atts := t.(tftypes.Tuple).ElementTypes
atts := x.ElementTypes
if len(v.Type().(tftypes.Tuple).ElementTypes) != len(atts) {
if len(atts) != 1 {
return tftypes.Value{}, p.NewErrorf("[%s] incompatible tuple types", p.String())
Expand All @@ -85,7 +85,7 @@ func DeepUnknown(t tftypes.Type, v tftypes.Value, p *tftypes.AttributePath) (tft
vals[i] = nv
}
return tftypes.NewValue(tftypes.Tuple{ElementTypes: atts}, vals), nil
case t.Is(tftypes.List{}) || t.Is(tftypes.Set{}):
case tftypes.List, tftypes.Set:
if v.IsNull() {
return tftypes.NewValue(t, tftypes.UnknownValue), nil
}
Expand All @@ -95,11 +95,11 @@ func DeepUnknown(t tftypes.Type, v tftypes.Value, p *tftypes.AttributePath) (tft
return tftypes.Value{}, p.NewError(err)
}
var elt tftypes.Type
switch {
case t.Is(tftypes.List{}):
elt = t.(tftypes.List).ElementType
case t.Is(tftypes.Set{}):
elt = t.(tftypes.Set).ElementType
switch xt := x.(type) {
case tftypes.List:
elt = xt.ElementType
case tftypes.Set:
elt = xt.ElementType
}
for i, el := range vals {
np := p.WithElementKeyInt(i)
Expand Down
Loading