Skip to content

Commit

Permalink
tests/kendra_experience: with faq ids
Browse files Browse the repository at this point in the history
  • Loading branch information
anGie44 committed Jun 22, 2022
1 parent e38d116 commit 83599ba
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 8 deletions.
154 changes: 154 additions & 0 deletions internal/service/kendra/experience_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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),
Expand Down
18 changes: 10 additions & 8 deletions internal/service/kendra/kendra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/kendra_experience.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 83599ba

Please sign in to comment.