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

json-output: Fix unknowns for tuples and sets #31236

Merged
merged 1 commit into from Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions internal/command/jsonplan/plan.go
Expand Up @@ -566,8 +566,9 @@ func omitUnknowns(val cty.Value) cty.Value {
newVal := omitUnknowns(v)
if newVal != cty.NilVal {
vals = append(vals, newVal)
} else if newVal == cty.NilVal && ty.IsListType() {
// list length may be significant, so we will turn unknowns into nulls
} else if newVal == cty.NilVal {
// element order is how we correlate unknownness, so we must
// replace unknowns with nulls
vals = append(vals, cty.NullVal(v.Type()))
}
}
Expand Down
13 changes: 13 additions & 0 deletions internal/command/jsonplan/plan_test.go
Expand Up @@ -65,6 +65,18 @@ func TestOmitUnknowns(t *testing.T) {
"hello": cty.True,
}),
},
{
cty.TupleVal([]cty.Value{
cty.StringVal("alpha"),
cty.UnknownVal(cty.String),
cty.StringVal("charlie"),
}),
cty.TupleVal([]cty.Value{
cty.StringVal("alpha"),
cty.NullVal(cty.String),
cty.StringVal("charlie"),
}),
},
{
cty.SetVal([]cty.Value{
cty.StringVal("dev"),
Expand All @@ -76,6 +88,7 @@ func TestOmitUnknowns(t *testing.T) {
cty.StringVal("dev"),
cty.StringVal("foo"),
cty.StringVal("stg"),
cty.NullVal(cty.String),
}),
},
{
Expand Down