-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Refactor Kinesis Streams resource and data source to use keyvaluetags package #11352
Conversation
@@ -422,6 +432,16 @@ func ServiceTagInputTagsField(serviceName string) string { | |||
} | |||
} | |||
|
|||
// ServiceTagInputResourceTypeField determines the service tagging tags field requires a map[string]*string. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yet another permutation for the Kinesis Streams service.
Listing tags returns a []*kinesis.Tag
but the tags input to the AddTags
API requires a map[string]*string
.
Capture that here via another specialization.
Refactoring the import functionality to set resource ID there is too much surgery for this refactor.
|
Given that #11368 has a similar problem with a transformation of the tags passed to the tagging function i replaced the |
Removed WIP (again). |
Phew! We are getting into the weeds now with these tagging implementations. Thanks for starting this one and nice work shimming this in here so far. A few notes/open questions -- would love to hear your opinions here! The I think for this type of handling we can introduce a generator function that just contains the number of tags per batch, e.g. func ServiceTagFunctionBatchSize(serviceName string) string {
switch serviceName {
case "kinesis":
return "10"
default:
return ""
}
} And the template can if/else the batching logic based off that. The logic I originally had in For the TagInputRequiresTransformation bits, wow that API difference is annoying. While the extra
{{- if . | TagInputCustomValue }}
{{ . | TagInputTagsField }}: {{ . | TagInputCustomValue }},
{{- else }} This has the problem of needing to make sure any changes to the
{{- if . | TagInputRequiresMap }}
{{ . | TagInputTagsField }}: aws.StringMap(updatedTags.IgnoreAws().Map()),
{{- else }} At first blush, this seemed like a quick win, but I see the problem you mention with Pinpoint being that it needs to be {{- if . | TagInputRequiresMap }}
{{ . | TagInputTagsField }}: aws.StringMap(updatedTags.IgnoreAws().Map()),
{{- else if . | TagInputRequiresWrappingType }}
{{ . | TagInputTagsField }}: {{ . | TagInputRequiresWrappingType }} updatedTags.IgnoreAws().{{ . | Title }}Tags()},
{{- else }}}} Gross. This was a problem that would needed to be solved for CloudFront as well.
This would make the logic potentially easier to understand since it'd be the same for all services instead of having one-off customization functions either in the generator I'm not necessarily opposed to these one-off TagInput customization functions since they would allow the ultimate customizability, just food for thought about later folks who need to read and understand the generator. 😄 Open to ideas. |
b9ed22f
to
68259eb
Compare
68259eb
to
7418bca
Compare
Batch size:I implemented the Input transformation:Overall the suggestion of generating Re-ran acceptance tests: $ make testacc TEST=./aws TESTARGS='-run=TestAccAWSKinesisStream_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -count 1 -parallel 20 -run=TestAccAWSKinesisStream_ -timeout 120m
=== RUN TestAccAWSKinesisStream_basic
=== PAUSE TestAccAWSKinesisStream_basic
=== RUN TestAccAWSKinesisStream_createMultipleConcurrentStreams
=== PAUSE TestAccAWSKinesisStream_createMultipleConcurrentStreams
=== RUN TestAccAWSKinesisStream_encryptionWithoutKmsKeyThrowsError
=== PAUSE TestAccAWSKinesisStream_encryptionWithoutKmsKeyThrowsError
=== RUN TestAccAWSKinesisStream_encryption
=== PAUSE TestAccAWSKinesisStream_encryption
=== RUN TestAccAWSKinesisStream_shardCount
=== PAUSE TestAccAWSKinesisStream_shardCount
=== RUN TestAccAWSKinesisStream_retentionPeriod
=== PAUSE TestAccAWSKinesisStream_retentionPeriod
=== RUN TestAccAWSKinesisStream_shardLevelMetrics
=== PAUSE TestAccAWSKinesisStream_shardLevelMetrics
=== RUN TestAccAWSKinesisStream_enforceConsumerDeletion
=== PAUSE TestAccAWSKinesisStream_enforceConsumerDeletion
=== RUN TestAccAWSKinesisStream_Tags
=== PAUSE TestAccAWSKinesisStream_Tags
=== CONT TestAccAWSKinesisStream_basic
=== CONT TestAccAWSKinesisStream_retentionPeriod
=== CONT TestAccAWSKinesisStream_Tags
=== CONT TestAccAWSKinesisStream_enforceConsumerDeletion
=== CONT TestAccAWSKinesisStream_shardLevelMetrics
=== CONT TestAccAWSKinesisStream_encryptionWithoutKmsKeyThrowsError
=== CONT TestAccAWSKinesisStream_createMultipleConcurrentStreams
=== CONT TestAccAWSKinesisStream_shardCount
=== CONT TestAccAWSKinesisStream_encryption
--- PASS: TestAccAWSKinesisStream_encryptionWithoutKmsKeyThrowsError (56.87s)
--- PASS: TestAccAWSKinesisStream_basic (78.59s)
--- PASS: TestAccAWSKinesisStream_enforceConsumerDeletion (79.44s)
--- PASS: TestAccAWSKinesisStream_retentionPeriod (140.28s)
--- PASS: TestAccAWSKinesisStream_shardLevelMetrics (152.38s)
--- PASS: TestAccAWSKinesisStream_shardCount (157.12s)
--- PASS: TestAccAWSKinesisStream_createMultipleConcurrentStreams (159.59s)
--- PASS: TestAccAWSKinesisStream_Tags (164.11s)
--- PASS: TestAccAWSKinesisStream_encryption (202.96s)
PASS
ok github.com/terraform-providers/terraform-provider-aws/aws 203.034s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great and nice implementation, @ewbankkit 🚀
Output from acceptance testing:
--- PASS: TestAccAWSKinesisStream_basic (60.09s)
--- PASS: TestAccAWSKinesisStream_createMultipleConcurrentStreams (175.57s)
--- PASS: TestAccAWSKinesisStream_encryption (166.80s)
--- PASS: TestAccAWSKinesisStream_encryptionWithoutKmsKeyThrowsError (46.62s)
--- PASS: TestAccAWSKinesisStream_enforceConsumerDeletion (60.54s)
--- PASS: TestAccAWSKinesisStream_retentionPeriod (89.48s)
--- PASS: TestAccAWSKinesisStream_shardCount (124.02s)
--- PASS: TestAccAWSKinesisStream_shardLevelMetrics (110.65s)
--- PASS: TestAccAWSKinesisStream_Tags (121.00s)
--- PASS: TestAccAWSKinesisStreamDataSource (151.77s)
{{- 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 }} | ||
{{ . | UntagInputTagsField }}: aws.StringSlice(chunk.Keys()), | ||
{{- end }} | ||
} | ||
|
||
_, err := conn.{{ . | UntagFunction }}(input) | ||
|
||
if err != nil { | ||
return fmt.Errorf("error untagging resource (%s): %w", identifier, err) | ||
} | ||
} | ||
{{- else }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential optimization: Given this nice KeyValueTags.Chunks()
implementation (💯), we might be able to skip redeclaring the majority of the copy-paste template content by re-scoping the removedTags
and updatedTags
variables in the loop:
{{- if . | TagFunctionBatchSize }}
for _, removedTags := range removedTags.Chunks({{ . | TagFunctionBatchSize }}) {
{{- end }}
The template generator should automatically fix up the formatting whether it should be nested for the looping or not. This doesn't seem worth holding up this merge though. 😄
We could also support always calling for _, removedTags := range removedTags.Chunks(-1)
for other services and forego the template conditional, but only adding the looping logic when batching is enabled seems more right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR submitted: #11502
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bflad Nice,
I didn't know about the formatting fix up with the template generator and had thought about something like:
{{- if . | TagFunctionBatchSize }}
chunks := removedTags.Chunks({{ . | TagFunctionBatchSize }})
{{- else }}
chunks := []KeyValueTags{removedTags}
{{- end }}
…g support Reference: #11352 (comment) Updated via: ``` make gen ``` Output from acceptance testing: ``` --- PASS: TestAccAWSKinesisStream_Tags (219.62s) ```
This has been released in version 2.44.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks! |
…g support Reference: #11352 (comment) Updated via: ``` make gen ``` Output from acceptance testing: ``` --- PASS: TestAccAWSKinesisStream_Tags (219.62s) ```
…g support (#11502) Reference: #11352 (comment) Updated via: ``` make gen ``` Output from acceptance testing: ``` --- PASS: TestAccAWSKinesisStream_Tags (219.62s) ```
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks! |
Community Note
Relates #10688.
Release note for CHANGELOG:
Output from acceptance testing: