From 8e96ad4841e486aa6cb4a2bbc2499baaddd964ab Mon Sep 17 00:00:00 2001 From: Travis Rutledge Date: Fri, 27 Sep 2024 18:06:20 -0400 Subject: [PATCH 01/14] Add tags and tags_all to event_source_mapping.go --- internal/service/emr/cluster.go | 6 +++ .../service/lambda/event_source_mapping.go | 18 ++++++++- .../lambda/event_source_mapping_test.go | 39 +++++++++++++++++++ internal/service/lambda/tags.go | 18 +++++++++ 4 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 internal/service/lambda/tags.go diff --git a/internal/service/emr/cluster.go b/internal/service/emr/cluster.go index 7e352f88bd9..b41260c9093 100644 --- a/internal/service/emr/cluster.go +++ b/internal/service/emr/cluster.go @@ -100,6 +100,12 @@ func resourceCluster() *schema.Resource { }, }, }, + "custom_ami_id": { + Type: schema.TypeString, + ForceNew: true, + Optional: true, + ValidateFunc: validCustomAMIID, + }, "ebs_config": { Type: schema.TypeSet, Optional: true, diff --git a/internal/service/lambda/event_source_mapping.go b/internal/service/lambda/event_source_mapping.go index d6e1e0d4ba9..5fec6382cdf 100644 --- a/internal/service/lambda/event_source_mapping.go +++ b/internal/service/lambda/event_source_mapping.go @@ -16,8 +16,10 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/lambda" awstypes "github.com/aws/aws-sdk-go-v2/service/lambda/types" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -26,6 +28,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/flex" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" + tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -348,6 +351,8 @@ func resourceEventSourceMapping() *schema.Resource { Type: schema.TypeString, Computed: true, }, + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), "topics": { Type: schema.TypeSet, Optional: true, @@ -367,6 +372,10 @@ func resourceEventSourceMapping() *schema.Resource { Computed: true, }, }, + + CustomizeDiff: customdiff.Sequence( + verify.SetTagsDiff, + ), } } @@ -378,6 +387,7 @@ func resourceEventSourceMappingCreate(ctx context.Context, d *schema.ResourceDat input := &lambda.CreateEventSourceMappingInput{ Enabled: aws.Bool(d.Get(names.AttrEnabled).(bool)), FunctionName: aws.String(functionName), + Tags: getTagsIn(ctx), } var target string @@ -468,7 +478,7 @@ func resourceEventSourceMappingCreate(ctx context.Context, d *schema.ResourceDat input.StartingPositionTimestamp = aws.Time(t) } - + if v, ok := d.GetOk("topics"); ok && v.(*schema.Set).Len() > 0 { input.Topics = flex.ExpandStringValueSet(v.(*schema.Set)) } @@ -502,10 +512,15 @@ func resourceEventSourceMappingCreate(ctx context.Context, d *schema.ResourceDat func resourceEventSourceMappingRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics + var tags tftags.KeyValueTags conn := meta.(*conns.AWSClient).LambdaClient(ctx) + + output, err := findEventSourceMappingByID(ctx, conn, d.Id()) + tags, err = listTags(ctx, conn, aws.ToString(output.EventSourceMappingArn)) + if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Lambda Event Source Mapping (%s) not found, removing from state", d.Id()) d.SetId("") @@ -595,6 +610,7 @@ func resourceEventSourceMappingRead(ctx context.Context, d *schema.ResourceData, d.Set(names.AttrState, output.State) d.Set("state_transition_reason", output.StateTransitionReason) d.Set("topics", output.Topics) + setKeyValueTagsOut(ctx, tags) d.Set("tumbling_window_in_seconds", output.TumblingWindowInSeconds) d.Set("uuid", output.UUID) diff --git a/internal/service/lambda/event_source_mapping_test.go b/internal/service/lambda/event_source_mapping_test.go index eaac574bc2d..eb22331adce 100644 --- a/internal/service/lambda/event_source_mapping_test.go +++ b/internal/service/lambda/event_source_mapping_test.go @@ -114,6 +114,30 @@ func TestAccLambdaEventSourceMapping_KMSKeyARN(t *testing.T) { }) } +func TestAccLambdaEventSourceMapping_Tags(t *testing.T) { + ctx := acctest.Context(t) + var conf lambda.GetEventSourceMappingOutput + resourceName := "aws_lambda_event_source_mapping.test" + functionResourceName := "aws_lambda_function.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.LambdaServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckEventSourceMappingDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccEventSourceMappingConfig_tags(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckEventSourceMappingExists(ctx, resourceName, &conf), + resource.TestCheckResourceAttrPair(resourceName, "function_name", functionResourceName, names.AttrARN), + ), + }, + }, + }) +} + func TestAccLambdaEventSourceMapping_SQS_basic(t *testing.T) { ctx := acctest.Context(t) var conf lambda.GetEventSourceMappingOutput @@ -2152,6 +2176,21 @@ resource "aws_lambda_event_source_mapping" "test" { `, batchSize)) } +func testAccEventSourceMappingConfig_tags(rName string) string { + return acctest.ConfigCompose(testAccEventSourceMappingConfig_kinesisBase(rName), fmt.Sprintf(` +resource "aws_lambda_event_source_mapping" "test" { + enabled = true + event_source_arn = aws_kinesis_stream.test.arn + function_name = aws_lambda_function.test.function_name + starting_position = "TRIM_HORIZON" + + tags = { + Name = %[1]q + } +} +`, rName)) +} + func testAccEventSourceMappingConfig_kinesisUpdateFunctionName(rName string) string { return acctest.ConfigCompose(testAccEventSourceMappingConfig_kinesisBase(rName), fmt.Sprintf(` resource "aws_lambda_function" "test_update" { diff --git a/internal/service/lambda/tags.go b/internal/service/lambda/tags.go new file mode 100644 index 00000000000..1bc20c504db --- /dev/null +++ b/internal/service/lambda/tags.go @@ -0,0 +1,18 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package lambda + +import ( + "context" + + tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" + "github.com/hashicorp/terraform-provider-aws/internal/types/option" +) + +// setTagsOut sets KeyValueTags in Context. +func setKeyValueTagsOut(ctx context.Context, tags tftags.KeyValueTags) { + if inContext, ok := tftags.FromContext(ctx); ok { + inContext.TagsOut = option.Some(tags) + } +} \ No newline at end of file From a600731374819315cf002c2c2d04a8d94591dfbc Mon Sep 17 00:00:00 2001 From: Travis Rutledge Date: Mon, 30 Sep 2024 10:00:27 -0400 Subject: [PATCH 02/14] add support for tags to lambda_code_signing_config --- .changelog/change.txt | 7 +++ .../service/lambda/code_signing_config.go | 13 ++++++ .../lambda/code_signing_config_test.go | 45 +++++++++++++++++++ .../service/lambda/event_source_mapping.go | 2 - .../lambda_code_signing_config.html.markdown | 6 +++ .../lambda_event_source_mapping.html.markdown | 6 +++ 6 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 .changelog/change.txt diff --git a/.changelog/change.txt b/.changelog/change.txt new file mode 100644 index 00000000000..c7f9ac3cca9 --- /dev/null +++ b/.changelog/change.txt @@ -0,0 +1,7 @@ +```release-note:enhancement +resource/aws_lambda_event_source_mapping: Add tag support. +``` + +```release-note:enhancement +resource/aws_lambda_code_signing_config: Add tag support. +``` \ No newline at end of file diff --git a/internal/service/lambda/code_signing_config.go b/internal/service/lambda/code_signing_config.go index 69c6eadab18..66b54d1e7fe 100644 --- a/internal/service/lambda/code_signing_config.go +++ b/internal/service/lambda/code_signing_config.go @@ -12,6 +12,7 @@ import ( awstypes "github.com/aws/aws-sdk-go-v2/service/lambda/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -20,6 +21,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/flex" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" + tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -88,7 +90,13 @@ func resourceCodeSigningConfig() *schema.Resource { }, }, }, + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), }, + + CustomizeDiff: customdiff.Sequence( + verify.SetTagsDiff, + ), } } @@ -99,6 +107,7 @@ func resourceCodeSigningConfigCreate(ctx context.Context, d *schema.ResourceData input := &lambda.CreateCodeSigningConfigInput{ AllowedPublishers: expandAllowedPublishers(d.Get("allowed_publishers").([]interface{})), Description: aws.String(d.Get(names.AttrDescription).(string)), + Tags: getTagsIn(ctx), } if v, ok := d.GetOk("policies"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { @@ -121,10 +130,13 @@ func resourceCodeSigningConfigCreate(ctx context.Context, d *schema.ResourceData func resourceCodeSigningConfigRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics + var tags tftags.KeyValueTags conn := meta.(*conns.AWSClient).LambdaClient(ctx) output, err := findCodeSigningConfigByARN(ctx, conn, d.Id()) + tags, err = listTags(ctx, conn, aws.ToString(output.CodeSigningConfigArn)) + if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Lambda Code Signing Config %s not found, removing from state", d.Id()) d.SetId("") @@ -145,6 +157,7 @@ func resourceCodeSigningConfigRead(ctx context.Context, d *schema.ResourceData, if err := d.Set("policies", flattenCodeSigningPolicies(output.CodeSigningPolicies)); err != nil { return sdkdiag.AppendErrorf(diags, "setting policies: %s", err) } + setKeyValueTagsOut(ctx, tags) return diags } diff --git a/internal/service/lambda/code_signing_config_test.go b/internal/service/lambda/code_signing_config_test.go index be0b8ed6d5b..5571aa6ce14 100644 --- a/internal/service/lambda/code_signing_config_test.go +++ b/internal/service/lambda/code_signing_config_test.go @@ -10,6 +10,7 @@ import ( awstypes "github.com/aws/aws-sdk-go-v2/service/lambda/types" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-aws/internal/acctest" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -51,6 +52,31 @@ func TestAccLambdaCodeSigningConfig_basic(t *testing.T) { }) } +func TestAccLambdaCodeSigningConfig_Tags(t *testing.T) { + ctx := acctest.Context(t) + resourceName := "aws_lambda_code_signing_config.code_signing_config" + signingProfile1 := "aws_signer_signing_profile.test1" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + var conf awstypes.CodeSigningConfig + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.LambdaServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckCodeSigningConfigDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccCodeSigningConfigConfig_tags(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckCodeSigningConfigExists(ctx, resourceName, &conf), + resource.TestCheckResourceAttr(resourceName, "allowed_publishers.0.signing_profile_version_arns.#", acctest.Ct1), + resource.TestCheckTypeSetElemAttrPair(resourceName, "allowed_publishers.0.signing_profile_version_arns.*", signingProfile1, "version_arn"), + ), + }, + }, + }) +} + func TestAccLambdaCodeSigningConfig_disappears(t *testing.T) { ctx := acctest.Context(t) resourceName := "aws_lambda_code_signing_config.code_signing_config" @@ -222,6 +248,25 @@ resource "aws_lambda_code_signing_config" "code_signing_config" { }` } +func testAccCodeSigningConfigConfig_tags(rName string) string { + return fmt.Sprintf(` +resource "aws_signer_signing_profile" "test1" { + platform_id = "AWSLambda-SHA384-ECDSA" +} + +resource "aws_lambda_code_signing_config" "code_signing_config" { + allowed_publishers { + signing_profile_version_arns = [ + aws_signer_signing_profile.test1.version_arn, + ] + } + + tags = { + Name = %[1]q + } +}`, rName) +} + func testAccCodeSigningConfigConfig_updatePublishers() string { return ` resource "aws_signer_signing_profile" "test1" { diff --git a/internal/service/lambda/event_source_mapping.go b/internal/service/lambda/event_source_mapping.go index 5fec6382cdf..63512ba454b 100644 --- a/internal/service/lambda/event_source_mapping.go +++ b/internal/service/lambda/event_source_mapping.go @@ -515,8 +515,6 @@ func resourceEventSourceMappingRead(ctx context.Context, d *schema.ResourceData, var tags tftags.KeyValueTags conn := meta.(*conns.AWSClient).LambdaClient(ctx) - - output, err := findEventSourceMappingByID(ctx, conn, d.Id()) tags, err = listTags(ctx, conn, aws.ToString(output.EventSourceMappingArn)) diff --git a/website/docs/r/lambda_code_signing_config.html.markdown b/website/docs/r/lambda_code_signing_config.html.markdown index c83a99eb341..2113001fe23 100644 --- a/website/docs/r/lambda_code_signing_config.html.markdown +++ b/website/docs/r/lambda_code_signing_config.html.markdown @@ -28,6 +28,10 @@ resource "aws_lambda_code_signing_config" "new_csc" { } description = "My awesome code signing config." + + tags = { + Name = "dynamodb" + } } ``` @@ -36,6 +40,7 @@ resource "aws_lambda_code_signing_config" "new_csc" { * `allowed_publishers` (Required) A configuration block of allowed publishers as signing profiles for this code signing configuration. Detailed below. * `policies` (Optional) A configuration block of code signing policies that define the actions to take if the validation checks fail. Detailed below. * `description` - (Optional) Descriptive name for this code signing configuration. +* `tags` - (Optional) Map of tags to assign to the object. If configured with a provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level. The `allowed_publishers` block supports the following argument: @@ -52,6 +57,7 @@ This resource exports the following attributes in addition to the arguments abov * `arn` - The Amazon Resource Name (ARN) of the code signing configuration. * `config_id` - Unique identifier for the code signing configuration. * `last_modified` - The date and time that the code signing configuration was last modified. +* `tags_all` - A map of tags assigned to the resource, including those inherited from the provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block). [1]: https://docs.aws.amazon.com/lambda/latest/dg/configuration-codesigning.html diff --git a/website/docs/r/lambda_event_source_mapping.html.markdown b/website/docs/r/lambda_event_source_mapping.html.markdown index db41b29cb2f..fe117ca77d6 100644 --- a/website/docs/r/lambda_event_source_mapping.html.markdown +++ b/website/docs/r/lambda_event_source_mapping.html.markdown @@ -22,6 +22,10 @@ resource "aws_lambda_event_source_mapping" "example" { event_source_arn = aws_dynamodb_table.example.stream_arn function_name = aws_lambda_function.example.arn starting_position = "LATEST" + + tags = { + Name = "dynamodb" + } } ``` @@ -169,6 +173,7 @@ resource "aws_lambda_event_source_mapping" "example" { * `source_access_configuration`: (Optional) For Self Managed Kafka sources, the access configuration for the source. If set, configuration must also include `self_managed_event_source`. Detailed below. * `starting_position` - (Optional) The position in the stream where AWS Lambda should start reading. Must be one of `AT_TIMESTAMP` (Kinesis only), `LATEST` or `TRIM_HORIZON` if getting events from Kinesis, DynamoDB, MSK or Self Managed Apache Kafka. Must not be provided if getting events from SQS. More information about these positions can be found in the [AWS DynamoDB Streams API Reference](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_streams_GetShardIterator.html) and [AWS Kinesis API Reference](https://docs.aws.amazon.com/kinesis/latest/APIReference/API_GetShardIterator.html#Kinesis-GetShardIterator-request-ShardIteratorType). * `starting_position_timestamp` - (Optional) A timestamp in [RFC3339 format](https://tools.ietf.org/html/rfc3339#section-5.8) of the data record which to start reading when using `starting_position` set to `AT_TIMESTAMP`. If a record with this exact timestamp does not exist, the next later record is chosen. If the timestamp is older than the current trim horizon, the oldest available record is chosen. +* `tags` - (Optional) Map of tags to assign to the object. If configured with a provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level. * `topics` - (Optional) The name of the Kafka topics. Only available for MSK sources. A single topic name must be specified. * `tumbling_window_in_seconds` - (Optional) The duration in seconds of a processing window for [AWS Lambda streaming analytics](https://docs.aws.amazon.com/lambda/latest/dg/with-kinesis.html#services-kinesis-windows). The range is between 1 second up to 900 seconds. Only available for stream sources (DynamoDB and Kinesis). @@ -222,6 +227,7 @@ This resource exports the following attributes in addition to the arguments abov * `function_arn` - The the ARN of the Lambda function the event source mapping is sending events to. (Note: this is a computed value that differs from `function_name` above.) * `last_modified` - The date this resource was last modified. * `last_processing_result` - The result of the last AWS Lambda invocation of your Lambda function. +* `tags_all` - A map of tags assigned to the resource, including those inherited from the provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block). * `state` - The state of the event source mapping. * `state_transition_reason` - The reason the event source mapping is in its current state. * `uuid` - The UUID of the created event source mapping. From 0603f3b6edfc8e5a5dec9f7b9486c6b160740ade Mon Sep 17 00:00:00 2001 From: Travis Rutledge Date: Mon, 30 Sep 2024 10:38:20 -0400 Subject: [PATCH 03/14] formatting files and updating changelog --- internal/service/lambda/code_signing_config.go | 6 +++--- internal/service/lambda/code_signing_config_test.go | 2 +- internal/service/lambda/event_source_mapping.go | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/internal/service/lambda/code_signing_config.go b/internal/service/lambda/code_signing_config.go index 66b54d1e7fe..c0f3dafa239 100644 --- a/internal/service/lambda/code_signing_config.go +++ b/internal/service/lambda/code_signing_config.go @@ -11,8 +11,8 @@ import ( "github.com/aws/aws-sdk-go-v2/service/lambda" awstypes "github.com/aws/aws-sdk-go-v2/service/lambda/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -20,8 +20,8 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/flex" - "github.com/hashicorp/terraform-provider-aws/internal/tfresource" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -107,7 +107,7 @@ func resourceCodeSigningConfigCreate(ctx context.Context, d *schema.ResourceData input := &lambda.CreateCodeSigningConfigInput{ AllowedPublishers: expandAllowedPublishers(d.Get("allowed_publishers").([]interface{})), Description: aws.String(d.Get(names.AttrDescription).(string)), - Tags: getTagsIn(ctx), + Tags: getTagsIn(ctx), } if v, ok := d.GetOk("policies"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { diff --git a/internal/service/lambda/code_signing_config_test.go b/internal/service/lambda/code_signing_config_test.go index 5571aa6ce14..3dcfdd21a15 100644 --- a/internal/service/lambda/code_signing_config_test.go +++ b/internal/service/lambda/code_signing_config_test.go @@ -9,8 +9,8 @@ import ( "testing" awstypes "github.com/aws/aws-sdk-go-v2/service/lambda/types" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-aws/internal/acctest" "github.com/hashicorp/terraform-provider-aws/internal/conns" diff --git a/internal/service/lambda/event_source_mapping.go b/internal/service/lambda/event_source_mapping.go index 63512ba454b..9f7713aa914 100644 --- a/internal/service/lambda/event_source_mapping.go +++ b/internal/service/lambda/event_source_mapping.go @@ -16,10 +16,10 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/lambda" awstypes "github.com/aws/aws-sdk-go-v2/service/lambda/types" - + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -27,8 +27,8 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/flex" - "github.com/hashicorp/terraform-provider-aws/internal/tfresource" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -387,7 +387,7 @@ func resourceEventSourceMappingCreate(ctx context.Context, d *schema.ResourceDat input := &lambda.CreateEventSourceMappingInput{ Enabled: aws.Bool(d.Get(names.AttrEnabled).(bool)), FunctionName: aws.String(functionName), - Tags: getTagsIn(ctx), + Tags: getTagsIn(ctx), } var target string @@ -478,7 +478,7 @@ func resourceEventSourceMappingCreate(ctx context.Context, d *schema.ResourceDat input.StartingPositionTimestamp = aws.Time(t) } - + if v, ok := d.GetOk("topics"); ok && v.(*schema.Set).Len() > 0 { input.Topics = flex.ExpandStringValueSet(v.(*schema.Set)) } From 307584a13f8d88ddc64dafe6945170c7325ff6d0 Mon Sep 17 00:00:00 2001 From: Travis Rutledge Date: Mon, 30 Sep 2024 10:41:19 -0400 Subject: [PATCH 04/14] formatting --- internal/service/lambda/tags.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/lambda/tags.go b/internal/service/lambda/tags.go index 1bc20c504db..9bbf5f7647b 100644 --- a/internal/service/lambda/tags.go +++ b/internal/service/lambda/tags.go @@ -15,4 +15,4 @@ func setKeyValueTagsOut(ctx context.Context, tags tftags.KeyValueTags) { if inContext, ok := tftags.FromContext(ctx); ok { inContext.TagsOut = option.Some(tags) } -} \ No newline at end of file +} From 800dfcedeb404cd5897e365b0e46358b6b0b730a Mon Sep 17 00:00:00 2001 From: Travis Rutledge Date: Mon, 30 Sep 2024 10:48:56 -0400 Subject: [PATCH 05/14] removing new line --- internal/service/lambda/event_source_mapping.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/service/lambda/event_source_mapping.go b/internal/service/lambda/event_source_mapping.go index 9f7713aa914..bab6570a18a 100644 --- a/internal/service/lambda/event_source_mapping.go +++ b/internal/service/lambda/event_source_mapping.go @@ -16,7 +16,6 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/lambda" awstypes "github.com/aws/aws-sdk-go-v2/service/lambda/types" - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" From 1fd8937da0bf8a2a93548230be088aca1c504594 Mon Sep 17 00:00:00 2001 From: Travis Rutledge Date: Mon, 30 Sep 2024 14:12:36 -0400 Subject: [PATCH 06/14] fixing ineffectual assignment to err warnings --- internal/service/lambda/code_signing_config.go | 6 ++++++ internal/service/lambda/event_source_mapping.go | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/internal/service/lambda/code_signing_config.go b/internal/service/lambda/code_signing_config.go index c0f3dafa239..056002b1103 100644 --- a/internal/service/lambda/code_signing_config.go +++ b/internal/service/lambda/code_signing_config.go @@ -134,8 +134,14 @@ func resourceCodeSigningConfigRead(ctx context.Context, d *schema.ResourceData, conn := meta.(*conns.AWSClient).LambdaClient(ctx) output, err := findCodeSigningConfigByARN(ctx, conn, d.Id()) + if err != nil { + return sdkdiag.AppendErrorf(diags, "finding Lambda Code Signing Config: %s", err) + } tags, err = listTags(ctx, conn, aws.ToString(output.CodeSigningConfigArn)) + if err != nil { + return sdkdiag.AppendErrorf(diags, "finding Lambda Code Signing Config: %s", err) + } if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Lambda Code Signing Config %s not found, removing from state", d.Id()) diff --git a/internal/service/lambda/event_source_mapping.go b/internal/service/lambda/event_source_mapping.go index bab6570a18a..4ac8ced9ea9 100644 --- a/internal/service/lambda/event_source_mapping.go +++ b/internal/service/lambda/event_source_mapping.go @@ -515,8 +515,14 @@ func resourceEventSourceMappingRead(ctx context.Context, d *schema.ResourceData, conn := meta.(*conns.AWSClient).LambdaClient(ctx) output, err := findEventSourceMappingByID(ctx, conn, d.Id()) + if err != nil { + return sdkdiag.AppendErrorf(diags, "finding Lambda Event Source Mapping Config: %s", err) + } tags, err = listTags(ctx, conn, aws.ToString(output.EventSourceMappingArn)) + if err != nil { + return sdkdiag.AppendErrorf(diags, "finding Lambda Event Source Mapping Config: %s", err) + } if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Lambda Event Source Mapping (%s) not found, removing from state", d.Id()) From 6aed291efb3a478f7e5edf3d5540b9fc06ebc5c0 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 1 Oct 2024 08:08:53 -0400 Subject: [PATCH 07/14] Correct CHANGELOG entry file name. --- .changelog/{change.txt => 39535.txt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .changelog/{change.txt => 39535.txt} (100%) diff --git a/.changelog/change.txt b/.changelog/39535.txt similarity index 100% rename from .changelog/change.txt rename to .changelog/39535.txt From cdaad477e3595e1fd45757c5df0a882d4ef36cd8 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 1 Oct 2024 08:10:11 -0400 Subject: [PATCH 08/14] Tweak CHANGELOG entries. --- .changelog/39535.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.changelog/39535.txt b/.changelog/39535.txt index c7f9ac3cca9..9d31a101533 100644 --- a/.changelog/39535.txt +++ b/.changelog/39535.txt @@ -1,7 +1,7 @@ ```release-note:enhancement -resource/aws_lambda_event_source_mapping: Add tag support. +resource/aws_lambda_event_source_mapping: Add `tags` argument and `tags_all` attribute ``` ```release-note:enhancement -resource/aws_lambda_code_signing_config: Add tag support. +resource/aws_lambda_code_signing_config: Add `tags` argument and `tags_all` attribute ``` \ No newline at end of file From 4fc0c3569387c88afea69e4d042cc2f8d94626be Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 1 Oct 2024 08:31:03 -0400 Subject: [PATCH 09/14] r/aws_lambda_event_source_mapping: Add and use 'arn' attribute. --- .changelog/39535.txt | 4 + .../service/lambda/event_source_mapping.go | 167 +++++++++--------- .../lambda/event_source_mapping_test.go | 53 +++++- .../service/lambda/service_package_gen.go | 3 + .../lambda_event_source_mapping.html.markdown | 5 +- 5 files changed, 139 insertions(+), 93 deletions(-) diff --git a/.changelog/39535.txt b/.changelog/39535.txt index 9d31a101533..f706362a68d 100644 --- a/.changelog/39535.txt +++ b/.changelog/39535.txt @@ -2,6 +2,10 @@ resource/aws_lambda_event_source_mapping: Add `tags` argument and `tags_all` attribute ``` +```release-note:enhancement +resource/aws_lambda_event_source_mapping: Add `arn` attribute +``` + ```release-note:enhancement resource/aws_lambda_code_signing_config: Add `tags` argument and `tags_all` attribute ``` \ No newline at end of file diff --git a/internal/service/lambda/event_source_mapping.go b/internal/service/lambda/event_source_mapping.go index 4ac8ced9ea9..e4472fd35fa 100644 --- a/internal/service/lambda/event_source_mapping.go +++ b/internal/service/lambda/event_source_mapping.go @@ -33,6 +33,8 @@ import ( ) // @SDKResource("aws_lambda_event_source_mapping", name="Event Source Mapping") +// @Tags(identifierAttribute="arn") +// @Testing(tagsTest=false) func resourceEventSourceMapping() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceEventSourceMappingCreate, @@ -64,6 +66,10 @@ func resourceEventSourceMapping() *schema.Resource { }, }, }, + names.AttrARN: { + Type: schema.TypeString, + Computed: true, + }, "batch_size": { Type: schema.TypeInt, Optional: true, @@ -511,18 +517,9 @@ func resourceEventSourceMappingCreate(ctx context.Context, d *schema.ResourceDat func resourceEventSourceMappingRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - var tags tftags.KeyValueTags conn := meta.(*conns.AWSClient).LambdaClient(ctx) output, err := findEventSourceMappingByID(ctx, conn, d.Id()) - if err != nil { - return sdkdiag.AppendErrorf(diags, "finding Lambda Event Source Mapping Config: %s", err) - } - - tags, err = listTags(ctx, conn, aws.ToString(output.EventSourceMappingArn)) - if err != nil { - return sdkdiag.AppendErrorf(diags, "finding Lambda Event Source Mapping Config: %s", err) - } if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Lambda Event Source Mapping (%s) not found, removing from state", d.Id()) @@ -541,6 +538,7 @@ func resourceEventSourceMappingRead(ctx context.Context, d *schema.ResourceData, } else { d.Set("amazon_managed_kafka_event_source_config", nil) } + d.Set(names.AttrARN, output.EventSourceMappingArn) d.Set("batch_size", output.BatchSize) d.Set("bisect_batch_on_function_error", output.BisectBatchOnFunctionError) if output.DestinationConfig != nil { @@ -613,7 +611,6 @@ func resourceEventSourceMappingRead(ctx context.Context, d *schema.ResourceData, d.Set(names.AttrState, output.State) d.Set("state_transition_reason", output.StateTransitionReason) d.Set("topics", output.Topics) - setKeyValueTagsOut(ctx, tags) d.Set("tumbling_window_in_seconds", output.TumblingWindowInSeconds) d.Set("uuid", output.UUID) @@ -634,100 +631,102 @@ func resourceEventSourceMappingUpdate(ctx context.Context, d *schema.ResourceDat var diags diag.Diagnostics conn := meta.(*conns.AWSClient).LambdaClient(ctx) - input := &lambda.UpdateEventSourceMappingInput{ - UUID: aws.String(d.Id()), - } + if d.HasChangesExcept(names.AttrTags, names.AttrTagsAll) { + input := &lambda.UpdateEventSourceMappingInput{ + UUID: aws.String(d.Id()), + } - if d.HasChange("batch_size") { - input.BatchSize = aws.Int32(int32(d.Get("batch_size").(int))) - } + if d.HasChange("batch_size") { + input.BatchSize = aws.Int32(int32(d.Get("batch_size").(int))) + } - if d.HasChange("bisect_batch_on_function_error") { - input.BisectBatchOnFunctionError = aws.Bool(d.Get("bisect_batch_on_function_error").(bool)) - } + if d.HasChange("bisect_batch_on_function_error") { + input.BisectBatchOnFunctionError = aws.Bool(d.Get("bisect_batch_on_function_error").(bool)) + } - if d.HasChange("destination_config") { - if v, ok := d.GetOk("destination_config"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { - input.DestinationConfig = expandDestinationConfig(v.([]interface{})[0].(map[string]interface{})) + if d.HasChange("destination_config") { + if v, ok := d.GetOk("destination_config"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { + input.DestinationConfig = expandDestinationConfig(v.([]interface{})[0].(map[string]interface{})) + } } - } - if d.HasChange("document_db_event_source_config") { - if v, ok := d.GetOk("document_db_event_source_config"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { - input.DocumentDBEventSourceConfig = expandDocumentDBEventSourceConfig(v.([]interface{})[0].(map[string]interface{})) + if d.HasChange("document_db_event_source_config") { + if v, ok := d.GetOk("document_db_event_source_config"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { + input.DocumentDBEventSourceConfig = expandDocumentDBEventSourceConfig(v.([]interface{})[0].(map[string]interface{})) + } } - } - if d.HasChange(names.AttrEnabled) { - input.Enabled = aws.Bool(d.Get(names.AttrEnabled).(bool)) - } + if d.HasChange(names.AttrEnabled) { + input.Enabled = aws.Bool(d.Get(names.AttrEnabled).(bool)) + } - if d.HasChange("filter_criteria") { - if v, ok := d.GetOk("filter_criteria"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { - input.FilterCriteria = expandFilterCriteria(v.([]interface{})[0].(map[string]interface{})) - } else { - // AWS ignores the removal if this is left as nil. - input.FilterCriteria = &awstypes.FilterCriteria{} + if d.HasChange("filter_criteria") { + if v, ok := d.GetOk("filter_criteria"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { + input.FilterCriteria = expandFilterCriteria(v.([]interface{})[0].(map[string]interface{})) + } else { + // AWS ignores the removal if this is left as nil. + input.FilterCriteria = &awstypes.FilterCriteria{} + } } - } - if d.HasChange("function_name") { - input.FunctionName = aws.String(d.Get("function_name").(string)) - } + if d.HasChange("function_name") { + input.FunctionName = aws.String(d.Get("function_name").(string)) + } - if d.HasChange("function_response_types") { - input.FunctionResponseTypes = flex.ExpandStringyValueSet[awstypes.FunctionResponseType](d.Get("function_response_types").(*schema.Set)) - } + if d.HasChange("function_response_types") { + input.FunctionResponseTypes = flex.ExpandStringyValueSet[awstypes.FunctionResponseType](d.Get("function_response_types").(*schema.Set)) + } - if d.HasChange(names.AttrKMSKeyARN) { - input.KMSKeyArn = aws.String(d.Get(names.AttrKMSKeyARN).(string)) - } + if d.HasChange(names.AttrKMSKeyARN) { + input.KMSKeyArn = aws.String(d.Get(names.AttrKMSKeyARN).(string)) + } - if d.HasChange("maximum_batching_window_in_seconds") { - input.MaximumBatchingWindowInSeconds = aws.Int32(int32(d.Get("maximum_batching_window_in_seconds").(int))) - } + if d.HasChange("maximum_batching_window_in_seconds") { + input.MaximumBatchingWindowInSeconds = aws.Int32(int32(d.Get("maximum_batching_window_in_seconds").(int))) + } - if d.HasChange("maximum_record_age_in_seconds") { - input.MaximumRecordAgeInSeconds = aws.Int32(int32(d.Get("maximum_record_age_in_seconds").(int))) - } + if d.HasChange("maximum_record_age_in_seconds") { + input.MaximumRecordAgeInSeconds = aws.Int32(int32(d.Get("maximum_record_age_in_seconds").(int))) + } - if d.HasChange("maximum_retry_attempts") { - input.MaximumRetryAttempts = aws.Int32(int32(d.Get("maximum_retry_attempts").(int))) - } + if d.HasChange("maximum_retry_attempts") { + input.MaximumRetryAttempts = aws.Int32(int32(d.Get("maximum_retry_attempts").(int))) + } - if d.HasChange("parallelization_factor") { - input.ParallelizationFactor = aws.Int32(int32(d.Get("parallelization_factor").(int))) - } + if d.HasChange("parallelization_factor") { + input.ParallelizationFactor = aws.Int32(int32(d.Get("parallelization_factor").(int))) + } - if d.HasChange("scaling_config") { - if v, ok := d.GetOk("scaling_config"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { - input.ScalingConfig = expandScalingConfig(v.([]interface{})[0].(map[string]interface{})) - } else { - // AWS ignores the removal if this is left as nil. - input.ScalingConfig = &awstypes.ScalingConfig{} + if d.HasChange("scaling_config") { + if v, ok := d.GetOk("scaling_config"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { + input.ScalingConfig = expandScalingConfig(v.([]interface{})[0].(map[string]interface{})) + } else { + // AWS ignores the removal if this is left as nil. + input.ScalingConfig = &awstypes.ScalingConfig{} + } } - } - if d.HasChange("source_access_configuration") { - if v, ok := d.GetOk("source_access_configuration"); ok && v.(*schema.Set).Len() > 0 { - input.SourceAccessConfigurations = expandSourceAccessConfigurations(v.(*schema.Set).List()) + if d.HasChange("source_access_configuration") { + if v, ok := d.GetOk("source_access_configuration"); ok && v.(*schema.Set).Len() > 0 { + input.SourceAccessConfigurations = expandSourceAccessConfigurations(v.(*schema.Set).List()) + } } - } - if d.HasChange("tumbling_window_in_seconds") { - input.TumblingWindowInSeconds = aws.Int32(int32(d.Get("tumbling_window_in_seconds").(int))) - } + if d.HasChange("tumbling_window_in_seconds") { + input.TumblingWindowInSeconds = aws.Int32(int32(d.Get("tumbling_window_in_seconds").(int))) + } - _, err := retryEventSourceMapping(ctx, func() (*lambda.UpdateEventSourceMappingOutput, error) { - return conn.UpdateEventSourceMapping(ctx, input) - }) + _, err := retryEventSourceMapping(ctx, func() (*lambda.UpdateEventSourceMappingOutput, error) { + return conn.UpdateEventSourceMapping(ctx, input) + }) - if err != nil { - return sdkdiag.AppendErrorf(diags, "updating Lambda Event Source Mapping (%s): %s", d.Id(), err) - } + if err != nil { + return sdkdiag.AppendErrorf(diags, "updating Lambda Event Source Mapping (%s): %s", d.Id(), err) + } - if _, err := waitEventSourceMappingUpdated(ctx, conn, d.Id()); err != nil { - return sdkdiag.AppendErrorf(diags, "waiting for Lambda Event Source Mapping (%s) update: %s", d.Id(), err) + if _, err := waitEventSourceMappingUpdated(ctx, conn, d.Id()); err != nil { + return sdkdiag.AppendErrorf(diags, "waiting for Lambda Event Source Mapping (%s) update: %s", d.Id(), err) + } } return append(diags, resourceEventSourceMappingRead(ctx, d, meta)...) @@ -824,7 +823,7 @@ func findEventSourceMappingByID(ctx context.Context, conn *lambda.Client, uuid s return findEventSourceMapping(ctx, conn, input) } -func statusEventSourceMappingState(ctx context.Context, conn *lambda.Client, id string) retry.StateRefreshFunc { +func statusEventSourceMapping(ctx context.Context, conn *lambda.Client, id string) retry.StateRefreshFunc { return func() (interface{}, string, error) { output, err := findEventSourceMappingByID(ctx, conn, id) @@ -847,7 +846,7 @@ func waitEventSourceMappingCreated(ctx context.Context, conn *lambda.Client, id stateConf := &retry.StateChangeConf{ Pending: []string{eventSourceMappingStateCreating, eventSourceMappingStateDisabling, eventSourceMappingStateEnabling}, Target: []string{eventSourceMappingStateDisabled, eventSourceMappingStateEnabled}, - Refresh: statusEventSourceMappingState(ctx, conn, id), + Refresh: statusEventSourceMapping(ctx, conn, id), Timeout: timeout, } @@ -869,7 +868,7 @@ func waitEventSourceMappingUpdated(ctx context.Context, conn *lambda.Client, id stateConf := &retry.StateChangeConf{ Pending: []string{eventSourceMappingStateDisabling, eventSourceMappingStateEnabling, eventSourceMappingStateUpdating}, Target: []string{eventSourceMappingStateDisabled, eventSourceMappingStateEnabled}, - Refresh: statusEventSourceMappingState(ctx, conn, id), + Refresh: statusEventSourceMapping(ctx, conn, id), Timeout: timeout, } @@ -891,7 +890,7 @@ func waitEventSourceMappingDeleted(ctx context.Context, conn *lambda.Client, id stateConf := &retry.StateChangeConf{ Pending: []string{eventSourceMappingStateDeleting}, Target: []string{}, - Refresh: statusEventSourceMappingState(ctx, conn, id), + Refresh: statusEventSourceMapping(ctx, conn, id), Timeout: timeout, } diff --git a/internal/service/lambda/event_source_mapping_test.go b/internal/service/lambda/event_source_mapping_test.go index eb22331adce..2652bc6870c 100644 --- a/internal/service/lambda/event_source_mapping_test.go +++ b/internal/service/lambda/event_source_mapping_test.go @@ -47,6 +47,7 @@ func TestAccLambdaEventSourceMapping_Kinesis_basic(t *testing.T) { Config: testAccEventSourceMappingConfig_kinesisBatchSize(rName, "100"), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckEventSourceMappingExists(ctx, resourceName, &conf), + resource.TestCheckResourceAttrSet(resourceName, names.AttrARN), resource.TestCheckResourceAttr(resourceName, "batch_size", "100"), resource.TestCheckResourceAttr(resourceName, names.AttrEnabled, acctest.CtTrue), resource.TestCheckResourceAttrPair(resourceName, "event_source_arn", eventSourceResourceName, names.AttrARN), @@ -114,11 +115,10 @@ func TestAccLambdaEventSourceMapping_KMSKeyARN(t *testing.T) { }) } -func TestAccLambdaEventSourceMapping_Tags(t *testing.T) { +func TestAccLambdaEventSourceMapping_tags(t *testing.T) { ctx := acctest.Context(t) var conf lambda.GetEventSourceMappingOutput resourceName := "aws_lambda_event_source_mapping.test" - functionResourceName := "aws_lambda_function.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ @@ -128,10 +128,33 @@ func TestAccLambdaEventSourceMapping_Tags(t *testing.T) { CheckDestroy: testAccCheckEventSourceMappingDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccEventSourceMappingConfig_tags(rName), + Config: testAccEventSourceMappingConfig_tags1(rName, acctest.CtKey1, acctest.CtValue1), Check: resource.ComposeTestCheckFunc( testAccCheckEventSourceMappingExists(ctx, resourceName, &conf), - resource.TestCheckResourceAttrPair(resourceName, "function_name", functionResourceName, names.AttrARN), + resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, acctest.Ct1), + resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey1, acctest.CtValue1), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccEventSourceMappingConfig_tags2(rName, acctest.CtKey1, acctest.CtValue1Updated, acctest.CtKey2, acctest.CtValue2), + Check: resource.ComposeTestCheckFunc( + testAccCheckEventSourceMappingExists(ctx, resourceName, &conf), + resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, acctest.Ct2), + resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey1, acctest.CtValue1Updated), + resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey2, acctest.CtValue2), + ), + }, + { + Config: testAccEventSourceMappingConfig_tags1(rName, acctest.CtKey2, acctest.CtValue2), + Check: resource.ComposeTestCheckFunc( + testAccCheckEventSourceMappingExists(ctx, resourceName, &conf), + resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, acctest.Ct1), + resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey2, acctest.CtValue2), ), }, }, @@ -2176,7 +2199,7 @@ resource "aws_lambda_event_source_mapping" "test" { `, batchSize)) } -func testAccEventSourceMappingConfig_tags(rName string) string { +func testAccEventSourceMappingConfig_tags1(rName, tagKey1, tagValue1 string) string { return acctest.ConfigCompose(testAccEventSourceMappingConfig_kinesisBase(rName), fmt.Sprintf(` resource "aws_lambda_event_source_mapping" "test" { enabled = true @@ -2185,10 +2208,26 @@ resource "aws_lambda_event_source_mapping" "test" { starting_position = "TRIM_HORIZON" tags = { - Name = %[1]q + %[2]q = %[3]q } } -`, rName)) +`, rName, tagKey1, tagValue1)) +} + +func testAccEventSourceMappingConfig_tags2(rName, tagKey1, tagValue1, tagKey2, tagValue2 string) string { + return acctest.ConfigCompose(testAccEventSourceMappingConfig_kinesisBase(rName), fmt.Sprintf(` +resource "aws_lambda_event_source_mapping" "test" { + enabled = true + event_source_arn = aws_kinesis_stream.test.arn + function_name = aws_lambda_function.test.function_name + starting_position = "TRIM_HORIZON" + + tags = { + %[2]q = %[3]q + %[4]q = %[5]q + } +} +`, rName, tagKey1, tagValue1, tagKey2, tagValue2)) } func testAccEventSourceMappingConfig_kinesisUpdateFunctionName(rName string) string { diff --git a/internal/service/lambda/service_package_gen.go b/internal/service/lambda/service_package_gen.go index a93ee3f2f90..0f8cb13881f 100644 --- a/internal/service/lambda/service_package_gen.go +++ b/internal/service/lambda/service_package_gen.go @@ -87,6 +87,9 @@ func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePacka Factory: resourceEventSourceMapping, TypeName: "aws_lambda_event_source_mapping", Name: "Event Source Mapping", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: names.AttrARN, + }, }, { Factory: resourceFunction, diff --git a/website/docs/r/lambda_event_source_mapping.html.markdown b/website/docs/r/lambda_event_source_mapping.html.markdown index fe117ca77d6..e1191136cae 100644 --- a/website/docs/r/lambda_event_source_mapping.html.markdown +++ b/website/docs/r/lambda_event_source_mapping.html.markdown @@ -224,12 +224,13 @@ resource "aws_lambda_event_source_mapping" "example" { This resource exports the following attributes in addition to the arguments above: -* `function_arn` - The the ARN of the Lambda function the event source mapping is sending events to. (Note: this is a computed value that differs from `function_name` above.) +* `arn` - The event source mapping ARN. +* `function_arn` - The ARN of the Lambda function the event source mapping is sending events to. (Note: this is a computed value that differs from `function_name` above.) * `last_modified` - The date this resource was last modified. * `last_processing_result` - The result of the last AWS Lambda invocation of your Lambda function. -* `tags_all` - A map of tags assigned to the resource, including those inherited from the provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block). * `state` - The state of the event source mapping. * `state_transition_reason` - The reason the event source mapping is in its current state. +* `tags_all` - A map of tags assigned to the resource, including those inherited from the provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block). * `uuid` - The UUID of the created event source mapping. [1]: http://docs.aws.amazon.com/lambda/latest/dg/welcome.html From 3e94dd81288d9ef1dca08565eb285d6b45f1e91a Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 1 Oct 2024 08:39:13 -0400 Subject: [PATCH 10/14] r/aws_lambda_code_signing_config: Use transparent tagging. --- .../service/lambda/code_signing_config.go | 50 ++++++------- .../lambda/code_signing_config_test.go | 73 +++++++++++++++---- .../service/lambda/service_package_gen.go | 3 + internal/service/lambda/tags.go | 18 ----- 4 files changed, 83 insertions(+), 61 deletions(-) delete mode 100644 internal/service/lambda/tags.go diff --git a/internal/service/lambda/code_signing_config.go b/internal/service/lambda/code_signing_config.go index 056002b1103..5f4b1af3520 100644 --- a/internal/service/lambda/code_signing_config.go +++ b/internal/service/lambda/code_signing_config.go @@ -27,6 +27,8 @@ import ( ) // @SDKResource("aws_lambda_code_signing_config", name="Code Signing Config") +// @Tags(identifierAttribute="arn") +// @Testing(tagsTest=false) func resourceCodeSigningConfig() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceCodeSigningConfigCreate, @@ -130,18 +132,9 @@ func resourceCodeSigningConfigCreate(ctx context.Context, d *schema.ResourceData func resourceCodeSigningConfigRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - var tags tftags.KeyValueTags conn := meta.(*conns.AWSClient).LambdaClient(ctx) output, err := findCodeSigningConfigByARN(ctx, conn, d.Id()) - if err != nil { - return sdkdiag.AppendErrorf(diags, "finding Lambda Code Signing Config: %s", err) - } - - tags, err = listTags(ctx, conn, aws.ToString(output.CodeSigningConfigArn)) - if err != nil { - return sdkdiag.AppendErrorf(diags, "finding Lambda Code Signing Config: %s", err) - } if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Lambda Code Signing Config %s not found, removing from state", d.Id()) @@ -163,7 +156,6 @@ func resourceCodeSigningConfigRead(ctx context.Context, d *schema.ResourceData, if err := d.Set("policies", flattenCodeSigningPolicies(output.CodeSigningPolicies)); err != nil { return sdkdiag.AppendErrorf(diags, "setting policies: %s", err) } - setKeyValueTagsOut(ctx, tags) return diags } @@ -172,31 +164,33 @@ func resourceCodeSigningConfigUpdate(ctx context.Context, d *schema.ResourceData var diags diag.Diagnostics conn := meta.(*conns.AWSClient).LambdaClient(ctx) - input := &lambda.UpdateCodeSigningConfigInput{ - CodeSigningConfigArn: aws.String(d.Id()), - } + if d.HasChangesExcept(names.AttrTags, names.AttrTagsAll) { + input := &lambda.UpdateCodeSigningConfigInput{ + CodeSigningConfigArn: aws.String(d.Id()), + } - if d.HasChange("allowed_publishers") { - input.AllowedPublishers = expandAllowedPublishers(d.Get("allowed_publishers").([]interface{})) - } + if d.HasChange("allowed_publishers") { + input.AllowedPublishers = expandAllowedPublishers(d.Get("allowed_publishers").([]interface{})) + } - if d.HasChange(names.AttrDescription) { - input.Description = aws.String(d.Get(names.AttrDescription).(string)) - } + if d.HasChange(names.AttrDescription) { + input.Description = aws.String(d.Get(names.AttrDescription).(string)) + } - if d.HasChange("policies") { - if v, ok := d.GetOk("policies"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { - tfMap := v.([]interface{})[0].(map[string]interface{}) - input.CodeSigningPolicies = &awstypes.CodeSigningPolicies{ - UntrustedArtifactOnDeployment: awstypes.CodeSigningPolicy(tfMap["untrusted_artifact_on_deployment"].(string)), + if d.HasChange("policies") { + if v, ok := d.GetOk("policies"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { + tfMap := v.([]interface{})[0].(map[string]interface{}) + input.CodeSigningPolicies = &awstypes.CodeSigningPolicies{ + UntrustedArtifactOnDeployment: awstypes.CodeSigningPolicy(tfMap["untrusted_artifact_on_deployment"].(string)), + } } } - } - _, err := conn.UpdateCodeSigningConfig(ctx, input) + _, err := conn.UpdateCodeSigningConfig(ctx, input) - if err != nil { - return sdkdiag.AppendErrorf(diags, "updating Lambda Code Signing Config (%s): %s", d.Id(), err) + if err != nil { + return sdkdiag.AppendErrorf(diags, "updating Lambda Code Signing Config (%s): %s", d.Id(), err) + } } return append(diags, resourceCodeSigningConfigRead(ctx, d, meta)...) diff --git a/internal/service/lambda/code_signing_config_test.go b/internal/service/lambda/code_signing_config_test.go index 3dcfdd21a15..69c0aaea92b 100644 --- a/internal/service/lambda/code_signing_config_test.go +++ b/internal/service/lambda/code_signing_config_test.go @@ -52,11 +52,9 @@ func TestAccLambdaCodeSigningConfig_basic(t *testing.T) { }) } -func TestAccLambdaCodeSigningConfig_Tags(t *testing.T) { +func TestAccLambdaCodeSigningConfig_disappears(t *testing.T) { ctx := acctest.Context(t) resourceName := "aws_lambda_code_signing_config.code_signing_config" - signingProfile1 := "aws_signer_signing_profile.test1" - rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) var conf awstypes.CodeSigningConfig resource.ParallelTest(t, resource.TestCase{ @@ -66,20 +64,21 @@ func TestAccLambdaCodeSigningConfig_Tags(t *testing.T) { CheckDestroy: testAccCheckCodeSigningConfigDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccCodeSigningConfigConfig_tags(rName), + Config: testAccCodeSigningConfigConfig_basic(), Check: resource.ComposeTestCheckFunc( testAccCheckCodeSigningConfigExists(ctx, resourceName, &conf), - resource.TestCheckResourceAttr(resourceName, "allowed_publishers.0.signing_profile_version_arns.#", acctest.Ct1), - resource.TestCheckTypeSetElemAttrPair(resourceName, "allowed_publishers.0.signing_profile_version_arns.*", signingProfile1, "version_arn"), + acctest.CheckResourceDisappears(ctx, acctest.Provider, tflambda.ResourceCodeSigningConfig(), resourceName), ), + ExpectNonEmptyPlan: true, }, }, }) } -func TestAccLambdaCodeSigningConfig_disappears(t *testing.T) { +func TestAccLambdaCodeSigningConfig_tags(t *testing.T) { ctx := acctest.Context(t) resourceName := "aws_lambda_code_signing_config.code_signing_config" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) var conf awstypes.CodeSigningConfig resource.ParallelTest(t, resource.TestCase{ @@ -89,12 +88,34 @@ func TestAccLambdaCodeSigningConfig_disappears(t *testing.T) { CheckDestroy: testAccCheckCodeSigningConfigDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccCodeSigningConfigConfig_basic(), + Config: testAccCodeSigningConfigConfig_tags1(rName, acctest.CtKey1, acctest.CtValue1), Check: resource.ComposeTestCheckFunc( testAccCheckCodeSigningConfigExists(ctx, resourceName, &conf), - acctest.CheckResourceDisappears(ctx, acctest.Provider, tflambda.ResourceCodeSigningConfig(), resourceName), + resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, acctest.Ct1), + resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey1, acctest.CtValue1), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccCodeSigningConfigConfig_tags2(rName, acctest.CtKey1, acctest.CtValue1Updated, acctest.CtKey2, acctest.CtValue2), + Check: resource.ComposeTestCheckFunc( + testAccCheckCodeSigningConfigExists(ctx, resourceName, &conf), + resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, acctest.Ct2), + resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey1, acctest.CtValue1Updated), + resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey2, acctest.CtValue2), + ), + }, + { + Config: testAccCodeSigningConfigConfig_tags1(rName, acctest.CtKey2, acctest.CtValue2), + Check: resource.ComposeTestCheckFunc( + testAccCheckCodeSigningConfigExists(ctx, resourceName, &conf), + resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, acctest.Ct1), + resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey2, acctest.CtValue2), ), - ExpectNonEmptyPlan: true, }, }, }) @@ -248,23 +269,45 @@ resource "aws_lambda_code_signing_config" "code_signing_config" { }` } -func testAccCodeSigningConfigConfig_tags(rName string) string { +func testAccCodeSigningConfigConfig_tags1(rName, tagKey1, tagValue1 string) string { return fmt.Sprintf(` -resource "aws_signer_signing_profile" "test1" { +resource "aws_signer_signing_profile" "test" { platform_id = "AWSLambda-SHA384-ECDSA" } resource "aws_lambda_code_signing_config" "code_signing_config" { allowed_publishers { signing_profile_version_arns = [ - aws_signer_signing_profile.test1.version_arn, + aws_signer_signing_profile.test.version_arn, ] } tags = { - Name = %[1]q + %[2]q = %[3]q } -}`, rName) +} +`, rName, tagKey1, tagValue1) +} + +func testAccCodeSigningConfigConfig_tags2(rName, tagKey1, tagValue1, tagKey2, tagValue2 string) string { + return fmt.Sprintf(` +resource "aws_signer_signing_profile" "test" { + platform_id = "AWSLambda-SHA384-ECDSA" +} + +resource "aws_lambda_code_signing_config" "code_signing_config" { + allowed_publishers { + signing_profile_version_arns = [ + aws_signer_signing_profile.test.version_arn, + ] + } + + tags = { + %[2]q = %[3]q + %[4]q = %[5]q + } +} +`, rName, tagKey1, tagValue1, tagKey2, tagValue2) } func testAccCodeSigningConfigConfig_updatePublishers() string { diff --git a/internal/service/lambda/service_package_gen.go b/internal/service/lambda/service_package_gen.go index 0f8cb13881f..c70ed5f1f4c 100644 --- a/internal/service/lambda/service_package_gen.go +++ b/internal/service/lambda/service_package_gen.go @@ -82,6 +82,9 @@ func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePacka Factory: resourceCodeSigningConfig, TypeName: "aws_lambda_code_signing_config", Name: "Code Signing Config", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: names.AttrARN, + }, }, { Factory: resourceEventSourceMapping, diff --git a/internal/service/lambda/tags.go b/internal/service/lambda/tags.go deleted file mode 100644 index 9bbf5f7647b..00000000000 --- a/internal/service/lambda/tags.go +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -package lambda - -import ( - "context" - - tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" - "github.com/hashicorp/terraform-provider-aws/internal/types/option" -) - -// setTagsOut sets KeyValueTags in Context. -func setKeyValueTagsOut(ctx context.Context, tags tftags.KeyValueTags) { - if inContext, ok := tftags.FromContext(ctx); ok { - inContext.TagsOut = option.Some(tags) - } -} From 1d486ec3760e9ef122ca41e614e0526e10e4e604 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 1 Oct 2024 08:40:49 -0400 Subject: [PATCH 11/14] Remove 'aws_emr_cluster.custom_ami_id' change. --- internal/service/emr/cluster.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/internal/service/emr/cluster.go b/internal/service/emr/cluster.go index b41260c9093..7e352f88bd9 100644 --- a/internal/service/emr/cluster.go +++ b/internal/service/emr/cluster.go @@ -100,12 +100,6 @@ func resourceCluster() *schema.Resource { }, }, }, - "custom_ami_id": { - Type: schema.TypeString, - ForceNew: true, - Optional: true, - ValidateFunc: validCustomAMIID, - }, "ebs_config": { Type: schema.TypeSet, Optional: true, From 9e5f2d8363668e4b0f220b15a078c5364ab6135b Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 1 Oct 2024 08:54:58 -0400 Subject: [PATCH 12/14] aws_lambda_code_signing_config: Not supported in US GovCloud (https://docs.aws.amazon.com/govcloud-us/latest/UserGuide/govcloud-lambda.html#govcloud-lambda-diffs). --- .../code_signing_config_data_source_test.go | 18 ++++++++++--- .../lambda/code_signing_config_test.go | 25 +++++++++++++++---- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/internal/service/lambda/code_signing_config_data_source_test.go b/internal/service/lambda/code_signing_config_data_source_test.go index 57a4ebba1e9..d157f83e676 100644 --- a/internal/service/lambda/code_signing_config_data_source_test.go +++ b/internal/service/lambda/code_signing_config_data_source_test.go @@ -15,8 +15,12 @@ func TestAccLambdaCodeSigningConfigDataSource_basic(t *testing.T) { ctx := acctest.Context(t) dataSourceName := "data.aws_lambda_code_signing_config.test" resourceName := "aws_lambda_code_signing_config.test" + resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionNot(t, names.USGovCloudPartitionID) + }, ErrorCheck: acctest.ErrorCheck(t, names.LambdaServiceID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, Steps: []resource.TestStep{ @@ -35,8 +39,12 @@ func TestAccLambdaCodeSigningConfigDataSource_policyID(t *testing.T) { ctx := acctest.Context(t) dataSourceName := "data.aws_lambda_code_signing_config.test" resourceName := "aws_lambda_code_signing_config.test" + resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionNot(t, names.USGovCloudPartitionID) + }, ErrorCheck: acctest.ErrorCheck(t, names.LambdaServiceID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, Steps: []resource.TestStep{ @@ -57,8 +65,12 @@ func TestAccLambdaCodeSigningConfigDataSource_description(t *testing.T) { ctx := acctest.Context(t) dataSourceName := "data.aws_lambda_code_signing_config.test" resourceName := "aws_lambda_code_signing_config.test" + resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionNot(t, names.USGovCloudPartitionID) + }, ErrorCheck: acctest.ErrorCheck(t, names.LambdaServiceID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, Steps: []resource.TestStep{ diff --git a/internal/service/lambda/code_signing_config_test.go b/internal/service/lambda/code_signing_config_test.go index 69c0aaea92b..7d944b42278 100644 --- a/internal/service/lambda/code_signing_config_test.go +++ b/internal/service/lambda/code_signing_config_test.go @@ -27,7 +27,10 @@ func TestAccLambdaCodeSigningConfig_basic(t *testing.T) { var conf awstypes.CodeSigningConfig resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionNot(t, names.USGovCloudPartitionID) + }, ErrorCheck: acctest.ErrorCheck(t, names.LambdaServiceID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckCodeSigningConfigDestroy(ctx), @@ -58,7 +61,10 @@ func TestAccLambdaCodeSigningConfig_disappears(t *testing.T) { var conf awstypes.CodeSigningConfig resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionNot(t, names.USGovCloudPartitionID) + }, ErrorCheck: acctest.ErrorCheck(t, names.LambdaServiceID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckCodeSigningConfigDestroy(ctx), @@ -82,7 +88,10 @@ func TestAccLambdaCodeSigningConfig_tags(t *testing.T) { var conf awstypes.CodeSigningConfig resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionNot(t, names.USGovCloudPartitionID) + }, ErrorCheck: acctest.ErrorCheck(t, names.LambdaServiceID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckCodeSigningConfigDestroy(ctx), @@ -127,7 +136,10 @@ func TestAccLambdaCodeSigningConfig_updatePolicy(t *testing.T) { var conf awstypes.CodeSigningConfig resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionNot(t, names.USGovCloudPartitionID) + }, ErrorCheck: acctest.ErrorCheck(t, names.LambdaServiceID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckCodeSigningConfigDestroy(ctx), @@ -164,7 +176,10 @@ func TestAccLambdaCodeSigningConfig_updatePublishers(t *testing.T) { var conf awstypes.CodeSigningConfig resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionNot(t, names.USGovCloudPartitionID) + }, ErrorCheck: acctest.ErrorCheck(t, names.LambdaServiceID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckCodeSigningConfigDestroy(ctx), From 99b8b550e75d079d9e7f092bf62b56abdda62999 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 1 Oct 2024 09:02:26 -0400 Subject: [PATCH 13/14] r/aws_lambda_event_source_mapping: Tags not supported in US GovCloud. --- internal/service/lambda/event_source_mapping.go | 9 +++++++++ internal/service/lambda/event_source_mapping_test.go | 5 ++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/internal/service/lambda/event_source_mapping.go b/internal/service/lambda/event_source_mapping.go index e4472fd35fa..5946ad4bfbd 100644 --- a/internal/service/lambda/event_source_mapping.go +++ b/internal/service/lambda/event_source_mapping.go @@ -502,6 +502,15 @@ func resourceEventSourceMappingCreate(ctx context.Context, d *schema.ResourceDat return conn.CreateEventSourceMapping(ctx, input) }) + // Some partitions (e.g. US GovCloud) may not support tags. + if input.Tags != nil && errs.IsUnsupportedOperationInPartitionError(meta.(*conns.AWSClient).Partition, err) { + input.Tags = nil + + output, err = retryEventSourceMapping(ctx, func() (*lambda.CreateEventSourceMappingOutput, error) { + return conn.CreateEventSourceMapping(ctx, input) + }) + } + if err != nil { return sdkdiag.AppendErrorf(diags, "creating Lambda Event Source Mapping (%s): %s", target, err) } diff --git a/internal/service/lambda/event_source_mapping_test.go b/internal/service/lambda/event_source_mapping_test.go index 2652bc6870c..ae983f811a8 100644 --- a/internal/service/lambda/event_source_mapping_test.go +++ b/internal/service/lambda/event_source_mapping_test.go @@ -122,7 +122,10 @@ func TestAccLambdaEventSourceMapping_tags(t *testing.T) { rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionNot(t, names.USGovCloudPartitionID) + }, ErrorCheck: acctest.ErrorCheck(t, names.LambdaServiceID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckEventSourceMappingDestroy(ctx), From ac587b6bea21078f657ca7d401b1ca7fe974ecd6 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 1 Oct 2024 09:08:05 -0400 Subject: [PATCH 14/14] r/aws_lambda_event_source_mapping: arn not set in US GovCloud. --- internal/service/lambda/event_source_mapping_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/service/lambda/event_source_mapping_test.go b/internal/service/lambda/event_source_mapping_test.go index ae983f811a8..14ab92ff79e 100644 --- a/internal/service/lambda/event_source_mapping_test.go +++ b/internal/service/lambda/event_source_mapping_test.go @@ -47,7 +47,8 @@ func TestAccLambdaEventSourceMapping_Kinesis_basic(t *testing.T) { Config: testAccEventSourceMappingConfig_kinesisBatchSize(rName, "100"), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckEventSourceMappingExists(ctx, resourceName, &conf), - resource.TestCheckResourceAttrSet(resourceName, names.AttrARN), + // arn not set in US GovCloud. + // resource.TestCheckResourceAttrSet(resourceName, names.AttrARN), resource.TestCheckResourceAttr(resourceName, "batch_size", "100"), resource.TestCheckResourceAttr(resourceName, names.AttrEnabled, acctest.CtTrue), resource.TestCheckResourceAttrPair(resourceName, "event_source_arn", eventSourceResourceName, names.AttrARN),