From 35000d5bea494ef482166cd34bbbf255b147595c Mon Sep 17 00:00:00 2001 From: Farhan Angullia Date: Wed, 28 Jul 2021 04:18:37 +0800 Subject: [PATCH 1/5] add CustomizeDiff func for lex resources --- aws/resource_aws_lex_bot.go | 33 +++++++++++++++++++++++++++++++ aws/resource_aws_lex_intent.go | 30 ++++++++++++++++++++++++++++ aws/resource_aws_lex_slot_type.go | 23 +++++++++++++++++++++ 3 files changed, 86 insertions(+) diff --git a/aws/resource_aws_lex_bot.go b/aws/resource_aws_lex_bot.go index c9f63219559..828da35e1f0 100644 --- a/aws/resource_aws_lex_bot.go +++ b/aws/resource_aws_lex_bot.go @@ -1,6 +1,7 @@ package aws import ( + "context" "fmt" "log" "regexp" @@ -177,9 +178,41 @@ func resourceAwsLexBot() *schema.Resource { Computed: true, }, }, + CustomizeDiff: updateComputedAttributesOnBotCreateVersion, } } +func updateComputedAttributesOnBotCreateVersion(_ context.Context, d *schema.ResourceDiff, meta interface{}) error { + createVersion := d.Get("create_version").(bool) + if createVersion && hasBotConfigChanges(d) { + d.SetNewComputed("version") + } + return nil +} + +func hasBotConfigChanges(d resourceDiffer) bool { + for _, key := range []string{ + "description", + "child_directed", + "detect_sentiment", + "enable_model_improvements", + "idle_session_ttl_in_seconds", + "intent", + "locale", + "nlu_intent_confidence_threshold", + "abort_statement.0.response_card", + "abort_statement.0.message", + "clarification_prompt", + "process_behavior", + "voice_id", + } { + if d.HasChange(key) { + return true + } + } + return false +} + var validateLexBotName = validation.All( validation.StringLenBetween(2, 50), validation.StringMatch(regexp.MustCompile(`^([A-Za-z]_?)+$`), ""), diff --git a/aws/resource_aws_lex_intent.go b/aws/resource_aws_lex_intent.go index ae7cc5117a7..767d3c78756 100644 --- a/aws/resource_aws_lex_intent.go +++ b/aws/resource_aws_lex_intent.go @@ -1,6 +1,7 @@ package aws import ( + "context" "fmt" "log" "regexp" @@ -247,9 +248,38 @@ func resourceAwsLexIntent() *schema.Resource { Computed: true, }, }, + CustomizeDiff: updateComputedAttributesOnIntentCreateVersion, } } +func updateComputedAttributesOnIntentCreateVersion(_ context.Context, d *schema.ResourceDiff, meta interface{}) error { + createVersion := d.Get("create_version").(bool) + if createVersion && hasIntentConfigChanges(d) { + d.SetNewComputed("version") + } + return nil +} + +func hasIntentConfigChanges(d resourceDiffer) bool { + for _, key := range []string{ + "description", + "conclusion_statement", + "confirmation_prompt", + "dialog_code_hook", + "follow_up_prompt", + "fulfillment_activity", + "parent_intent_signature", + "rejection_statement", + "sample_utterances", + "slot", + } { + if d.HasChange(key) { + return true + } + } + return false +} + func resourceAwsLexIntentCreate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).lexmodelconn name := d.Get("name").(string) diff --git a/aws/resource_aws_lex_slot_type.go b/aws/resource_aws_lex_slot_type.go index 2a485363aa6..9ba27922065 100644 --- a/aws/resource_aws_lex_slot_type.go +++ b/aws/resource_aws_lex_slot_type.go @@ -1,6 +1,7 @@ package aws import ( + "context" "fmt" "regexp" "time" @@ -106,9 +107,31 @@ func resourceAwsLexSlotType() *schema.Resource { Computed: true, }, }, + CustomizeDiff: updateComputedAttributesOnSlotTypeCreateVersion, } } +func updateComputedAttributesOnSlotTypeCreateVersion(_ context.Context, d *schema.ResourceDiff, meta interface{}) error { + createVersion := d.Get("create_version").(bool) + if createVersion && hasSlotTypeConfigChanges(d) { + d.SetNewComputed("version") + } + return nil +} + +func hasSlotTypeConfigChanges(d resourceDiffer) bool { + for _, key := range []string{ + "description", + "enumeration_value", + "value_selection_strategy", + } { + if d.HasChange(key) { + return true + } + } + return false +} + func resourceAwsLexSlotTypeCreate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).lexmodelconn name := d.Get("name").(string) From c3d95ee24a46c412128657fcd68467e7872c4533 Mon Sep 17 00:00:00 2001 From: Farhan Angullia Date: Wed, 28 Jul 2021 04:19:18 +0800 Subject: [PATCH 2/5] added acc tests for version dependency use case --- aws/resource_aws_lex_bot_test.go | 74 ++++++++++++++++++++++ aws/resource_aws_lex_intent_test.go | 85 ++++++++++++++++++++++++++ aws/resource_aws_lex_slot_type_test.go | 77 +++++++++++++++++++++++ 3 files changed, 236 insertions(+) diff --git a/aws/resource_aws_lex_bot_test.go b/aws/resource_aws_lex_bot_test.go index b603dbb8fbc..ee36bbce538 100644 --- a/aws/resource_aws_lex_bot_test.go +++ b/aws/resource_aws_lex_bot_test.go @@ -556,6 +556,54 @@ func TestAccAwsLexBot_intents(t *testing.T) { }) } +func TestAccAwsLexBot_computeVersion(t *testing.T) { + var v1 lexmodelbuildingservice.GetBotOutput + var v2 lexmodelbuildingservice.GetBotAliasOutput + + botResourceName := "aws_lex_bot.test" + botAliasResourceName := "aws_lex_bot_alias.test" + + testBotID := "test_bot_" + acctest.RandStringFromCharSet(8, acctest.CharSetAlpha) + + version := "1" + updatedVersion := "2" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPartitionHasServicePreCheck(lexmodelbuildingservice.EndpointsID, t) }, + ErrorCheck: testAccErrorCheck(t, lexmodelbuildingservice.EndpointsID), + Providers: testAccProviders, + CheckDestroy: testAccCheckAwsLexBotDestroy, + Steps: []resource.TestStep{ + { + Config: composeConfig( + testAccAwsLexBotConfig_createVersion(testBotID), + testAccAwsLexBotConfig_intentMultiple(testBotID), + testAccAwsLexBotAliasConfig_basic(testBotID), + ), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckAwsLexBotExistsWithVersion(botResourceName, version, &v1), + resource.TestCheckResourceAttr(botResourceName, "version", version), + testAccCheckAwsLexBotAliasExists(botAliasResourceName, &v2), + resource.TestCheckResourceAttr(botAliasResourceName, "bot_version", version), + ), + }, + { + Config: composeConfig( + testAccAwsLexBotConfig_intentMultiple(testBotID), + testAccAwsLexBotConfig_multipleIntentsWithVersion(testBotID), + testAccAwsLexBotAliasConfig_basic(testBotID), + ), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckAwsLexBotExistsWithVersion(botResourceName, updatedVersion, &v1), + resource.TestCheckResourceAttr(botResourceName, "version", updatedVersion), + resource.TestCheckResourceAttr(botResourceName, "intent.#", "2"), + resource.TestCheckResourceAttr(botAliasResourceName, "bot_version", updatedVersion), + ), + }, + }, + }) +} + func TestAccAwsLexBot_locale(t *testing.T) { var v lexmodelbuildingservice.GetBotOutput rName := "aws_lex_bot.test" @@ -1111,3 +1159,29 @@ resource "aws_lex_bot" "test" { } `, rName) } + +func testAccAwsLexBotConfig_multipleIntentsWithVersion(rName string) string { + return fmt.Sprintf(` +resource "aws_lex_bot" "test" { + name = "%s" + description = "Bot to order flowers on the behalf of a user" + child_directed = false + create_version = true + process_behavior = "BUILD" + abort_statement { + message { + content = "Sorry, I'm not able to assist at this time" + content_type = "PlainText" + } + } + intent { + intent_name = aws_lex_intent.test.name + intent_version = aws_lex_intent.test.version + } + intent { + intent_name = aws_lex_intent.test_2.name + intent_version = aws_lex_intent.test_2.version + } +} +`, rName) +} diff --git a/aws/resource_aws_lex_intent_test.go b/aws/resource_aws_lex_intent_test.go index bc601880d30..18b8cf93a20 100644 --- a/aws/resource_aws_lex_intent_test.go +++ b/aws/resource_aws_lex_intent_test.go @@ -639,6 +639,53 @@ func TestAccAwsLexIntent_updateWithExternalChange(t *testing.T) { }) } +func TestAccAwsLexIntent_computeVersion(t *testing.T) { + var v1 lexmodelbuildingservice.GetIntentOutput + var v2 lexmodelbuildingservice.GetBotOutput + + intentResourceName := "aws_lex_intent.test" + botResourceName := "aws_lex_bot.test" + testIntentID := "test_intent_" + acctest.RandStringFromCharSet(8, acctest.CharSetAlpha) + + version := "1" + updatedVersion := "2" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPartitionHasServicePreCheck(lexmodelbuildingservice.EndpointsID, t) }, + ErrorCheck: testAccErrorCheck(t, lexmodelbuildingservice.EndpointsID), + Providers: testAccProviders, + CheckDestroy: testAccCheckAwsLexIntentDestroy, + Steps: []resource.TestStep{ + { + Config: composeConfig( + testAccAwsLexIntentConfig_createVersion(testIntentID), + testAccAwsLexBotConfig_createVersion(testIntentID), + ), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckAwsLexIntentExistsWithVersion(intentResourceName, version, &v1), + resource.TestCheckResourceAttr(intentResourceName, "version", version), + testAccCheckAwsLexBotExistsWithVersion(botResourceName, version, &v2), + resource.TestCheckResourceAttr(botResourceName, "version", version), + ), + }, + { + Config: composeConfig( + testAccAwsLexIntentConfig_sampleUtterancesWithVersion(testIntentID), + testAccAwsLexBotConfig_createVersion(testIntentID), + ), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckAwsLexIntentExistsWithVersion(intentResourceName, updatedVersion, &v1), + resource.TestCheckResourceAttr(intentResourceName, "version", updatedVersion), + resource.TestCheckResourceAttr(intentResourceName, "sample_utterances.#", "1"), + resource.TestCheckResourceAttr(intentResourceName, "sample_utterances.0", "I would like to pick up flowers"), + testAccCheckAwsLexBotExistsWithVersion(botResourceName, updatedVersion, &v2), + resource.TestCheckResourceAttr(botResourceName, "version", updatedVersion), + ), + }, + }, + }) +} + func testAccCheckAwsLexIntentExistsWithVersion(rName, intentVersion string, output *lexmodelbuildingservice.GetIntentOutput) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[rName] @@ -1102,3 +1149,41 @@ resource "aws_lex_intent" "test" { } `, rName) } + +func testAccAwsLexIntentConfig_sampleUtterancesWithVersion(rName string) string { + return fmt.Sprintf(` +resource "aws_lex_intent" "test" { + name = "%s" + create_version = true + fulfillment_activity { + type = "ReturnIntent" + } + sample_utterances = [ + "I would like to pick up flowers", + ] +} +`, rName) +} + +func testAccAwsLexIntentConfig_slotsWithVersion(rName string) string { + return fmt.Sprintf(` +resource "aws_lex_intent" "test" { + name = "%[1]s" + create_version = true + fulfillment_activity { + type = "ReturnIntent" + } + slot { + description = "Types of flowers to pick up" + name = "FlowerType" + priority = 1 + sample_utterances = [ + "I would like to order {FlowerType}", + ] + slot_constraint = "Required" + slot_type = aws_lex_slot_type.test.name + slot_type_version = aws_lex_slot_type.test.version + } +} +`, rName) +} diff --git a/aws/resource_aws_lex_slot_type_test.go b/aws/resource_aws_lex_slot_type_test.go index fa28ac89874..0309b662788 100644 --- a/aws/resource_aws_lex_slot_type_test.go +++ b/aws/resource_aws_lex_slot_type_test.go @@ -346,6 +346,57 @@ func TestAccAwsLexSlotType_disappears(t *testing.T) { }) } +func TestAccAwsLexSlotType_computeVersion(t *testing.T) { + var v1 lexmodelbuildingservice.GetSlotTypeOutput + var v2 lexmodelbuildingservice.GetIntentOutput + + slotTypeResourceName := "aws_lex_slot_type.test" + intentResourceName := "aws_lex_intent.test" + testSlotTypeID := "test_slot_type_" + acctest.RandStringFromCharSet(8, acctest.CharSetAlpha) + + version := "1" + updatedVersion := "2" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPartitionHasServicePreCheck(lexmodelbuildingservice.EndpointsID, t) }, + ErrorCheck: testAccErrorCheck(t, lexmodelbuildingservice.EndpointsID), + Providers: testAccProviders, + CheckDestroy: testAccCheckAwsLexSlotTypeDestroy, + Steps: []resource.TestStep{ + { + Config: composeConfig( + testAccAwsLexSlotTypeConfig_withVersion(testSlotTypeID), + testAccAwsLexIntentConfig_slotsWithVersion(testSlotTypeID), + ), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckAwsLexSlotTypeExistsWithVersion(slotTypeResourceName, version, &v1), + resource.TestCheckResourceAttr(slotTypeResourceName, "version", version), + testAccCheckAwsLexIntentExistsWithVersion(intentResourceName, version, &v2), + resource.TestCheckResourceAttr(intentResourceName, "version", version), + ), + }, + { + Config: composeConfig( + testAccAwsLexSlotTypeUpdateConfig_enumerationValuesWithVersion(testSlotTypeID), + testAccAwsLexIntentConfig_slotsWithVersion(testSlotTypeID), + ), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckAwsLexSlotTypeExistsWithVersion(slotTypeResourceName, updatedVersion, &v1), + resource.TestCheckResourceAttr(slotTypeResourceName, "version", updatedVersion), + resource.TestCheckResourceAttr(slotTypeResourceName, "enumeration_value.#", "2"), + resource.TestCheckTypeSetElemNestedAttrs(slotTypeResourceName, "enumeration_value.*", map[string]string{ + "value": "tulips", + }), + resource.TestCheckTypeSetElemAttr(slotTypeResourceName, "enumeration_value.*.synonyms.*", "Eduardoregelia"), + resource.TestCheckTypeSetElemAttr(slotTypeResourceName, "enumeration_value.*.synonyms.*", "Podonix"), + testAccCheckAwsLexIntentExistsWithVersion(intentResourceName, updatedVersion, &v2), + resource.TestCheckResourceAttr(intentResourceName, "version", updatedVersion), + ), + }, + }, + }) +} + func testAccCheckAwsLexSlotTypeExistsWithVersion(rName, slotTypeVersion string, output *lexmodelbuildingservice.GetSlotTypeOutput) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[rName] @@ -514,3 +565,29 @@ resource "aws_lex_slot_type" "test" { } `, rName) } + +func testAccAwsLexSlotTypeUpdateConfig_enumerationValuesWithVersion(rName string) string { + return fmt.Sprintf(` +resource "aws_lex_slot_type" "test" { + name = "%s" + enumeration_value { + synonyms = [ + "Lirium", + "Martagon", + ] + value = "lilies" + } + + enumeration_value { + synonyms = [ + "Eduardoregelia", + "Podonix", + ] + + value = "tulips" + } + + create_version = true +} +`, rName) +} From a7b098bba10998b1e0c9392956e38b5673e94ad3 Mon Sep 17 00:00:00 2001 From: Tyler Lynch Date: Wed, 28 Jul 2021 13:07:45 -0400 Subject: [PATCH 3/5] Updated Lex* AccTests with additional testchecks and then cleaned up formatting. --- aws/resource_aws_lex_bot_test.go | 107 ++++++++++++++++--------- aws/resource_aws_lex_intent_test.go | 12 +-- aws/resource_aws_lex_slot_type_test.go | 17 ++-- 3 files changed, 85 insertions(+), 51 deletions(-) diff --git a/aws/resource_aws_lex_bot_test.go b/aws/resource_aws_lex_bot_test.go index ee36bbce538..ca8cb2d6cc8 100644 --- a/aws/resource_aws_lex_bot_test.go +++ b/aws/resource_aws_lex_bot_test.go @@ -562,6 +562,8 @@ func TestAccAwsLexBot_computeVersion(t *testing.T) { botResourceName := "aws_lex_bot.test" botAliasResourceName := "aws_lex_bot_alias.test" + intentResourceName := "aws_lex_intent.test" + intentResourceName2 := "aws_lex_intent.test_2" testBotID := "test_bot_" + acctest.RandStringFromCharSet(8, acctest.CharSetAlpha) @@ -583,13 +585,16 @@ func TestAccAwsLexBot_computeVersion(t *testing.T) { Check: resource.ComposeAggregateTestCheckFunc( testAccCheckAwsLexBotExistsWithVersion(botResourceName, version, &v1), resource.TestCheckResourceAttr(botResourceName, "version", version), + resource.TestCheckResourceAttr(botResourceName, "intent.#", "1"), + resource.TestCheckResourceAttr(botResourceName, "intent.0.intent_version", version), testAccCheckAwsLexBotAliasExists(botAliasResourceName, &v2), resource.TestCheckResourceAttr(botAliasResourceName, "bot_version", version), + resource.TestCheckResourceAttr(intentResourceName, "version", version), ), }, { Config: composeConfig( - testAccAwsLexBotConfig_intentMultiple(testBotID), + testAccAwsLexBotConfig_intentMultipleSecondUpdated(testBotID), testAccAwsLexBotConfig_multipleIntentsWithVersion(testBotID), testAccAwsLexBotAliasConfig_basic(testBotID), ), @@ -597,7 +602,11 @@ func TestAccAwsLexBot_computeVersion(t *testing.T) { testAccCheckAwsLexBotExistsWithVersion(botResourceName, updatedVersion, &v1), resource.TestCheckResourceAttr(botResourceName, "version", updatedVersion), resource.TestCheckResourceAttr(botResourceName, "intent.#", "2"), + resource.TestCheckResourceAttr(botResourceName, "intent.0.intent_version", version), + resource.TestCheckResourceAttr(botResourceName, "intent.1.intent_version", updatedVersion), resource.TestCheckResourceAttr(botAliasResourceName, "bot_version", updatedVersion), + resource.TestCheckResourceAttr(intentResourceName, "version", version), + resource.TestCheckResourceAttr(intentResourceName2, "version", updatedVersion), ), }, }, @@ -801,8 +810,8 @@ func testAccCheckAwsLexBotDestroy(s *terraform.State) error { func testAccAwsLexBotConfig_intent(rName string) string { return fmt.Sprintf(` resource "aws_lex_intent" "test" { - name = "%s" create_version = true + name = "%s" fulfillment_activity { type = "ReturnIntent" } @@ -816,8 +825,8 @@ resource "aws_lex_intent" "test" { func testAccAwsLexBotConfig_intentMultiple(rName string) string { return fmt.Sprintf(` resource "aws_lex_intent" "test" { - name = "%[1]s" create_version = true + name = "%[1]s" fulfillment_activity { type = "ReturnIntent" } @@ -827,8 +836,23 @@ resource "aws_lex_intent" "test" { } resource "aws_lex_intent" "test_2" { + create_version = true name = "%[1]stwo" + fulfillment_activity { + type = "ReturnIntent" + } + sample_utterances = [ + "I would like to pick up flowers", + ] +} +`, rName) +} + +func testAccAwsLexBotConfig_intentMultipleSecondUpdated(rName string) string { + return fmt.Sprintf(` +resource "aws_lex_intent" "test" { create_version = true + name = "%[1]s" fulfillment_activity { type = "ReturnIntent" } @@ -836,15 +860,26 @@ resource "aws_lex_intent" "test_2" { "I would like to pick up flowers", ] } + +resource "aws_lex_intent" "test_2" { + create_version = true + name = "%[1]stwo" + fulfillment_activity { + type = "ReturnIntent" + } + sample_utterances = [ + "I would like to return these flowers", + ] +} `, rName) } func testAccAwsLexBotConfig_basic(rName string) string { return fmt.Sprintf(` resource "aws_lex_bot" "test" { - name = "%s" - description = "Bot to order flowers on the behalf of a user" child_directed = false + description = "Bot to order flowers on the behalf of a user" + name = "%s" abort_statement { message { content = "Sorry, I'm not able to assist at this time" @@ -862,10 +897,10 @@ resource "aws_lex_bot" "test" { func testAccAwsLexBotConfig_createVersion(rName string) string { return fmt.Sprintf(` resource "aws_lex_bot" "test" { - name = "%s" - description = "Bot to order flowers on the behalf of a user" child_directed = false create_version = true + description = "Bot to order flowers on the behalf of a user" + name = "%s" process_behavior = "BUILD" abort_statement { message { @@ -884,9 +919,9 @@ resource "aws_lex_bot" "test" { func testAccAwsLexBotConfig_abortStatement(rName string) string { return fmt.Sprintf(` resource "aws_lex_bot" "test" { - name = "%s" - description = "Bot to order flowers on the behalf of a user" child_directed = false + description = "Bot to order flowers on the behalf of a user" + name = "%s" abort_statement { message { content = "Sorry, I'm not able to assist at this time" @@ -904,9 +939,9 @@ resource "aws_lex_bot" "test" { func testAccAwsLexBotConfig_abortStatementUpdate(rName string) string { return fmt.Sprintf(` resource "aws_lex_bot" "test" { - name = "%s" - description = "Bot to order flowers on the behalf of a user" child_directed = false + description = "Bot to order flowers on the behalf of a user" + name = "%s" abort_statement { message { content = "Sorry, I'm not able to assist at this time" @@ -931,9 +966,9 @@ resource "aws_lex_bot" "test" { func testAccAwsLexBotConfig_clarificationPrompt(rName string) string { return fmt.Sprintf(` resource "aws_lex_bot" "test" { - name = "%s" - description = "Bot to order flowers on the behalf of a user" child_directed = false + description = "Bot to order flowers on the behalf of a user" + name = "%s" abort_statement { message { content = "Sorry, I'm not able to assist at this time" @@ -958,9 +993,9 @@ resource "aws_lex_bot" "test" { func testAccAwsLexBotConfig_clarificationPromptUpdate(rName string) string { return fmt.Sprintf(` resource "aws_lex_bot" "test" { - name = "%s" - description = "Bot to order flowers on the behalf of a user" child_directed = false + description = "Bot to order flowers on the behalf of a user" + name = "%s" abort_statement { message { content = "Sorry, I'm not able to assist at this time" @@ -992,9 +1027,9 @@ resource "aws_lex_bot" "test" { func testAccAwsLexBotConfig_childDirectedUpdate(rName string) string { return fmt.Sprintf(` resource "aws_lex_bot" "test" { - name = "%s" - description = "Bot to order flowers on the behalf of a user" child_directed = true + description = "Bot to order flowers on the behalf of a user" + name = "%s" abort_statement { message { content = "Sorry, I'm not able to assist at this time" @@ -1012,9 +1047,9 @@ resource "aws_lex_bot" "test" { func testAccAwsLexBotConfig_descriptionUpdate(rName string) string { return fmt.Sprintf(` resource "aws_lex_bot" "test" { - name = "%s" - description = "Bot to order flowers" child_directed = false + description = "Bot to order flowers" + name = "%s" abort_statement { message { content = "Sorry, I'm not able to assist at this time" @@ -1032,10 +1067,10 @@ resource "aws_lex_bot" "test" { func testAccAwsLexBotConfig_detectSentimentUpdate(rName string) string { return fmt.Sprintf(` resource "aws_lex_bot" "test" { - name = "%s" - description = "Bot to order flowers on the behalf of a user" child_directed = false - detect_sentiment = true + description = "Bot to order flowers on the behalf of a user" + detect_sentiment = true + name = "%s" abort_statement { message { content = "Sorry, I'm not able to assist at this time" @@ -1053,10 +1088,10 @@ resource "aws_lex_bot" "test" { func testAccAwsLexBotConfig_enableModelImprovementsUpdate(rName string) string { return fmt.Sprintf(` resource "aws_lex_bot" "test" { - name = "%s" - description = "Bot to order flowers on the behalf of a user" child_directed = false - enable_model_improvements = true + description = "Bot to order flowers on the behalf of a user" + enable_model_improvements = true + name = "%s" nlu_intent_confidence_threshold = 0.5 abort_statement { message { @@ -1075,10 +1110,10 @@ resource "aws_lex_bot" "test" { func testAccAwsLexBotConfig_idleSessionTtlInSecondsUpdate(rName string) string { return fmt.Sprintf(` resource "aws_lex_bot" "test" { - name = "%s" - description = "Bot to order flowers on the behalf of a user" child_directed = false - idle_session_ttl_in_seconds = 600 + description = "Bot to order flowers on the behalf of a user" + idle_session_ttl_in_seconds = 600 + name = "%s" abort_statement { message { content = "Sorry, I'm not able to assist at this time" @@ -1096,9 +1131,9 @@ resource "aws_lex_bot" "test" { func testAccAwsLexBotConfig_intentsUpdate(rName string) string { return fmt.Sprintf(` resource "aws_lex_bot" "test" { - name = "%s" - description = "Bot to order flowers on the behalf of a user" child_directed = false + description = "Bot to order flowers on the behalf of a user" + name = "%s" abort_statement { message { content = "Sorry, I'm not able to assist at this time" @@ -1120,11 +1155,11 @@ resource "aws_lex_bot" "test" { func testAccAwsLexBotConfig_localeUpdate(rName string) string { return fmt.Sprintf(` resource "aws_lex_bot" "test" { - name = "%s" - description = "Bot to order flowers on the behalf of a user" child_directed = false + description = "Bot to order flowers on the behalf of a user" enable_model_improvements = true locale = "en-GB" + name = "%s" abort_statement { message { content = "Sorry, I'm not able to assist at this time" @@ -1142,9 +1177,9 @@ resource "aws_lex_bot" "test" { func testAccAwsLexBotConfig_voiceIdUpdate(rName string) string { return fmt.Sprintf(` resource "aws_lex_bot" "test" { - name = "%s" - description = "Bot to order flowers on the behalf of a user" child_directed = false + description = "Bot to order flowers on the behalf of a user" + name = "%s" voice_id = "Justin" abort_statement { message { @@ -1163,10 +1198,10 @@ resource "aws_lex_bot" "test" { func testAccAwsLexBotConfig_multipleIntentsWithVersion(rName string) string { return fmt.Sprintf(` resource "aws_lex_bot" "test" { - name = "%s" - description = "Bot to order flowers on the behalf of a user" child_directed = false create_version = true + description = "Bot to order flowers on the behalf of a user" + name = "%s" process_behavior = "BUILD" abort_statement { message { diff --git a/aws/resource_aws_lex_intent_test.go b/aws/resource_aws_lex_intent_test.go index 18b8cf93a20..dff289e8dae 100644 --- a/aws/resource_aws_lex_intent_test.go +++ b/aws/resource_aws_lex_intent_test.go @@ -666,6 +666,7 @@ func TestAccAwsLexIntent_computeVersion(t *testing.T) { resource.TestCheckResourceAttr(intentResourceName, "version", version), testAccCheckAwsLexBotExistsWithVersion(botResourceName, version, &v2), resource.TestCheckResourceAttr(botResourceName, "version", version), + resource.TestCheckResourceAttr(botResourceName, "intent.0.intent_version", version), ), }, { @@ -680,6 +681,7 @@ func TestAccAwsLexIntent_computeVersion(t *testing.T) { resource.TestCheckResourceAttr(intentResourceName, "sample_utterances.0", "I would like to pick up flowers"), testAccCheckAwsLexBotExistsWithVersion(botResourceName, updatedVersion, &v2), resource.TestCheckResourceAttr(botResourceName, "version", updatedVersion), + resource.TestCheckResourceAttr(botResourceName, "intent.0.intent_version", updatedVersion), ), }, }, @@ -779,8 +781,8 @@ data "aws_iam_policy_document" "lambda_assume_role" { } resource "aws_iam_role" "test" { - name = "%[1]s" assume_role_policy = data.aws_iam_policy_document.lambda_assume_role.json + name = "%[1]s" } resource "aws_lambda_permission" "lex" { @@ -813,8 +815,8 @@ resource "aws_lex_intent" "test" { func testAccAwsLexIntentConfig_createVersion(rName string) string { return fmt.Sprintf(` resource "aws_lex_intent" "test" { - name = "%s" create_version = true + name = "%s" fulfillment_activity { type = "ReturnIntent" } @@ -1123,7 +1125,7 @@ resource "aws_lex_intent" "test" { func testAccAwsLexIntentConfig_slotsCustom(rName string) string { return fmt.Sprintf(` resource "aws_lex_intent" "test" { - name = "%[1]s" + name = "%s" fulfillment_activity { type = "ReturnIntent" } @@ -1153,8 +1155,8 @@ resource "aws_lex_intent" "test" { func testAccAwsLexIntentConfig_sampleUtterancesWithVersion(rName string) string { return fmt.Sprintf(` resource "aws_lex_intent" "test" { - name = "%s" create_version = true + name = "%s" fulfillment_activity { type = "ReturnIntent" } @@ -1168,8 +1170,8 @@ resource "aws_lex_intent" "test" { func testAccAwsLexIntentConfig_slotsWithVersion(rName string) string { return fmt.Sprintf(` resource "aws_lex_intent" "test" { - name = "%[1]s" create_version = true + name = "%s" fulfillment_activity { type = "ReturnIntent" } diff --git a/aws/resource_aws_lex_slot_type_test.go b/aws/resource_aws_lex_slot_type_test.go index 0309b662788..bbea2ac5a88 100644 --- a/aws/resource_aws_lex_slot_type_test.go +++ b/aws/resource_aws_lex_slot_type_test.go @@ -373,6 +373,7 @@ func TestAccAwsLexSlotType_computeVersion(t *testing.T) { resource.TestCheckResourceAttr(slotTypeResourceName, "version", version), testAccCheckAwsLexIntentExistsWithVersion(intentResourceName, version, &v2), resource.TestCheckResourceAttr(intentResourceName, "version", version), + resource.TestCheckResourceAttr(intentResourceName, "slot.0.slot_type_version", version), ), }, { @@ -391,6 +392,7 @@ func TestAccAwsLexSlotType_computeVersion(t *testing.T) { resource.TestCheckTypeSetElemAttr(slotTypeResourceName, "enumeration_value.*.synonyms.*", "Podonix"), testAccCheckAwsLexIntentExistsWithVersion(intentResourceName, updatedVersion, &v2), resource.TestCheckResourceAttr(intentResourceName, "version", updatedVersion), + resource.TestCheckResourceAttr(intentResourceName, "slot.0.slot_type_version", updatedVersion), ), }, }, @@ -495,7 +497,8 @@ resource "aws_lex_slot_type" "test" { func testAccAwsLexSlotTypeConfig_withVersion(rName string) string { return fmt.Sprintf(` resource "aws_lex_slot_type" "test" { - name = "%s" + create_version = true + name = "%s" enumeration_value { synonyms = [ "Lirium", @@ -503,7 +506,6 @@ resource "aws_lex_slot_type" "test" { ] value = "lilies" } - create_version = true } `, rName) } @@ -527,12 +529,12 @@ resource "aws_lex_slot_type" "test" { func testAccAwsLexSlotTypeConfig_enumerationValues(rName string) string { return fmt.Sprintf(` resource "aws_lex_slot_type" "test" { + name = "%s" enumeration_value { synonyms = [ "Lirium", "Martagon", ] - value = "lilies" } @@ -541,11 +543,8 @@ resource "aws_lex_slot_type" "test" { "Eduardoregelia", "Podonix", ] - value = "tulips" } - - name = "%s" } `, rName) } @@ -569,7 +568,8 @@ resource "aws_lex_slot_type" "test" { func testAccAwsLexSlotTypeUpdateConfig_enumerationValuesWithVersion(rName string) string { return fmt.Sprintf(` resource "aws_lex_slot_type" "test" { - name = "%s" + create_version = true + name = "%s" enumeration_value { synonyms = [ "Lirium", @@ -583,11 +583,8 @@ resource "aws_lex_slot_type" "test" { "Eduardoregelia", "Podonix", ] - value = "tulips" } - - create_version = true } `, rName) } From da4bb42f18796a3e0dd0741d2b91be14e041764b Mon Sep 17 00:00:00 2001 From: Tyler Lynch Date: Wed, 28 Jul 2021 13:59:41 -0400 Subject: [PATCH 4/5] Fixed formatting errors --- aws/resource_aws_lex_bot_test.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/aws/resource_aws_lex_bot_test.go b/aws/resource_aws_lex_bot_test.go index ca8cb2d6cc8..02f01771914 100644 --- a/aws/resource_aws_lex_bot_test.go +++ b/aws/resource_aws_lex_bot_test.go @@ -879,7 +879,7 @@ func testAccAwsLexBotConfig_basic(rName string) string { resource "aws_lex_bot" "test" { child_directed = false description = "Bot to order flowers on the behalf of a user" - name = "%s" + name = "%s" abort_statement { message { content = "Sorry, I'm not able to assist at this time" @@ -920,7 +920,7 @@ func testAccAwsLexBotConfig_abortStatement(rName string) string { return fmt.Sprintf(` resource "aws_lex_bot" "test" { child_directed = false - description = "Bot to order flowers on the behalf of a user" + description = "Bot to order flowers on the behalf of a user" name = "%s" abort_statement { message { @@ -1049,7 +1049,7 @@ func testAccAwsLexBotConfig_descriptionUpdate(rName string) string { resource "aws_lex_bot" "test" { child_directed = false description = "Bot to order flowers" - name = "%s" + name = "%s" abort_statement { message { content = "Sorry, I'm not able to assist at this time" @@ -1069,7 +1069,7 @@ func testAccAwsLexBotConfig_detectSentimentUpdate(rName string) string { resource "aws_lex_bot" "test" { child_directed = false description = "Bot to order flowers on the behalf of a user" - detect_sentiment = true + detect_sentiment = true name = "%s" abort_statement { message { @@ -1089,8 +1089,8 @@ func testAccAwsLexBotConfig_enableModelImprovementsUpdate(rName string) string { return fmt.Sprintf(` resource "aws_lex_bot" "test" { child_directed = false - description = "Bot to order flowers on the behalf of a user" - enable_model_improvements = true + description = "Bot to order flowers on the behalf of a user" + enable_model_improvements = true name = "%s" nlu_intent_confidence_threshold = 0.5 abort_statement { @@ -1111,8 +1111,8 @@ func testAccAwsLexBotConfig_idleSessionTtlInSecondsUpdate(rName string) string { return fmt.Sprintf(` resource "aws_lex_bot" "test" { child_directed = false - description = "Bot to order flowers on the behalf of a user" - idle_session_ttl_in_seconds = 600 + description = "Bot to order flowers on the behalf of a user" + idle_session_ttl_in_seconds = 600 name = "%s" abort_statement { message { @@ -1156,7 +1156,7 @@ func testAccAwsLexBotConfig_localeUpdate(rName string) string { return fmt.Sprintf(` resource "aws_lex_bot" "test" { child_directed = false - description = "Bot to order flowers on the behalf of a user" + description = "Bot to order flowers on the behalf of a user" enable_model_improvements = true locale = "en-GB" name = "%s" From 25781d03d43c06af4b3ae0e0c48410b5bd5d5793 Mon Sep 17 00:00:00 2001 From: Angie Pinilla Date: Wed, 28 Jul 2021 20:44:08 -0400 Subject: [PATCH 5/5] Add CHANGELOG for #20336 --- .changelog/20336.txt | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .changelog/20336.txt diff --git a/.changelog/20336.txt b/.changelog/20336.txt new file mode 100644 index 00000000000..f6695d5f38c --- /dev/null +++ b/.changelog/20336.txt @@ -0,0 +1,11 @@ +```release-note:bug +aws/resource_aws_lex_bot: Fix computed `version` for dependent resources +``` + +```release-note:bug +aws/resource_aws_lex_intent: Fix computed `version` for dependent resources +``` + +```release-note:bug +aws/resource_aws_lex_slot_type: Fix computed `version` for dependent resources +``` \ No newline at end of file