Skip to content

Commit

Permalink
Merge pull request #25592 from GlennChia/f-aws_kendra_query_suggestio…
Browse files Browse the repository at this point in the history
…ns_block_list

d/aws_kendra_query_suggestions_block_list
  • Loading branch information
ewbankkit committed Jun 28, 2022
2 parents b72bc5d + 4b98333 commit 3a7ba6b
Show file tree
Hide file tree
Showing 6 changed files with 306 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .changelog/25592.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-data-source
aws_kendra_query_suggestions_block_list
```
7 changes: 4 additions & 3 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,9 +711,10 @@ func Provider() *schema.Provider {
"aws_mskconnect_custom_plugin": kafkaconnect.DataSourceCustomPlugin(),
"aws_mskconnect_worker_configuration": kafkaconnect.DataSourceWorkerConfiguration(),

"aws_kendra_faq": kendra.DataSourceFaq(),
"aws_kendra_index": kendra.DataSourceIndex(),
"aws_kendra_thesaurus": kendra.DataSourceThesaurus(),
"aws_kendra_faq": kendra.DataSourceFaq(),
"aws_kendra_index": kendra.DataSourceIndex(),
"aws_kendra_query_suggestions_block_list": kendra.DataSourceQuerySuggestionsBlockList(),
"aws_kendra_thesaurus": kendra.DataSourceThesaurus(),

"aws_kinesis_stream": kinesis.DataSourceStream(),
"aws_kinesis_stream_consumer": kinesis.DataSourceStreamConsumer(),
Expand Down
15 changes: 8 additions & 7 deletions internal/service/kendra/kendra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ func TestAccKendra_serial(t *testing.T) {
"DataSource_basic": testAccIndexDataSource_basic,
},
"QuerySuggestionsBlockList": {
"basic": testAccQuerySuggestionsBlockList_basic,
"disappears": testAccQuerySuggestionsBlockList_disappears,
"tags": testAccQuerySuggestionsBlockList_tags,
"Description": testAccQuerySuggestionsBlockList_Description,
"Name": testAccQuerySuggestionsBlockList_Name,
"RoleARN": testAccQuerySuggestionsBlockList_RoleARN,
"SourceS3Path": testAccQuerySuggestionsBlockList_SourceS3Path,
"basic": testAccQuerySuggestionsBlockList_basic,
"disappears": testAccQuerySuggestionsBlockList_disappears,
"tags": testAccQuerySuggestionsBlockList_tags,
"Description": testAccQuerySuggestionsBlockList_Description,
"Name": testAccQuerySuggestionsBlockList_Name,
"RoleARN": testAccQuerySuggestionsBlockList_RoleARN,
"SourceS3Path": testAccQuerySuggestionsBlockList_SourceS3Path,
"DataSource_basic": testAccQuerySuggestionsBlockListDataSource_basic,
},
"Thesaurus": {
"basic": testAccThesaurus_basic,
Expand Down
151 changes: 151 additions & 0 deletions internal/service/kendra/query_suggestions_block_list_data_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
package kendra

import (
"context"
"fmt"
"regexp"
"time"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/aws/arn"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"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"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
)

func DataSourceQuerySuggestionsBlockList() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceQuerySuggestionsBlockListRead,
Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},
"created_at": {
Type: schema.TypeString,
Computed: true,
},
"description": {
Type: schema.TypeString,
Computed: true,
},
"error_message": {
Type: schema.TypeString,
Computed: true,
},
"file_size_bytes": {
Type: schema.TypeInt,
Computed: true,
},
"index_id": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringMatch(
regexp.MustCompile(`[a-zA-Z0-9][a-zA-Z0-9-]{35}`),
"Starts with an alphanumeric character. Subsequently, can contain alphanumeric characters and hyphens. Fixed length of 36.",
),
},
"item_count": {
Type: schema.TypeInt,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"query_suggestions_block_list_id": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringMatch(
regexp.MustCompile(`[a-zA-Z0-9][a-zA-Z0-9-]{35}`),
"Starts with an alphanumeric character. Subsequently, can contain alphanumeric characters and hyphens. Fixed length of 36.",
),
},
"role_arn": {
Type: schema.TypeString,
Computed: true,
},
"source_s3_path": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"bucket": {
Type: schema.TypeString,
Computed: true,
},
"key": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"tags": tftags.TagsSchemaComputed(),
"updated_at": {
Type: schema.TypeString,
Computed: true,
},
},
}
}

func dataSourceQuerySuggestionsBlockListRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.AWSClient).KendraConn
ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig

querySuggestionsBlockListID := d.Get("query_suggestions_block_list_id").(string)
indexID := d.Get("index_id").(string)

resp, err := FindQuerySuggestionsBlockListByID(ctx, conn, querySuggestionsBlockListID, indexID)

if err != nil {
return diag.Errorf("reading Kendra QuerySuggestionsBlockList (%s): %s", querySuggestionsBlockListID, err)
}

arn := arn.ARN{
Partition: meta.(*conns.AWSClient).Partition,
Service: "kendra",
Region: meta.(*conns.AWSClient).Region,
AccountID: meta.(*conns.AWSClient).AccountID,
Resource: fmt.Sprintf("index/%s/query-suggestions-block-list/%s", indexID, querySuggestionsBlockListID),
}.String()
d.Set("arn", arn)
d.Set("created_at", aws.ToTime(resp.CreatedAt).Format(time.RFC3339))
d.Set("description", resp.Description)
d.Set("error_message", resp.ErrorMessage)
d.Set("file_size_bytes", resp.FileSizeBytes)
d.Set("index_id", resp.IndexId)
d.Set("item_count", resp.ItemCount)
d.Set("name", resp.Name)
d.Set("query_suggestions_block_list_id", resp.Id)
d.Set("role_arn", resp.RoleArn)
d.Set("status", resp.Status)
d.Set("updated_at", aws.ToTime(resp.UpdatedAt).Format(time.RFC3339))

if err := d.Set("source_s3_path", flattenSourceS3Path(resp.SourceS3Path)); err != nil {
return diag.Errorf("setting source_s3_path: %s", err)
}

tags, err := ListTags(ctx, conn, arn)

if err != nil {
return diag.Errorf("listing tags for Kendra QuerySuggestionsBlockList (%s): %s", arn, err)
}

tags = tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig)

if err := d.Set("tags", tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()); err != nil {
return diag.Errorf("setting tags: %s", err)
}

d.SetId(fmt.Sprintf("%s/%s", querySuggestionsBlockListID, indexID))

return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package kendra_test

import (
"fmt"
"regexp"
"testing"

"github.com/aws/aws-sdk-go/service/backup"
sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
)

func testAccQuerySuggestionsBlockListDataSource_basic(t *testing.T) {
if testing.Short() {
t.Skip("skipping long-running test in short mode")
}

datasourceName := "data.aws_kendra_query_suggestions_block_list.test"
resourceName := "aws_kendra_query_suggestions_block_list.test"
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
rName2 := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t); testAccPreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, backup.EndpointsID),
ProviderFactories: acctest.ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccQuerySuggestionsBlockListDataSourceConfig_nonExistent,
ExpectError: regexp.MustCompile(`reading Kendra QuerySuggestionsBlockList`),
},
{
Config: testAccQuerySuggestionsBlockListDataSourceConfig_basic(rName, rName2),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(datasourceName, "arn", resourceName, "arn"),
resource.TestCheckResourceAttrSet(datasourceName, "created_at"),
resource.TestCheckResourceAttrPair(datasourceName, "description", resourceName, "description"),
resource.TestCheckResourceAttrSet(datasourceName, "file_size_bytes"),
resource.TestCheckResourceAttrPair(datasourceName, "id", resourceName, "id"),
resource.TestCheckResourceAttrPair(datasourceName, "index_id", resourceName, "index_id"),
resource.TestCheckResourceAttrSet(datasourceName, "item_count"),
resource.TestCheckResourceAttrPair(datasourceName, "name", resourceName, "name"),
resource.TestCheckResourceAttrPair(datasourceName, "query_suggestions_block_list_id", resourceName, "query_suggestions_block_list_id"),
resource.TestCheckResourceAttrPair(datasourceName, "role_arn", resourceName, "role_arn"),
resource.TestCheckResourceAttrPair(datasourceName, "source_s3_path.#", resourceName, "source_s3_path.#"),
resource.TestCheckResourceAttrPair(datasourceName, "source_s3_path.0.bucket", resourceName, "source_s3_path.0.bucket"),
resource.TestCheckResourceAttrPair(datasourceName, "source_s3_path.0.key", resourceName, "source_s3_path.0.key"),
resource.TestCheckResourceAttrPair(datasourceName, "status", resourceName, "status"),
resource.TestCheckResourceAttrSet(datasourceName, "updated_at"),
resource.TestCheckResourceAttrPair(datasourceName, "tags.%", resourceName, "tags.%"),
resource.TestCheckResourceAttrPair(datasourceName, "tags.Key1", resourceName, "tags.Key1")),
},
},
})
}

const testAccQuerySuggestionsBlockListDataSourceConfig_nonExistent = `
data "aws_kendra_query_suggestions_block_list" "test" {
index_id = "tf-acc-test-does-not-exist-kendra-id"
query_suggestions_block_list_id = "tf-acc-test-does-not-exist-kendra-id"
}
`

func testAccQuerySuggestionsBlockListDataSourceConfig_basic(rName, rName2 string) string {
return acctest.ConfigCompose(
testAccQuerySuggestionsBlockListBaseConfig(rName),
fmt.Sprintf(`
resource "aws_kendra_query_suggestions_block_list" "test" {
index_id = aws_kendra_index.test.id
name = %[1]q
description = "example description query suggestions block list"
role_arn = aws_iam_role.test.arn
source_s3_path {
bucket = aws_s3_bucket.test.id
key = aws_s3_object.test.key
}
tags = {
"Key1" = "Value1"
}
}
data "aws_kendra_query_suggestions_block_list" "test" {
index_id = aws_kendra_index.test.id
query_suggestions_block_list_id = aws_kendra_query_suggestions_block_list.test.query_suggestions_block_list_id
}
`, rName2))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
subcategory: "Kendra"
layout: "aws"
page_title: "AWS: aws_kendra_query_suggestions_block_list"
description: |-
Provides details about a specific Amazon Kendra block list used for query suggestions for an index.
---

# Data Source: aws_kendra_query_suggestions_block_list

Provides details about a specific Amazon Kendra block list used for query suggestions for an index.

## Example Usage

```hcl
data "aws_kendra_query_suggestions_block_list" "example" {
index_id = "12345678-1234-1234-1234-123456789123"
query_suggestions_block_list_id = "87654321-1234-4321-4321-321987654321"
}
```

## Argument Reference

The following arguments are supported:

* `index_id` - (Required) The identifier of the index that contains the block list.
* `query_suggestions_block_list_id` - (Required) The identifier of the block list.

## Attributes Reference

In addition to all of the arguments above, the following attributes are exported:

* `arn` - The Amazon Resource Name (ARN) of the block list.
* `created_at` - The date-time a block list was created.
* `description` - The description for the block list.
* `error_message` - The error message containing details if there are issues processing the block list.
* `file_size_bytes` - The current size of the block list text file in S3.
* `id` - The unique identifiers of the block list and index separated by a slash (`/`).
* `item_count` - The current number of valid, non-empty words or phrases in the block list text file.
* `name` - The name of the block list.
* `role_arn` - The Amazon Resource Name (ARN) of a role with permission to access the S3 bucket that contains the block list. For more information, see [IAM Roles for Amazon Kendra](https://docs.aws.amazon.com/kendra/latest/dg/iam-roles.html).
* `source_s3_path` - The S3 location of the block list input data. Detailed below.
* `status` - The current status of the block list. When the value is `ACTIVE`, the block list is ready for use.
* `updated_at` - The date and time that the block list was last updated.
* `tags` - Metadata that helps organize the block list you create.

The `source_s3_path` configuration block supports the following attributes:

* `bucket` - The name of the S3 bucket that contains the file.
* `key` - The name of the file.

0 comments on commit 3a7ba6b

Please sign in to comment.