Skip to content

Commit

Permalink
internal/keyvaluetags: Simplify updatetags generator template batchin…
Browse files Browse the repository at this point in the history
…g support (#11502)

Reference: #11352 (comment)

Updated via:

```
make gen
```

Output from acceptance testing:

```
--- PASS: TestAccAWSKinesisStream_Tags (219.62s)
```
  • Loading branch information
bflad committed Jan 22, 2020
1 parent e67e2af commit a77f820
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 65 deletions.
66 changes: 9 additions & 57 deletions aws/internal/keyvaluetags/generators/updatetags/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,36 +243,8 @@ func {{ . | Title }}UpdateTags(conn {{ . | ClientType }}, identifier string{{ if
if removedTags := oldTags.Removed(newTags); len(removedTags) > 0 {
{{- if . | TagFunctionBatchSize }}
chunks := removedTags.Chunks({{ . | TagFunctionBatchSize }})
for _, chunk := range chunks {
input := &{{ . | TagPackage }}.{{ . | UntagFunction }}Input{
{{- if . | TagInputIdentifierRequiresSlice }}
{{ . | TagInputIdentifierField }}: aws.StringSlice([]string{identifier}),
{{- else }}
{{ . | TagInputIdentifierField }}: aws.String(identifier),
{{- end }}
{{- if . | TagInputResourceTypeField }}
{{ . | TagInputResourceTypeField }}: aws.String(resourceType),
{{- end }}
{{- if . | UntagInputRequiresTagType }}
{{ . | UntagInputTagsField }}: chunk.IgnoreAws().{{ . | Title }}Tags(),
{{- else if . | UntagInputRequiresTagKeyType }}
{{ . | UntagInputTagsField }}: chunk.IgnoreAws().{{ . | Title }}TagKeys(),
{{- else if . | UntagInputCustomValue }}
{{ . | UntagInputTagsField }}: {{ . | UntagInputCustomValue }},
{{- else }}
{{ . | UntagInputTagsField }}: aws.StringSlice(chunk.Keys()),
{{- end }}
}
_, err := conn.{{ . | UntagFunction }}(input)
if err != nil {
return fmt.Errorf("error untagging resource (%s): %w", identifier, err)
}
}
{{- else }}
for _, removedTags := range removedTags.Chunks({{ . | TagFunctionBatchSize }}) {
{{- end }}
input := &{{ . | TagPackage }}.{{ . | UntagFunction }}Input{
{{- if . | TagInputIdentifierRequiresSlice }}
{{ . | TagInputIdentifierField }}: aws.StringSlice([]string{identifier}),
Expand All @@ -298,37 +270,15 @@ func {{ . | Title }}UpdateTags(conn {{ . | ClientType }}, identifier string{{ if
if err != nil {
return fmt.Errorf("error untagging resource (%s): %w", identifier, err)
}
{{- if . | TagFunctionBatchSize }}
}
{{- end }}
}
if updatedTags := oldTags.Updated(newTags); len(updatedTags) > 0 {
{{- if . | TagFunctionBatchSize }}
chunks := updatedTags.Chunks({{ . | TagFunctionBatchSize }})
for _, chunk := range chunks {
input := &{{ . | TagPackage }}.{{ . | TagFunction }}Input{
{{- if . | TagInputIdentifierRequiresSlice }}
{{ . | TagInputIdentifierField }}: aws.StringSlice([]string{identifier}),
{{- else }}
{{ . | TagInputIdentifierField }}: aws.String(identifier),
{{- end }}
{{- if . | TagInputResourceTypeField }}
{{ . | TagInputResourceTypeField }}: aws.String(resourceType),
{{- end }}
{{- if . | TagInputCustomValue }}
{{ . | TagInputTagsField }}: {{ . | TagInputCustomValue }},
{{- else }}
{{ . | TagInputTagsField }}: chunk.IgnoreAws().{{ . | Title }}Tags(),
{{- end }}
}
_, err := conn.{{ . | TagFunction }}(input)
if err != nil {
return fmt.Errorf("error tagging resource (%s): %w", identifier, err)
}
}
{{- else }}
for _, updatedTags := range updatedTags.Chunks({{ . | TagFunctionBatchSize }}) {
{{- end }}
input := &{{ . | TagPackage }}.{{ . | TagFunction }}Input{
{{- if . | TagInputIdentifierRequiresSlice }}
{{ . | TagInputIdentifierField }}: aws.StringSlice([]string{identifier}),
Expand All @@ -350,6 +300,8 @@ func {{ . | Title }}UpdateTags(conn {{ . | ClientType }}, identifier string{{ if
if err != nil {
return fmt.Errorf("error tagging resource (%s): %w", identifier, err)
}
{{- if . | TagFunctionBatchSize }}
}
{{- end }}
}
Expand Down Expand Up @@ -584,7 +536,7 @@ func ServiceTagInputCustomValue(serviceName string) string {
case "cloudfront":
return "&cloudfront.Tags{Items: updatedTags.IgnoreAws().CloudfrontTags()}"
case "kinesis":
return "aws.StringMap(chunk.IgnoreAws().Map())"
return "aws.StringMap(updatedTags.IgnoreAws().Map())"
case "pinpoint":
return "&pinpoint.TagsModel{Tags: updatedTags.IgnoreAws().PinpointTags()}"
default:
Expand Down
12 changes: 4 additions & 8 deletions aws/internal/keyvaluetags/update_tags_gen.go

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

0 comments on commit a77f820

Please sign in to comment.