From 4680076a6b3f9f91452fac3653740cdb16ced120 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Thu, 26 Sep 2024 12:05:27 -0400 Subject: [PATCH 1/4] r/aws_kinesis_stream: Tag on create. --- internal/service/kinesis/generate.go | 2 +- internal/service/kinesis/stream.go | 5 +---- internal/service/kinesis/tags_gen.go | 9 --------- 3 files changed, 2 insertions(+), 14 deletions(-) diff --git a/internal/service/kinesis/generate.go b/internal/service/kinesis/generate.go index f7017028acb..568cfdabb74 100644 --- a/internal/service/kinesis/generate.go +++ b/internal/service/kinesis/generate.go @@ -1,7 +1,7 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 -//go:generate go run ../../generate/tags/main.go -ListTags -ListTagsOp=ListTagsForStream -ListTagsInIDElem=StreamName -ServiceTagsSlice -TagOp=AddTagsToStream -TagOpBatchSize=10 -TagInCustomVal=updatedTags.IgnoreAWS().Map() -TagInIDElem=StreamName -UntagOp=RemoveTagsFromStream -UpdateTags -CreateTags +//go:generate go run ../../generate/tags/main.go -ListTags -ListTagsOp=ListTagsForStream -ListTagsInIDElem=StreamName -ServiceTagsSlice -TagOp=AddTagsToStream -TagOpBatchSize=10 -TagInCustomVal=updatedTags.IgnoreAWS().Map() -TagInIDElem=StreamName -UntagOp=RemoveTagsFromStream -UpdateTags //go:generate go run ../../generate/servicepackage/main.go // ONLY generate directives and package declaration! Do not add anything else to this file. diff --git a/internal/service/kinesis/stream.go b/internal/service/kinesis/stream.go index d8009ea1ffa..c5e94b83265 100644 --- a/internal/service/kinesis/stream.go +++ b/internal/service/kinesis/stream.go @@ -155,6 +155,7 @@ func resourceStreamCreate(ctx context.Context, d *schema.ResourceData, meta inte name := d.Get(names.AttrName).(string) input := &kinesis.CreateStreamInput{ StreamName: aws.String(name), + Tags: KeyValueTags(ctx, getTagsIn(ctx)).Map(), } if v, ok := d.GetOk("stream_mode_details"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { @@ -240,10 +241,6 @@ func resourceStreamCreate(ctx context.Context, d *schema.ResourceData, meta inte } } - if err := createTags(ctx, conn, name, getTagsIn(ctx)); err != nil { - return sdkdiag.AppendErrorf(diags, "setting Kinesis Stream (%s) tags: %s", name, err) - } - return append(diags, resourceStreamRead(ctx, d, meta)...) } diff --git a/internal/service/kinesis/tags_gen.go b/internal/service/kinesis/tags_gen.go index 020134fd844..48eb1b5adf5 100644 --- a/internal/service/kinesis/tags_gen.go +++ b/internal/service/kinesis/tags_gen.go @@ -97,15 +97,6 @@ func setTagsOut(ctx context.Context, tags []awstypes.Tag) { } } -// createTags creates kinesis service tags for new resources. -func createTags(ctx context.Context, conn *kinesis.Client, identifier string, tags []awstypes.Tag, optFns ...func(*kinesis.Options)) error { - if len(tags) == 0 { - return nil - } - - return updateTags(ctx, conn, identifier, nil, KeyValueTags(ctx, tags), optFns...) -} - // updateTags updates kinesis service tags. // The identifier is typically the Amazon Resource Name (ARN), although // it may also be a different identifier depending on the service. From 4d43bf62130523e605d8de60b6b8c4bc2802a149 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Thu, 26 Sep 2024 12:08:22 -0400 Subject: [PATCH 2/4] Add CHANGELOG entry. --- .changelog/#####.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/#####.txt diff --git a/.changelog/#####.txt b/.changelog/#####.txt new file mode 100644 index 00000000000..07524068b2f --- /dev/null +++ b/.changelog/#####.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_kinesis_stream: Tag on Create to support attribute-based access control (ABAC) +``` \ No newline at end of file From 9cb2357923e8af956e1b0aa4c954b81dc26541da Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Thu, 26 Sep 2024 12:10:07 -0400 Subject: [PATCH 3/4] Correct CHANGELOG entry file name. --- .changelog/{#####.txt => 39504.txt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .changelog/{#####.txt => 39504.txt} (100%) diff --git a/.changelog/#####.txt b/.changelog/39504.txt similarity index 100% rename from .changelog/#####.txt rename to .changelog/39504.txt From 62f6693a85b4e41f3a360cda971642a3c7b263a9 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Thu, 26 Sep 2024 12:14:42 -0400 Subject: [PATCH 4/4] Fix 'ValidationException: 1 validation error detected: Value '{}' at 'tags' failed to satisfy constraint: Member must have length greater than or equal to 1'. --- internal/service/kinesis/stream.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/service/kinesis/stream.go b/internal/service/kinesis/stream.go index c5e94b83265..444bfc85b8b 100644 --- a/internal/service/kinesis/stream.go +++ b/internal/service/kinesis/stream.go @@ -155,7 +155,6 @@ func resourceStreamCreate(ctx context.Context, d *schema.ResourceData, meta inte name := d.Get(names.AttrName).(string) input := &kinesis.CreateStreamInput{ StreamName: aws.String(name), - Tags: KeyValueTags(ctx, getTagsIn(ctx)).Map(), } if v, ok := d.GetOk("stream_mode_details"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { @@ -166,6 +165,10 @@ func resourceStreamCreate(ctx context.Context, d *schema.ResourceData, meta inte input.ShardCount = aws.Int32(int32(d.Get("shard_count").(int))) } + if tags := KeyValueTags(ctx, getTagsIn(ctx)).Map(); len(tags) > 0 { + input.Tags = tags + } + _, err := conn.CreateStream(ctx, input) if err != nil {