From 83599ba1e6420543c43badf44a04f0f6bad0ebeb Mon Sep 17 00:00:00 2001 From: Angie Pinilla Date: Wed, 22 Jun 2022 02:40:56 -0400 Subject: [PATCH] tests/kendra_experience: with faq ids --- internal/service/kendra/experience_test.go | 154 ++++++++++++++++++ internal/service/kendra/kendra_test.go | 18 +- .../docs/r/kendra_experience.html.markdown | 1 + 3 files changed, 165 insertions(+), 8 deletions(-) diff --git a/internal/service/kendra/experience_test.go b/internal/service/kendra/experience_test.go index 5a9e4e437ca..f649dc2e9fe 100644 --- a/internal/service/kendra/experience_test.go +++ b/internal/service/kendra/experience_test.go @@ -291,6 +291,92 @@ func testAccExperience_Configuration_ContentSourceConfiguration_DirectPutContent }) } +func testAccExperience_Configuration_ContentSourceConfiguration_FaqIDs(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_kendra_experience.test" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(t) + acctest.PreCheckOrganizationManagementAccount(t) + testAccPreCheck(t) + }, + ErrorCheck: acctest.ErrorCheck(t, names.KendraEndpointID), + ProviderFactories: acctest.ProviderFactories, + CheckDestroy: testAccCheckExperienceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccExperienceConfig_configuration_contentSourceConfiguration_faqIDs(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckExperienceExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "configuration.#", "1"), + resource.TestCheckResourceAttr(resourceName, "configuration.0.content_source_configuration.#", "1"), + resource.TestCheckResourceAttr(resourceName, "configuration.0.content_source_configuration.0.direct_put_content", "false"), + resource.TestCheckResourceAttr(resourceName, "configuration.0.content_source_configuration.0.faq_ids.#", "1"), + resource.TestCheckTypeSetElemAttrPair(resourceName, "configuration.0.content_source_configuration.0.faq_ids.*", "aws_kendra_faq.test", "faq_id"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccExperience_Configuration_ContentSourceConfiguration_updateFaqIDs(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_kendra_experience.test" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(t) + acctest.PreCheckOrganizationManagementAccount(t) + testAccPreCheck(t) + }, + ErrorCheck: acctest.ErrorCheck(t, names.KendraEndpointID), + ProviderFactories: acctest.ProviderFactories, + CheckDestroy: testAccCheckExperienceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccExperienceConfig_configuration_contentSourceConfiguration_faqIDs(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckExperienceExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "configuration.#", "1"), + resource.TestCheckResourceAttr(resourceName, "configuration.0.content_source_configuration.#", "1"), + resource.TestCheckResourceAttr(resourceName, "configuration.0.content_source_configuration.0.direct_put_content", "false"), + resource.TestCheckResourceAttr(resourceName, "configuration.0.content_source_configuration.0.faq_ids.#", "1"), + resource.TestCheckTypeSetElemAttrPair(resourceName, "configuration.0.content_source_configuration.0.faq_ids.*", "aws_kendra_faq.test", "faq_id"), + ), + }, + { + Config: testAccExperienceConfig_configuration_contentSourceConfiguration_empty(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckExperienceExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "configuration.#", "1"), + resource.TestCheckResourceAttr(resourceName, "configuration.0.content_source_configuration.#", "1"), + resource.TestCheckResourceAttr(resourceName, "configuration.0.content_source_configuration.0.direct_put_content", "false"), + resource.TestCheckResourceAttr(resourceName, "configuration.0.content_source_configuration.0.faq_ids.#", "0"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func testAccExperience_Configuration_UserIdentityConfiguration(t *testing.T) { if testing.Short() { t.Skip("skipping long-running test in short mode") @@ -756,6 +842,74 @@ resource "aws_kendra_experience" "test" { `, rName, directPutContent)) } +func testAccExperienceConfig_configuration_contentSourceConfiguration_faqIDs(rName string) string { + return acctest.ConfigCompose( + testAccExperienceBaseConfig(rName), + fmt.Sprintf(` +resource "aws_s3_bucket" "test" { + bucket = %[1]q + force_destroy = true +} + +resource "aws_s3_object" "test" { + bucket = aws_s3_bucket.test.bucket + source = "test-fixtures/basic.csv" + key = "test/basic.csv" +} + +data "aws_iam_policy_document" "faq" { + statement { + sid = "AllowKendraToAccessS3" + effect = "Allow" + actions = [ + "s3:GetObject" + ] + resources = [ + "${aws_s3_bucket.test.arn}/*" + ] + } +} + +resource "aws_iam_policy" "faq" { + name = "%[1]s-faq" + description = "Allow Kendra to access S3" + policy = data.aws_iam_policy_document.faq.json +} + +resource "aws_iam_role_policy_attachment" "faq" { + role = aws_iam_role.test.name + policy_arn = aws_iam_policy.faq.arn +} + +resource "aws_kendra_faq" "test" { + depends_on = [aws_iam_role_policy_attachment.faq] + + index_id = aws_kendra_index.test.id + name = %[1]q + role_arn = aws_iam_role.test.arn + + s3_path { + bucket = aws_s3_bucket.test.id + key = aws_s3_object.test.key + } +} + +resource "aws_kendra_experience" "test" { + depends_on = [aws_iam_role_policy_attachment.experience] + + index_id = aws_kendra_index.test.id + name = %[1]q + role_arn = aws_iam_role.test.arn + + configuration { + content_source_configuration { + faq_ids = [aws_kendra_faq.test.faq_id] + } + } +} +`, rName)) +} + func testAccExperienceConfig_configuration_userIdentityConfiguration(rName, userId string) string { return acctest.ConfigCompose( testAccExperienceBaseConfig(rName), diff --git a/internal/service/kendra/kendra_test.go b/internal/service/kendra/kendra_test.go index 7e50cd83444..04d8988f670 100644 --- a/internal/service/kendra/kendra_test.go +++ b/internal/service/kendra/kendra_test.go @@ -12,11 +12,21 @@ func TestAccKendra_serial(t *testing.T) { "Name": testAccExperience_Name, "RoleARN": testAccExperience_roleARN, "Configuration_ContentSourceConfiguration_DirectPutContent": testAccExperience_Configuration_ContentSourceConfiguration_DirectPutContent, + "Configuration_ContentSourceConfiguration_FaqIDs": testAccExperience_Configuration_ContentSourceConfiguration_FaqIDs, + "Configuration_ContentSourceConfiguration_updateFaqIDs": testAccExperience_Configuration_ContentSourceConfiguration_updateFaqIDs, "Configuration_UserIdentityConfiguration": testAccExperience_Configuration_UserIdentityConfiguration, "Configuration_ContentSourceConfigurationAndUserIdentityConfiguration": testAccExperience_Configuration_ContentSourceConfigurationAndUserIdentityConfiguration, "Configuration_ContentSourceConfigurationWithUserIdentityConfigurationRemoved": testAccExperience_Configuration_ContentSourceConfigurationWithUserIdentityConfigurationRemoved, "Configuration_UserIdentityConfigurationWithContentSourceConfigurationRemoved": testAccExperience_Configuration_UserIdentityConfigurationWithContentSourceConfigurationRemoved, }, + "Faq": { + "basic": testAccFaq_basic, + "disappears": testAccFaq_disappears, + "tags": testAccFaq_tags, + "Description": testAccFaq_description, + "FileFormat": testAccFaq_fileFormat, + "LanguageCode": testAccFaq_languageCode, + }, "Index": { "basic": testAccIndex_basic, "disappears": testAccIndex_disappears, @@ -46,14 +56,6 @@ func TestAccKendra_serial(t *testing.T) { "RoleARN": testAccThesaurus_roleARN, "SourceS3Path": testAccThesaurus_sourceS3Path, }, - "Faq": { - "basic": testAccFaq_basic, - "disappears": testAccFaq_disappears, - "tags": testAccFaq_tags, - "Description": testAccFaq_description, - "FileFormat": testAccFaq_fileFormat, - "LanguageCode": testAccFaq_languageCode, - }, } for group, m := range testCases { diff --git a/website/docs/r/kendra_experience.html.markdown b/website/docs/r/kendra_experience.html.markdown index 0e6efcfaedb..4d952ed2e07 100644 --- a/website/docs/r/kendra_experience.html.markdown +++ b/website/docs/r/kendra_experience.html.markdown @@ -24,6 +24,7 @@ resource "aws_kendra_experience" "example" { configuration { content_source_configuration { direct_put_content = true + faq_ids = [aws_kendra_faq.example.faq_id] } user_identity_configuration { identity_attribute_name = "12345ec453-1546651e-79c4-4554-91fa-00b43ccfa245"