Skip to content

Commit

Permalink
Merge pull request #31587 from hashicorp/b-null-tag-values
Browse files Browse the repository at this point in the history
Tags: fix for null tags in config
  • Loading branch information
johnsonaj committed May 26, 2023
2 parents ca2ed88 + c147103 commit 048a82c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/31587.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
provider/tags: Fix crash when tags are `null`
```
32 changes: 32 additions & 0 deletions internal/service/ec2/vpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion internal/tags/key_value_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
}
Expand Down

0 comments on commit 048a82c

Please sign in to comment.