From c6d8c7446745af20580d1205c6284986d2a5ab59 Mon Sep 17 00:00:00 2001 From: Austin Valle Date: Thu, 25 Jan 2024 15:43:03 -0500 Subject: [PATCH] add set test showing invalid usage --- .../dynamic_nested_block_test.go | 59 ++++++++++++++++++- 1 file changed, 56 insertions(+), 3 deletions(-) diff --git a/internal/dynamic6provider/dynamic_nested_block_test.go b/internal/dynamic6provider/dynamic_nested_block_test.go index 2335ff1..f376f53 100644 --- a/internal/dynamic6provider/dynamic_nested_block_test.go +++ b/internal/dynamic6provider/dynamic_nested_block_test.go @@ -59,7 +59,7 @@ func Test_Dynamic_NestingModeList_Bug(t *testing.T) { BlockTypes: []*tfprotov6.SchemaNestedBlock{ { TypeName: "block_with_dpt", - // List nesting mode + // Nesting Mode: List Nesting: tfprotov6.SchemaNestedBlockNestingModeList, Block: &tfprotov6.SchemaBlock{ Attributes: []*tfprotov6.SchemaAttribute{ @@ -87,6 +87,59 @@ func Test_Dynamic_NestingModeList_Bug(t *testing.T) { }) } +func Test_Dynamic_NestingModeSet_Bug(t *testing.T) { + r.UnitTest(t, r.TestCase{ + Steps: []r.TestStep{ + { + // This error message shows that using a nesting mode of `Set` is currently invalid + // https://github.com/hashicorp/terraform/blob/a9b43f332ea2b8fcf152a74a60af1d3a4a26e5f7/internal/configs/configschema/internal_validate.go#L79 + Config: `resource "corner_dynamic_thing" "foo" { + block_with_dpt { + bar = "hello" + foo = 4 + } + }`, + ExpectError: regexp.MustCompile(`NestingSet blocks may not contain attributes of cty.DynamicPseudoType`), + }, + }, + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "corner": providerserver.NewProviderServer(testprovider.Provider{ + Resources: map[string]testprovider.Resource{ + "corner_dynamic_thing": { + SchemaResponse: &resource.SchemaResponse{ + Schema: &tfprotov6.Schema{ + Block: &tfprotov6.SchemaBlock{ + BlockTypes: []*tfprotov6.SchemaNestedBlock{ + { + TypeName: "block_with_dpt", + // Nesting Mode: Set + Nesting: tfprotov6.SchemaNestedBlockNestingModeSet, + Block: &tfprotov6.SchemaBlock{ + Attributes: []*tfprotov6.SchemaAttribute{ + { + Name: "bar", + Type: tftypes.DynamicPseudoType, + Optional: true, + }, + { + Name: "foo", + Type: tftypes.Number, + Optional: true, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }), + }, + }) +} + func Test_Dynamic_NestingModeMap_Bug(t *testing.T) { r.UnitTest(t, r.TestCase{ Steps: []r.TestStep{ @@ -125,7 +178,7 @@ func Test_Dynamic_NestingModeMap_Bug(t *testing.T) { BlockTypes: []*tfprotov6.SchemaNestedBlock{ { TypeName: "block_with_dpt", - // Map nesting mode + // Nesting Mode: Map Nesting: tfprotov6.SchemaNestedBlockNestingModeMap, Block: &tfprotov6.SchemaBlock{ Attributes: []*tfprotov6.SchemaAttribute{ @@ -188,7 +241,7 @@ func Test_Dynamic_NestingModeSingle_Success(t *testing.T) { BlockTypes: []*tfprotov6.SchemaNestedBlock{ { TypeName: "block_with_dpt", - // Single nesting mode + // Nesting Mode: Single Nesting: tfprotov6.SchemaNestedBlockNestingModeSingle, Block: &tfprotov6.SchemaBlock{ Attributes: []*tfprotov6.SchemaAttribute{