-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25592 from GlennChia/f-aws_kendra_query_suggestio…
…ns_block_list d/aws_kendra_query_suggestions_block_list
- Loading branch information
Showing
6 changed files
with
306 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
151 changes: 151 additions & 0 deletions
151
internal/service/kendra/query_suggestions_block_list_data_source.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
90 changes: 90 additions & 0 deletions
90
internal/service/kendra/query_suggestions_block_list_data_source_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} |
50 changes: 50 additions & 0 deletions
50
website/docs/d/kendra_query_suggestions_block_list.html.html.markdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |