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

r/dynamodb_tag: change equality check in propagation waiter #39491

Merged
merged 17 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 3 additions & 0 deletions internal/generate/tags/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ var (
updateTagsFunc = flag.String("UpdateTagsFunc", defaultUpdateTagsFunc, "updateTagsFunc")
waitTagsPropagatedFunc = flag.String("WaitFunc", defaultWaitTagsPropagatedFunc, "waitFunc")
waitContinuousOccurence = flag.Int("WaitContinuousOccurence", 0, "ContinuousTargetOccurence for Wait function")
waitFuncComparator = flag.String("WaitFuncComparator", "Equal", "waitFuncComparator")
waitDelay = flag.Duration("WaitDelay", 0, "Delay for Wait function")
waitMinTimeout = flag.Duration("WaitMinTimeout", 0, `"MinTimeout" (minimum poll interval) for Wait function`)
waitPollInterval = flag.Duration("WaitPollInterval", 0, "PollInterval for Wait function")
Expand Down Expand Up @@ -214,6 +215,7 @@ type TemplateData struct {
WaitTagsPropagatedFunc string
WaitContinuousOccurence int
WaitDelay string
WaitFuncComparator string
WaitMinTimeout string
WaitPollInterval string
WaitTimeout string
Expand Down Expand Up @@ -370,6 +372,7 @@ func main() {
UpdateTagsFunc: *updateTagsFunc,
UpdateTagsIgnoreSystem: !*updateTagsNoIgnoreSystem,
WaitForPropagation: *waitForPropagation,
WaitFuncComparator: *waitFuncComparator,
WaitTagsPropagatedFunc: *waitTagsPropagatedFunc,
WaitContinuousOccurence: *waitContinuousOccurence,
WaitDelay: formatDuration(*waitDelay),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func {{ .WaitTagsPropagatedFunc }}(ctx context.Context, conn {{ .ClientType }},
output = output.IgnoreConfig(inContext.IgnoreConfig)
}

return output.Equal(tags), nil
return output.{{ .WaitFuncComparator }}(tags), nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍

}
opts := tfresource.WaitOpts{
{{- if ne .WaitContinuousOccurence 0 }}
Expand Down
2 changes: 1 addition & 1 deletion internal/service/dynamodb/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: MPL-2.0

//go:generate go run ../../generate/tagresource/main.go
//go:generate go run ../../generate/tags/main.go -GetTag -ListTags -ListTagsOp=ListTagsOfResource -ServiceTagsSlice -UpdateTags -Wait -WaitContinuousOccurence 5 -WaitMinTimeout 1s -WaitTimeout 10m -ParentNotFoundErrCode=ResourceNotFoundException
//go:generate go run ../../generate/tags/main.go -GetTag -ListTags -ListTagsOp=ListTagsOfResource -ServiceTagsSlice -UpdateTags -Wait -WaitContinuousOccurence 2 -WaitMinTimeout 1s -WaitTimeout 2m -WaitFuncComparator=ContainsAll -ParentNotFoundErrCode=ResourceNotFoundException
//go:generate go run ../../generate/servicepackage/main.go
//go:generate go run ../../generate/listpages/main.go -ListOps=ListBackups -InputPaginator=ExclusiveStartBackupArn -OutputPaginator=LastEvaluatedBackupArn -- list_backups_pages_gen.go
// ONLY generate directives and package declaration! Do not add anything else to this file.
Expand Down
164 changes: 164 additions & 0 deletions internal/service/dynamodb/tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,62 @@ func TestAccDynamoDBTag_value(t *testing.T) {
})
}

func TestAccDynamoDBTag_multipleTags(t *testing.T) {
ctx := acctest.Context(t)
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_dynamodb_tag.test"
resourceName2 := "aws_dynamodb_tag.test2"
resourceName3 := "aws_dynamodb_tag.test3"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.DynamoDBServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckTagDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccTagConfig_multipleTags(rName, acctest.CtKey1, acctest.CtValue1),
Check: resource.ComposeTestCheckFunc(
testAccCheckTagExists(ctx, resourceName),
testAccCheckTagExists(ctx, resourceName2),
testAccCheckTagExists(ctx, resourceName3),
resource.TestCheckResourceAttr(resourceName, names.AttrKey, acctest.CtKey1),
resource.TestCheckResourceAttr(resourceName, names.AttrValue, acctest.CtValue1),
resource.TestCheckResourceAttr(resourceName2, names.AttrKey, fmt.Sprintf("%s-2", acctest.CtKey1)),
resource.TestCheckResourceAttr(resourceName2, names.AttrValue, fmt.Sprintf("%s-2", acctest.CtValue1)),
resource.TestCheckResourceAttr(resourceName3, names.AttrKey, fmt.Sprintf("%s-3", acctest.CtKey1)),
resource.TestCheckResourceAttr(resourceName3, names.AttrValue, fmt.Sprintf("%s-3", acctest.CtValue1)),
),
},
{
Config: testAccTagConfig_multipleTagsUpdate(rName, acctest.CtKey1, acctest.CtValue1, acctest.CtValue2),
Check: resource.ComposeTestCheckFunc(
testAccCheckTagExists(ctx, resourceName),
testAccCheckTagExists(ctx, resourceName2),
testAccCheckTagExists(ctx, resourceName3),
resource.TestCheckResourceAttr(resourceName, names.AttrKey, acctest.CtKey1),
resource.TestCheckResourceAttr(resourceName, names.AttrValue, acctest.CtValue1),
resource.TestCheckResourceAttr(resourceName2, names.AttrKey, fmt.Sprintf("%s-2", acctest.CtKey1)),
resource.TestCheckResourceAttr(resourceName2, names.AttrValue, acctest.CtValue2),
resource.TestCheckResourceAttr(resourceName3, names.AttrKey, fmt.Sprintf("%s-3", acctest.CtKey1)),
resource.TestCheckResourceAttr(resourceName3, names.AttrValue, fmt.Sprintf("%s-3", acctest.CtValue1)),
),
},
{
Config: testAccTagConfig_multipleTagsRemove(rName, acctest.CtKey1, acctest.CtValue1),
Check: resource.ComposeTestCheckFunc(
testAccCheckTagExists(ctx, resourceName),
testAccCheckTagExists(ctx, resourceName2),
resource.TestCheckResourceAttr(resourceName, names.AttrKey, acctest.CtKey1),
resource.TestCheckResourceAttr(resourceName, names.AttrValue, acctest.CtValue1),
resource.TestCheckResourceAttr(resourceName2, names.AttrKey, fmt.Sprintf("%s-2", acctest.CtKey1)),
resource.TestCheckResourceAttr(resourceName2, names.AttrValue, fmt.Sprintf("%s-2", acctest.CtValue1)),
),
},
},
})
}

func testAccTagConfig_basic(rName string, key string, value string) string {
return fmt.Sprintf(`
resource "aws_dynamodb_table" "test" {
Expand Down Expand Up @@ -194,3 +250,111 @@ resource "aws_dynamodb_tag" "test" {
}
`, rName))
}

func testAccTagConfig_multipleTags(rName string, key string, value string) string {
return fmt.Sprintf(`
resource "aws_dynamodb_table" "test" {
hash_key = "TestTableHashKey"
name = %[1]q
read_capacity = 1
write_capacity = 1

attribute {
name = "TestTableHashKey"
type = "S"
}

lifecycle {
ignore_changes = [tags]
}
}

resource "aws_dynamodb_tag" "test" {
resource_arn = aws_dynamodb_table.test.arn
key = %[2]q
value = %[3]q
}

resource "aws_dynamodb_tag" "test2" {
resource_arn = aws_dynamodb_table.test.arn
key = "%[2]s-2"
value = "%[3]s-2"
}

resource "aws_dynamodb_tag" "test3" {
resource_arn = aws_dynamodb_table.test.arn
key = "%[2]s-3"
value = "%[3]s-3"
}
`, rName, key, value)
}

func testAccTagConfig_multipleTagsUpdate(rName string, key string, value, value2 string) string {
return fmt.Sprintf(`
resource "aws_dynamodb_table" "test" {
hash_key = "TestTableHashKey"
name = %[1]q
read_capacity = 1
write_capacity = 1

attribute {
name = "TestTableHashKey"
type = "S"
}

lifecycle {
ignore_changes = [tags]
}
}

resource "aws_dynamodb_tag" "test" {
resource_arn = aws_dynamodb_table.test.arn
key = %[2]q
value = %[3]q
}

resource "aws_dynamodb_tag" "test2" {
resource_arn = aws_dynamodb_table.test.arn
key = "%[2]s-2"
value = %[4]q
}

resource "aws_dynamodb_tag" "test3" {
resource_arn = aws_dynamodb_table.test.arn
key = "%[2]s-3"
value = "%[3]s-3"
}
`, rName, key, value, value2)
}

func testAccTagConfig_multipleTagsRemove(rName string, key string, value string) string {
return fmt.Sprintf(`
resource "aws_dynamodb_table" "test" {
hash_key = "TestTableHashKey"
name = %[1]q
read_capacity = 1
write_capacity = 1

attribute {
name = "TestTableHashKey"
type = "S"
}

lifecycle {
ignore_changes = [tags]
}
}

resource "aws_dynamodb_tag" "test" {
resource_arn = aws_dynamodb_table.test.arn
key = %[2]q
value = %[3]q
}

resource "aws_dynamodb_tag" "test2" {
resource_arn = aws_dynamodb_table.test.arn
key = "%[2]s-2"
value = "%[3]s-2"
}
`, rName, key, value)
}
6 changes: 3 additions & 3 deletions internal/service/dynamodb/tags_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading