Skip to content

Commit 2f22560

Browse files
author
Gavin Williams
committed
fix: Resolve panic with ElementKeyInt(0): can't use tftypes
This commit updates the `manifest/morph/scaffold.go` logic in order to resolve a panic encountered when working with `Tuple` types. Also adds a new unit test to cover this case. Disclaimer: This fix and the coresponding test case was generated by Gemini, and has been reviewed and tested by myself. Fixes: #2778 #2754 plus probably others...
1 parent ea438d0 commit 2f22560

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

manifest/morph/scaffold.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,17 @@ func DeepUnknown(t tftypes.Type, v tftypes.Value, p *tftypes.AttributePath) (tft
7575
if err != nil {
7676
return tftypes.Value{}, p.NewError(err)
7777
}
78+
ntypes := make([]tftypes.Type, len(atts))
7879
for i, et := range atts {
7980
np := p.WithElementKeyInt(i)
8081
nv, err := DeepUnknown(et, vals[i], np)
8182
if err != nil {
8283
return tftypes.Value{}, np.NewError(err)
8384
}
8485
vals[i] = nv
86+
ntypes[i] = nv.Type()
8587
}
86-
return tftypes.NewValue(tftypes.Tuple{ElementTypes: atts}, vals), nil
88+
return tftypes.NewValue(tftypes.Tuple{ElementTypes: ntypes}, vals), nil
8789
case t.Is(tftypes.List{}) || t.Is(tftypes.Set{}):
8890
if v.IsNull() {
8991
return tftypes.NewValue(t, tftypes.UnknownValue), nil

manifest/morph/scaffold_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,61 @@ func TestDeepUnknown(t *testing.T) {
299299
},
300300
),
301301
},
302+
"tuple-with-dynamic": {
303+
In: deepUnknownTestSampleInput{
304+
T: tftypes.Tuple{
305+
ElementTypes: []tftypes.Type{
306+
tftypes.DynamicPseudoType,
307+
},
308+
},
309+
V: tftypes.NewValue(
310+
tftypes.Tuple{
311+
ElementTypes: []tftypes.Type{
312+
tftypes.Object{
313+
AttributeTypes: map[string]tftypes.Type{
314+
"name": tftypes.String,
315+
},
316+
},
317+
},
318+
},
319+
[]tftypes.Value{
320+
tftypes.NewValue(
321+
tftypes.Object{
322+
AttributeTypes: map[string]tftypes.Type{
323+
"name": tftypes.String,
324+
},
325+
},
326+
map[string]tftypes.Value{
327+
"name": tftypes.NewValue(tftypes.String, "test"),
328+
},
329+
),
330+
},
331+
),
332+
},
333+
Out: tftypes.NewValue(
334+
tftypes.Tuple{
335+
ElementTypes: []tftypes.Type{
336+
tftypes.Object{
337+
AttributeTypes: map[string]tftypes.Type{
338+
"name": tftypes.String,
339+
},
340+
},
341+
},
342+
},
343+
[]tftypes.Value{
344+
tftypes.NewValue(
345+
tftypes.Object{
346+
AttributeTypes: map[string]tftypes.Type{
347+
"name": tftypes.String,
348+
},
349+
},
350+
map[string]tftypes.Value{
351+
"name": tftypes.NewValue(tftypes.String, "test"),
352+
},
353+
),
354+
},
355+
),
356+
},
302357
}
303358
for n, s := range samples {
304359
t.Run(n, func(t *testing.T) {

0 commit comments

Comments
 (0)