From 6d669b5356b74c638cca9b8456f1d11ad4c8da6f Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Wed, 22 Nov 2023 11:46:31 -0500 Subject: [PATCH 1/2] r/aws_lexv2models_bot: support explicit type argument on create and update Previously, explicitly configured values for the type argument were not sent during create or update operations, resulting in the default `Bot` type in all cases. These operations will now send the type value when set. --- internal/service/lexv2models/bot.go | 12 ++++- internal/service/lexv2models/bot_test.go | 69 +++++++++++++++++++++--- 2 files changed, 71 insertions(+), 10 deletions(-) diff --git a/internal/service/lexv2models/bot.go b/internal/service/lexv2models/bot.go index cd5533f3a932..fc553b56bc39 100644 --- a/internal/service/lexv2models/bot.go +++ b/internal/service/lexv2models/bot.go @@ -77,12 +77,12 @@ func (r *resourceBot) Schema(ctx context.Context, req resource.SchemaRequest, re stringplanmodifier.RequiresReplace(), }, }, - names.AttrTags: tftags.TagsAttribute(), - names.AttrTagsAll: tftags.TagsAttributeComputedOnly(), "role_arn": schema.StringAttribute{ CustomType: fwtypes.ARNType, Required: true, }, + names.AttrTags: tftags.TagsAttribute(), + names.AttrTagsAll: tftags.TagsAttributeComputedOnly(), "test_bot_alias_tags": schema.MapAttribute{ ElementType: types.StringType, Optional: true, @@ -180,6 +180,10 @@ func (r *resourceBot) Create(ctx context.Context, req resource.CreateRequest, re in.BotMembers = bmInput } + if !plan.Type.IsNull() { + in.BotType = awstypes.BotType(plan.Type.ValueString()) + } + out, err := conn.CreateBot(ctx, &in) if err != nil { resp.Diagnostics.AddError( @@ -316,6 +320,10 @@ func (r *resourceBot) Update(ctx context.Context, req resource.UpdateRequest, re } } + if !plan.Type.IsNull() { + in.BotType = awstypes.BotType(plan.Type.ValueString()) + } + _, err := conn.UpdateBot(ctx, &in) if err != nil { resp.Diagnostics.AddError( diff --git a/internal/service/lexv2models/bot_test.go b/internal/service/lexv2models/bot_test.go index 1e6d826b836b..e08eef4c1753 100644 --- a/internal/service/lexv2models/bot_test.go +++ b/internal/service/lexv2models/bot_test.go @@ -10,6 +10,7 @@ import ( "testing" "github.com/aws/aws-sdk-go-v2/service/lexmodelsv2" + "github.com/aws/aws-sdk-go-v2/service/lexmodelsv2/types" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -27,6 +28,7 @@ func TestAccLexV2ModelsBot_basic(t *testing.T) { var bot lexmodelsv2.DescribeBotOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_lexv2models_bot.test" + iamRoleResourceName := "aws_iam_role.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { @@ -44,7 +46,7 @@ func TestAccLexV2ModelsBot_basic(t *testing.T) { testAccCheckBotExists(ctx, resourceName, &bot), resource.TestCheckResourceAttr(resourceName, "name", rName), resource.TestCheckResourceAttr(resourceName, "idle_session_ttl_in_seconds", "60"), - resource.TestCheckResourceAttrSet(resourceName, "role_arn"), + resource.TestCheckResourceAttrPair(resourceName, "role_arn", iamRoleResourceName, "arn"), resource.TestCheckResourceAttrSet(resourceName, "data_privacy.0.child_directed"), ), }, @@ -140,6 +142,40 @@ func TestAccLexV2ModelsBot_disappears(t *testing.T) { }) } +func TestAccLexV2ModelsBot_type(t *testing.T) { + ctx := acctest.Context(t) + + var bot lexmodelsv2.DescribeBotOutput + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_lexv2models_bot.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, names.LexV2ModelsEndpointID) + testAccPreCheck(ctx, t) + }, + ErrorCheck: acctest.ErrorCheck(t, names.LexV2ModelsEndpointID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckBotDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccBotConfig_type(rName, 60, true, string(types.BotTypeBot)), + Check: resource.ComposeTestCheckFunc( + testAccCheckBotExists(ctx, resourceName, &bot), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "type", string(types.BotTypeBot)), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func testAccCheckBotDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { conn := acctest.Provider.Meta().(*conns.AWSClient).LexV2ModelsClient(ctx) @@ -206,7 +242,7 @@ func testAccBotBaseConfig(rName string) string { return fmt.Sprintf(` data "aws_partition" "current" {} -resource "aws_iam_role" "test_role" { +resource "aws_iam_role" "test" { name = %[1]q assume_role_policy = jsonencode({ Version = "2012-10-17" @@ -223,8 +259,8 @@ resource "aws_iam_role" "test_role" { }) } -resource "aws_iam_role_policy_attachment" "test-attach" { - role = aws_iam_role.test_role.name +resource "aws_iam_role_policy_attachment" "test" { + role = aws_iam_role.test.name policy_arn = "arn:${data.aws_partition.current.partition}:iam::aws:policy/AmazonLexFullAccess" } `, rName) @@ -237,10 +273,10 @@ func testAccBotConfig_basic(rName string, ttl int, dp bool) string { resource "aws_lexv2models_bot" "test" { name = %[1]q idle_session_ttl_in_seconds = %[2]d - role_arn = aws_iam_role.test_role.arn + role_arn = aws_iam_role.test.arn data_privacy { - child_directed = "%[3]t" + child_directed = %[3]t } } `, rName, ttl, dp)) @@ -253,7 +289,7 @@ func testAccBotConfig_tags1(rName string, ttl int, dp bool, tagKey1, tagValue1 s resource "aws_lexv2models_bot" "test" { name = %[1]q idle_session_ttl_in_seconds = %[2]d - role_arn = aws_iam_role.test_role.arn + role_arn = aws_iam_role.test.arn data_privacy { child_directed = %[3]t @@ -273,7 +309,7 @@ func testAccBotConfig_tags2(rName string, ttl int, dp bool, tagKey1, tagValue1, resource "aws_lexv2models_bot" "test" { name = %[1]q idle_session_ttl_in_seconds = %[2]d - role_arn = aws_iam_role.test_role.arn + role_arn = aws_iam_role.test.arn data_privacy { child_directed = %[3]t @@ -286,3 +322,20 @@ resource "aws_lexv2models_bot" "test" { } `, rName, ttl, dp, tagKey1, tagValue1, tagKey2, tagValue2)) } + +func testAccBotConfig_type(rName string, ttl int, dp bool, botType string) string { + return acctest.ConfigCompose( + testAccBotBaseConfig(rName), + fmt.Sprintf(` +resource "aws_lexv2models_bot" "test" { + name = %[1]q + idle_session_ttl_in_seconds = %[2]d + role_arn = aws_iam_role.test.arn + type = %[4]q + + data_privacy { + child_directed = %[3]t + } +} +`, rName, ttl, dp, botType)) +} From 359946c4b8204b8821f5fed799c06e13ba7e26c7 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Wed, 22 Nov 2023 14:00:03 -0500 Subject: [PATCH 2/2] chore: changelog --- .changelog/34524.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/34524.txt diff --git a/.changelog/34524.txt b/.changelog/34524.txt new file mode 100644 index 000000000000..fab55bfd42bf --- /dev/null +++ b/.changelog/34524.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_lexv2models_bot: Properly send `type` argument on create and update when configured +```