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

Skip blocks while marking computed nils unknown #555

Merged
merged 1 commit into from Nov 28, 2022
Merged
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
87 changes: 87 additions & 0 deletions internal/fwserver/server_planresourcechange_test.go
Expand Up @@ -115,6 +115,41 @@ func TestMarkComputedNilsAsUnknown(t *testing.T) {
Computed: true,
},
},
Blocks: map[string]tfsdk.Block{
// nil blocks should remain nil
"block-nil-optional-computed": {
Attributes: map[string]tfsdk.Attribute{
"string-nil": {
Type: types.StringType,
Optional: true,
Computed: true,
},
"string-set": {
Type: types.StringType,
Optional: true,
Computed: true,
},
},
NestingMode: tfsdk.BlockNestingModeSet,
},
"block-value-optional-computed": {
Attributes: map[string]tfsdk.Attribute{
// nested computed attributes should be unknown
"string-nil": {
Type: types.StringType,
Optional: true,
Computed: true,
},
// nested non-nil computed attributes should be left alone
"string-set": {
Type: types.StringType,
Optional: true,
Computed: true,
},
},
NestingMode: tfsdk.BlockNestingModeSet,
},
},
}
input := tftypes.NewValue(s.Type().TerraformType(context.Background()), map[string]tftypes.Value{
"string-value": tftypes.NewValue(tftypes.String, "hello, world"),
Expand Down Expand Up @@ -152,6 +187,32 @@ func TestMarkComputedNilsAsUnknown(t *testing.T) {
"string-nil": tftypes.NewValue(tftypes.String, nil),
"string-set": tftypes.NewValue(tftypes.String, "bar"),
}),
"block-nil-optional-computed": tftypes.NewValue(tftypes.Set{
ElementType: tftypes.Object{
AttributeTypes: map[string]tftypes.Type{
"string-nil": tftypes.String,
"string-set": tftypes.String,
},
},
}, nil),
"block-value-optional-computed": tftypes.NewValue(tftypes.Set{
ElementType: tftypes.Object{
AttributeTypes: map[string]tftypes.Type{
"string-nil": tftypes.String,
"string-set": tftypes.String,
},
},
}, []tftypes.Value{
tftypes.NewValue(tftypes.Object{
AttributeTypes: map[string]tftypes.Type{
"string-nil": tftypes.String,
"string-set": tftypes.String,
},
}, map[string]tftypes.Value{
"string-nil": tftypes.NewValue(tftypes.String, nil),
"string-set": tftypes.NewValue(tftypes.String, "bar"),
}),
}),
})
expected := tftypes.NewValue(s.Type().TerraformType(context.Background()), map[string]tftypes.Value{
"string-value": tftypes.NewValue(tftypes.String, "hello, world"),
Expand Down Expand Up @@ -189,6 +250,32 @@ func TestMarkComputedNilsAsUnknown(t *testing.T) {
"string-nil": tftypes.NewValue(tftypes.String, tftypes.UnknownValue),
"string-set": tftypes.NewValue(tftypes.String, "bar"),
}),
"block-nil-optional-computed": tftypes.NewValue(tftypes.Set{
ElementType: tftypes.Object{
AttributeTypes: map[string]tftypes.Type{
"string-nil": tftypes.String,
"string-set": tftypes.String,
},
},
}, nil),
"block-value-optional-computed": tftypes.NewValue(tftypes.Set{
ElementType: tftypes.Object{
AttributeTypes: map[string]tftypes.Type{
"string-nil": tftypes.String,
"string-set": tftypes.String,
},
},
}, []tftypes.Value{
tftypes.NewValue(tftypes.Object{
AttributeTypes: map[string]tftypes.Type{
"string-nil": tftypes.String,
"string-set": tftypes.String,
},
}, map[string]tftypes.Value{
"string-nil": tftypes.NewValue(tftypes.String, tftypes.UnknownValue),
"string-set": tftypes.NewValue(tftypes.String, "bar"),
}),
}),
})

got, err := tftypes.Transform(input, fwserver.MarkComputedNilsAsUnknown(context.Background(), input, s))
Expand Down