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

Tags: fix for null tags in config #31587

Merged
merged 3 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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