diff --git a/.changelog/31587.txt b/.changelog/31587.txt new file mode 100644 index 00000000000..19305eab49a --- /dev/null +++ b/.changelog/31587.txt @@ -0,0 +1,3 @@ +```release-note:bug +provider/tags: Fix crash when tags are `null` +``` \ No newline at end of file diff --git a/internal/service/ec2/vpc_test.go b/internal/service/ec2/vpc_test.go index c662d532a4f..571eedf1356 100644 --- a/internal/service/ec2/vpc_test.go +++ b/internal/service/ec2/vpc_test.go @@ -157,6 +157,28 @@ func TestAccVPC_tags_computed(t *testing.T) { }) } +func TestAccVPC_tags_null(t *testing.T) { + ctx := acctest.Context(t) + var vpc ec2.Vpc + resourceName := "aws_vpc.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, ec2.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckVPCDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccVPCConfig_tags_null, + Check: resource.ComposeTestCheckFunc( + acctest.CheckVPCExists(ctx, resourceName, &vpc), + resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + ), + }, + }, + }) +} + func TestAccVPC_DefaultTags_zeroValue(t *testing.T) { ctx := acctest.Context(t) var vpc ec2.Vpc @@ -1139,6 +1161,16 @@ resource "aws_vpc" "test" { } ` +const testAccVPCConfig_tags_null = ` +resource "aws_vpc" "test" { + cidr_block = "10.1.0.0/16" + + tags = { + Name = null + } +} +` + func testAccVPCConfig_ignoreChangesDynamicTagsMergedLocals(localTagKey1, localTagValue1 string) string { return fmt.Sprintf(` locals { diff --git a/internal/tags/key_value_tags.go b/internal/tags/key_value_tags.go index 0b2581ccf76..dfb8b5de6c4 100644 --- a/internal/tags/key_value_tags.go +++ b/internal/tags/key_value_tags.go @@ -780,7 +780,10 @@ func (tags KeyValueTags) ResolveDuplicates(ctx context.Context, defaultConfig *D if !c.IsNull() && c.IsKnown() { for k, v := range c.AsValueMap() { if _, ok := configTags[k]; !ok { - configTags[k] = v.AsString() + // config tags can be null values. Ignore. + if !v.IsNull() { + configTags[k] = v.AsString() + } } } }