diff --git a/.changelog/37220.txt b/.changelog/37220.txt new file mode 100644 index 000000000000..b6b6d1aeb715 --- /dev/null +++ b/.changelog/37220.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_bedrockagent_knowledge_base: Add `storage_configuration.mongo_db_atlas_configuration` argument +``` \ No newline at end of file diff --git a/.changelog/44060.txt b/.changelog/44060.txt new file mode 100644 index 000000000000..dd0f56f7a5a3 --- /dev/null +++ b/.changelog/44060.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_bedrockagent_knowledge_base: Add `storage_configuration.opensearch_managed_cluster_configuration` argument +``` \ No newline at end of file diff --git a/.changelog/44388.txt b/.changelog/44388.txt new file mode 100644 index 000000000000..30955b45cdac --- /dev/null +++ b/.changelog/44388.txt @@ -0,0 +1,7 @@ +```release-note:enhancement +resource/aws_bedrockagent_knowledge_base: Add `knowledge_base_configuration.kendra_knowledge_base_configuration` argument +``` + +```release-note:enhancement +resource/aws_bedrockagent_knowledge_base: Make `knowledge_base_configuration.vector_knowledge_base_configuration` and ``storage_configuration` optional +``` \ No newline at end of file diff --git a/.changelog/45465.txt b/.changelog/45465.txt new file mode 100644 index 000000000000..df85be9f6843 --- /dev/null +++ b/.changelog/45465.txt @@ -0,0 +1,7 @@ +```release-note:enhancement +resource/aws_bedrockagent_knowledge_base: Add `knowledge_base_configuration.sql_knowledge_base_configuration` and `storage_configuration.neptune_analytics_configuration` arguments +``` + +```release-note:bug +resource/aws_bedrockagent_knowledge_base: Mark `knowledge_base_configuration.vector_knowledge_base_configuration.embedding_model_configuration` and `knowledge_base_configuration.vector_knowledge_base_configuration.supplemental_data_storage_configuration` as `ForceNew` +``` \ No newline at end of file diff --git a/.changelog/45468.txt b/.changelog/45468.txt new file mode 100644 index 000000000000..cf8b77a307fa --- /dev/null +++ b/.changelog/45468.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_bedrockagent_knowledge_base: Add `storage_configuration.s3_vectors_configuration` block +``` diff --git a/docs/acc-test-environment-variables.md b/docs/acc-test-environment-variables.md index 6d50e00f87bb..6a2444a91ebf 100644 --- a/docs/acc-test-environment-variables.md +++ b/docs/acc-test-environment-variables.md @@ -110,6 +110,7 @@ Environment variables (beyond standard AWS Go SDK ones) used by acceptance testi | `TF_AWS_CONTROLTOWER_CONTROL_OU_NAME` | Organizational unit name to be targeted by the Control Tower control. | | `TF_AWS_CONTROLTOWER_BASELINE_ENABLE_BASELINE_ARN` | Enable baseline ARN. | | `TF_AWS_DATAEXCHANGE_DATA_SET_ID` | ID of DataExchange Data Set to use for testing. | +| `TF_AWS_KENDRA_INDEX_ARN` | ARN of Kendra Index to use for testing. | | `TF_AWS_LICENSE_MANAGER_GRANT_HOME_REGION` | Region where a License Manager license is imported. | | `TF_AWS_LICENSE_MANAGER_GRANT_LICENSE_ARN` | ARN for a License Manager license imported into the current account. | | `TF_AWS_LICENSE_MANAGER_GRANT_PRINCIPAL` | ARN of a principal to share the License Manager license with. Either a root user, Organization, or Organizational Unit. | diff --git a/internal/acctest/configs.go b/internal/acctest/configs.go index be9a373d3dd1..50174e64ab4e 100644 --- a/internal/acctest/configs.go +++ b/internal/acctest/configs.go @@ -728,240 +728,70 @@ resource "aws_subnet" "test" { ) } -func ConfigBedrockAgentKnowledgeBaseRDSBase(rName, model string) string { - return ConfigCompose( - ConfigVPCWithSubnetsEnableDNSHostnames(rName, 2), //nolint:mnd // 2 subnets required - fmt.Sprintf(` -data "aws_partition" "current" {} +func ConfigBedrockAgentKnowledgeBaseS3VectorsBase(rName string) string { + return fmt.Sprintf(` data "aws_region" "current" {} +data "aws_partition" "current" {} -resource "aws_iam_role" "test" { - name = %[1]q - path = "/service-role/" - assume_role_policy = < 2.2.0", + }, + }, + CheckDestroy: testAccCheckKnowledgeBaseDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccKnowledgeBaseConfig_OpenSearch_supplementalDataStorage(rName, collectionName, foundationModel), + Config: testAccKnowledgeBaseConfig_OpenSearchManagedCluster_basic(rName, foundationModel), Check: resource.ComposeTestCheckFunc( testAccCheckKnowledgeBaseExists(ctx, resourceName, &knowledgebase), - resource.TestCheckResourceAttr(resourceName, "knowledge_base_configuration.#", "1"), - resource.TestCheckResourceAttr(resourceName, "knowledge_base_configuration.0.vector_knowledge_base_configuration.#", "1"), - resource.TestCheckResourceAttr(resourceName, "knowledge_base_configuration.0.type", "VECTOR"), - resource.TestCheckResourceAttr(resourceName, "knowledge_base_configuration.0.vector_knowledge_base_configuration.0.embedding_model_configuration.0.bedrock_embedding_model_configuration.0.dimensions", "1024"), - resource.TestCheckResourceAttr(resourceName, "knowledge_base_configuration.0.vector_knowledge_base_configuration.0.embedding_model_configuration.0.bedrock_embedding_model_configuration.0.embedding_data_type", "FLOAT32"), - resource.TestCheckResourceAttr(resourceName, "knowledge_base_configuration.0.vector_knowledge_base_configuration.0.supplemental_data_storage_configuration.0.storage_location.0.type", "S3"), - resource.TestCheckResourceAttr(resourceName, "knowledge_base_configuration.0.vector_knowledge_base_configuration.0.supplemental_data_storage_configuration.0.storage_location.0.s3_location.0.uri", fmt.Sprintf("s3://%s", rName)), - resource.TestCheckResourceAttr(resourceName, "storage_configuration.#", "1"), - resource.TestCheckResourceAttr(resourceName, "storage_configuration.0.type", "OPENSEARCH_SERVERLESS"), - resource.TestCheckResourceAttr(resourceName, "storage_configuration.0.opensearch_serverless_configuration.#", "1"), - resource.TestCheckResourceAttr(resourceName, "storage_configuration.0.opensearch_serverless_configuration.0.vector_index_name", "bedrock-knowledge-base-default-index"), - resource.TestCheckResourceAttr(resourceName, "storage_configuration.0.opensearch_serverless_configuration.0.field_mapping.#", "1"), - resource.TestCheckResourceAttr(resourceName, "storage_configuration.0.opensearch_serverless_configuration.0.field_mapping.0.vector_field", "bedrock-knowledge-base-default-vector"), - resource.TestCheckResourceAttr(resourceName, "storage_configuration.0.opensearch_serverless_configuration.0.field_mapping.0.text_field", "AMAZON_BEDROCK_TEXT_CHUNK"), - resource.TestCheckResourceAttr(resourceName, "storage_configuration.0.opensearch_serverless_configuration.0.field_mapping.0.metadata_field", "AMAZON_BEDROCK_METADATA"), ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{}, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + }, + }, + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("knowledge_base_configuration"), knownvalue.ListExact([]knownvalue.Check{ + knownvalue.MapExact(map[string]knownvalue.Check{ + "kendra_knowledge_base_configuration": knownvalue.ListSizeExact(0), + "sql_knowledge_base_configuration": knownvalue.ListSizeExact(0), + names.AttrType: tfknownvalue.StringExact(awstypes.KnowledgeBaseTypeVector), + "vector_knowledge_base_configuration": knownvalue.ListSizeExact(1), + }), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("storage_configuration"), knownvalue.ListExact([]knownvalue.Check{ + knownvalue.MapExact(map[string]knownvalue.Check{ + "mongo_db_atlas_configuration": knownvalue.ListSizeExact(0), + "neptune_analytics_configuration": knownvalue.ListSizeExact(0), + "opensearch_managed_cluster_configuration": knownvalue.ListSizeExact(1), + "opensearch_serverless_configuration": knownvalue.ListSizeExact(0), + names.AttrType: tfknownvalue.StringExact(awstypes.KnowledgeBaseStorageTypeOpensearchManagedCluster), + "pinecone_configuration": knownvalue.ListSizeExact(0), + "rds_configuration": knownvalue.ListSizeExact(0), + "redis_enterprise_cloud_configuration": knownvalue.ListSizeExact(0), + "s3_vectors_configuration": knownvalue.ListSizeExact(0), + }), + })), + }, }, }, }) } -func testAccCheckKnowledgeBaseDestroy(ctx context.Context) resource.TestCheckFunc { - return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).BedrockAgentClient(ctx) - - for _, rs := range s.RootModule().Resources { - if rs.Type != "aws_bedrockagent_knowledge_base" { - continue - } - - _, err := tfbedrockagent.FindKnowledgeBaseByID(ctx, conn, rs.Primary.ID) +func testAccKnowledgeBase_S3Vectors_update(t *testing.T) { + ctx := acctest.Context(t) + var knowledgebase awstypes.KnowledgeBase + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_bedrockagent_knowledge_base.test" + foundationModel := "amazon.titan-embed-text-v2:0" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.BedrockAgentServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckKnowledgeBaseDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccKnowledgeBaseConfig_S3VectorsByIndexARN(rName, foundationModel), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + }, + }, + Check: resource.ComposeTestCheckFunc( + testAccCheckKnowledgeBaseExists(ctx, resourceName, &knowledgebase), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("knowledge_base_configuration"), knownvalue.ListExact([]knownvalue.Check{ + knownvalue.MapExact(map[string]knownvalue.Check{ + "kendra_knowledge_base_configuration": knownvalue.ListSizeExact(0), + "sql_knowledge_base_configuration": knownvalue.ListSizeExact(0), + names.AttrType: tfknownvalue.StringExact(awstypes.KnowledgeBaseTypeVector), + "vector_knowledge_base_configuration": knownvalue.ListSizeExact(1), + }), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("storage_configuration"), knownvalue.ListExact([]knownvalue.Check{ + knownvalue.MapExact(map[string]knownvalue.Check{ + "mongo_db_atlas_configuration": knownvalue.ListSizeExact(0), + "neptune_analytics_configuration": knownvalue.ListSizeExact(0), + "opensearch_managed_cluster_configuration": knownvalue.ListSizeExact(0), + "opensearch_serverless_configuration": knownvalue.ListSizeExact(0), + names.AttrType: tfknownvalue.StringExact(awstypes.KnowledgeBaseStorageTypeS3Vectors), + "pinecone_configuration": knownvalue.ListSizeExact(0), + "rds_configuration": knownvalue.ListSizeExact(0), + "redis_enterprise_cloud_configuration": knownvalue.ListSizeExact(0), + "s3_vectors_configuration": knownvalue.ListSizeExact(1), + }), + })), + }, + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccKnowledgeBaseConfig_S3VectorsByIndexName(rName, foundationModel), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionDestroyBeforeCreate), + }, + }, + Check: resource.ComposeTestCheckFunc( + testAccCheckKnowledgeBaseExists(ctx, resourceName, &knowledgebase), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("storage_configuration"), knownvalue.ListExact([]knownvalue.Check{ + knownvalue.MapExact(map[string]knownvalue.Check{ + "mongo_db_atlas_configuration": knownvalue.ListSizeExact(0), + "neptune_analytics_configuration": knownvalue.ListSizeExact(0), + "opensearch_managed_cluster_configuration": knownvalue.ListSizeExact(0), + "opensearch_serverless_configuration": knownvalue.ListSizeExact(0), + names.AttrType: tfknownvalue.StringExact(awstypes.KnowledgeBaseStorageTypeS3Vectors), + "pinecone_configuration": knownvalue.ListSizeExact(0), + "rds_configuration": knownvalue.ListSizeExact(0), + "redis_enterprise_cloud_configuration": knownvalue.ListSizeExact(0), + "s3_vectors_configuration": knownvalue.ListSizeExact(1), + }), + })), + }, + }, + }, + }) +} + +func testAccKnowledgeBase_StructuredDataStore_redshiftProvisioned(t *testing.T) { + ctx := acctest.Context(t) + var knowledgebase awstypes.KnowledgeBase + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_bedrockagent_knowledge_base.test" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.BedrockAgentServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckKnowledgeBaseDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccKnowledgeBaseConfig_StructuredDataStore_redshiftProvisioned(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckKnowledgeBaseExists(ctx, resourceName, &knowledgebase), + ), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + }, + }, + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("knowledge_base_configuration"), knownvalue.ListExact([]knownvalue.Check{ + knownvalue.MapExact(map[string]knownvalue.Check{ + "kendra_knowledge_base_configuration": knownvalue.ListSizeExact(0), + "sql_knowledge_base_configuration": knownvalue.ListExact([]knownvalue.Check{ + knownvalue.ObjectExact(map[string]knownvalue.Check{ + names.AttrType: tfknownvalue.StringExact(awstypes.QueryEngineTypeRedshift), + "redshift_configuration": knownvalue.ListExact([]knownvalue.Check{ + knownvalue.ObjectExact(map[string]knownvalue.Check{ + "query_engine_configuration": knownvalue.ListExact([]knownvalue.Check{ + knownvalue.ObjectExact(map[string]knownvalue.Check{ + names.AttrType: tfknownvalue.StringExact(awstypes.RedshiftQueryEngineTypeProvisioned), + "provisioned_configuration": knownvalue.ListSizeExact(1), + "serverless_configuration": knownvalue.ListSizeExact(0), + }), + }), + "query_generation_configuration": knownvalue.ListSizeExact(0), + "storage_configuration": knownvalue.ListExact([]knownvalue.Check{ + knownvalue.ObjectExact(map[string]knownvalue.Check{ + names.AttrType: tfknownvalue.StringExact(awstypes.RedshiftQueryEngineStorageTypeRedshift), + "aws_data_catalog_configuration": knownvalue.ListSizeExact(0), + "redshift_configuration": knownvalue.ListSizeExact(1), + }), + }), + }), + }), + }), + }), + names.AttrType: tfknownvalue.StringExact(awstypes.KnowledgeBaseTypeSql), + "vector_knowledge_base_configuration": knownvalue.ListSizeExact(0), + }), + })), + }, + }, + }, + }) +} + +func testAccKnowledgeBase_StructuredDataStore_redshiftServerless(t *testing.T) { + ctx := acctest.Context(t) + var knowledgebase awstypes.KnowledgeBase + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_bedrockagent_knowledge_base.test" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.BedrockAgentServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckKnowledgeBaseDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccKnowledgeBaseConfig_StructuredDataStore_redshiftServerless(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckKnowledgeBaseExists(ctx, resourceName, &knowledgebase), + ), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + }, + }, + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("knowledge_base_configuration"), knownvalue.ListExact([]knownvalue.Check{ + knownvalue.MapExact(map[string]knownvalue.Check{ + "kendra_knowledge_base_configuration": knownvalue.ListSizeExact(0), + "sql_knowledge_base_configuration": knownvalue.ListExact([]knownvalue.Check{ + knownvalue.ObjectExact(map[string]knownvalue.Check{ + names.AttrType: tfknownvalue.StringExact(awstypes.QueryEngineTypeRedshift), + "redshift_configuration": knownvalue.ListExact([]knownvalue.Check{ + knownvalue.ObjectExact(map[string]knownvalue.Check{ + "query_engine_configuration": knownvalue.ListExact([]knownvalue.Check{ + knownvalue.ObjectExact(map[string]knownvalue.Check{ + names.AttrType: tfknownvalue.StringExact(awstypes.RedshiftQueryEngineTypeServerless), + "provisioned_configuration": knownvalue.ListSizeExact(0), + "serverless_configuration": knownvalue.ListSizeExact(1), + }), + }), + "query_generation_configuration": knownvalue.ListSizeExact(1), + "storage_configuration": knownvalue.ListExact([]knownvalue.Check{ + knownvalue.ObjectExact(map[string]knownvalue.Check{ + names.AttrType: tfknownvalue.StringExact(awstypes.RedshiftQueryEngineStorageTypeRedshift), + "aws_data_catalog_configuration": knownvalue.ListSizeExact(0), + "redshift_configuration": knownvalue.ListSizeExact(1), + }), + }), + }), + }), + }), + }), + names.AttrType: tfknownvalue.StringExact(awstypes.KnowledgeBaseTypeSql), + "vector_knowledge_base_configuration": knownvalue.ListSizeExact(0), + }), + })), + }, + }, + }, + }) +} + +func testAccKnowledgeBase_NeptuneAnalytics_basic(t *testing.T) { + ctx := acctest.Context(t) + var knowledgebase awstypes.KnowledgeBase + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_bedrockagent_knowledge_base.test" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.BedrockAgentServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckKnowledgeBaseDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccKnowledgeBaseConfig_NeptuneAnalytics_basic(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckKnowledgeBaseExists(ctx, resourceName, &knowledgebase), + ), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + }, + }, + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("knowledge_base_configuration"), knownvalue.ListExact([]knownvalue.Check{ + knownvalue.MapExact(map[string]knownvalue.Check{ + "kendra_knowledge_base_configuration": knownvalue.ListSizeExact(0), + "sql_knowledge_base_configuration": knownvalue.ListSizeExact(0), + names.AttrType: tfknownvalue.StringExact(awstypes.KnowledgeBaseTypeVector), + "vector_knowledge_base_configuration": knownvalue.ListSizeExact(1), + }), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("storage_configuration"), knownvalue.ListExact([]knownvalue.Check{ + knownvalue.MapExact(map[string]knownvalue.Check{ + "mongo_db_atlas_configuration": knownvalue.ListSizeExact(0), + "neptune_analytics_configuration": knownvalue.ListSizeExact(1), + "opensearch_managed_cluster_configuration": knownvalue.ListSizeExact(0), + "opensearch_serverless_configuration": knownvalue.ListSizeExact(0), + names.AttrType: tfknownvalue.StringExact(awstypes.KnowledgeBaseStorageTypeNeptuneAnalytics), + "pinecone_configuration": knownvalue.ListSizeExact(0), + "rds_configuration": knownvalue.ListSizeExact(0), + "redis_enterprise_cloud_configuration": knownvalue.ListSizeExact(0), + "s3_vectors_configuration": knownvalue.ListSizeExact(0), + }), + })), + }, + }, + }, + }) +} + +func testAccCheckKnowledgeBaseDestroy(ctx context.Context) resource.TestCheckFunc { + return func(s *terraform.State) error { + conn := acctest.Provider.Meta().(*conns.AWSClient).BedrockAgentClient(ctx) + + for _, rs := range s.RootModule().Resources { + if rs.Type != "aws_bedrockagent_knowledge_base" { + continue + } + + _, err := tfbedrockagent.FindKnowledgeBaseByID(ctx, conn, rs.Primary.ID) if retry.NotFound(err) { continue @@ -430,7 +756,7 @@ func testAccCheckKnowledgeBaseDestroy(ctx context.Context) resource.TestCheckFun } } -func testAccCheckKnowledgeBaseExists(ctx context.Context, n string, v *types.KnowledgeBase) resource.TestCheckFunc { +func testAccCheckKnowledgeBaseExists(ctx context.Context, n string, v *awstypes.KnowledgeBase) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -478,147 +804,307 @@ func testAccCheckKnowledgeBaseExists(ctx context.Context, n string, v *types.Kno // environment variable below. func skipIfOSSCollectionNameEnvVarNotSet(t *testing.T) string { t.Helper() - - v := os.Getenv("TF_AWS_BEDROCK_OSS_COLLECTION_NAME") - if v == "" { - acctest.Skip(t, "This test requires external configuration of an OpenSearch collection vector index. "+ - "Set the TF_AWS_BEDROCK_OSS_COLLECTION_NAME environment variable to the OpenSearch collection name "+ - "where the vector index is configured.") - } - return v + return acctest.SkipIfEnvVarNotSet(t, "TF_AWS_BEDROCK_OSS_COLLECTION_NAME") } -func testAccKnowledgeBaseConfig_basicRDS(rName, model, description string) string { - if description == "" { - description = "null" - } else { - description = strconv.Quote(description) - } - - return acctest.ConfigCompose(acctest.ConfigBedrockAgentKnowledgeBaseRDSBase(rName, model), fmt.Sprintf(` +func testAccKnowledgeBaseConfig_tags1(rName, model, tag1Key, tag1Value string) string { + return acctest.ConfigCompose(acctest.ConfigBedrockAgentKnowledgeBaseS3VectorsBase(rName), fmt.Sprintf(` resource "aws_bedrockagent_knowledge_base" "test" { + depends_on = [ + aws_iam_role_policy.test, + ] + name = %[1]q role_arn = aws_iam_role.test.arn - description = %[3]s - knowledge_base_configuration { + type = "VECTOR" + vector_knowledge_base_configuration { embedding_model_arn = "arn:${data.aws_partition.current.partition}:bedrock:${data.aws_region.current.region}::foundation-model/%[2]s" + embedding_model_configuration { + bedrock_embedding_model_configuration { + dimensions = 256 + embedding_data_type = "FLOAT32" + } + } } - type = "VECTOR" } storage_configuration { - type = "RDS" - rds_configuration { - resource_arn = aws_rds_cluster.test.arn - credentials_secret_arn = tolist(aws_rds_cluster.test.master_user_secret)[0].secret_arn - database_name = aws_rds_cluster.test.database_name - table_name = "bedrock_integration.bedrock_kb" - field_mapping { - vector_field = "embedding" - text_field = "chunks" - metadata_field = "metadata" - primary_key_field = "id" - custom_metadata_field = "custom_metadata" - } + type = "S3_VECTORS" + + s3_vectors_configuration { + index_arn = aws_s3vectors_index.test.index_arn } } - depends_on = [aws_iam_role_policy.test, null_resource.db_setup] + tags = { + %[3]q = %[4]q + } } -`, rName, model, description)) +`, rName, model, tag1Key, tag1Value)) } -func testAccKnowledgeBaseConfig_updateRDS(rName, model, description string) string { - return acctest.ConfigCompose(acctest.ConfigBedrockAgentKnowledgeBaseRDSUpdateBase(rName, model), fmt.Sprintf(` +func testAccKnowledgeBaseConfig_tags2(rName, model, tag1Key, tag1Value, tag2Key, tag2Value string) string { + return acctest.ConfigCompose(acctest.ConfigBedrockAgentKnowledgeBaseS3VectorsBase(rName), fmt.Sprintf(` resource "aws_bedrockagent_knowledge_base" "test" { - name = "%[1]s-update" - role_arn = aws_iam_role.test_update.arn + depends_on = [ + aws_iam_role_policy.test, + ] - description = %[3]q + name = %[1]q + role_arn = aws_iam_role.test.arn knowledge_base_configuration { + type = "VECTOR" + vector_knowledge_base_configuration { embedding_model_arn = "arn:${data.aws_partition.current.partition}:bedrock:${data.aws_region.current.region}::foundation-model/%[2]s" + embedding_model_configuration { + bedrock_embedding_model_configuration { + dimensions = 256 + embedding_data_type = "FLOAT32" + } + } } - type = "VECTOR" } storage_configuration { - type = "RDS" - rds_configuration { - resource_arn = aws_rds_cluster.test.arn - credentials_secret_arn = tolist(aws_rds_cluster.test.master_user_secret)[0].secret_arn - database_name = aws_rds_cluster.test.database_name - table_name = "bedrock_integration.bedrock_kb" - field_mapping { - vector_field = "embedding" - text_field = "chunks" - metadata_field = "metadata" - primary_key_field = "id" - custom_metadata_field = "custom_metadata" - } + type = "S3_VECTORS" + + s3_vectors_configuration { + index_arn = aws_s3vectors_index.test.index_arn } } - depends_on = [aws_iam_role_policy.test_update, null_resource.db_setup] + tags = { + %[3]q = %[4]q + %[5]q = %[6]q + } } -`, rName, model, description)) +`, rName, model, tag1Key, tag1Value, tag2Key, tag2Value)) } -func testAccKnowledgeBaseConfig_tags1(rName, model, tag1Key, tag1Value string) string { - return acctest.ConfigCompose(acctest.ConfigBedrockAgentKnowledgeBaseRDSBase(rName, model), fmt.Sprintf(` +func testAccKnowledgeBaseConfig_description(rName, model, description string) string { + return acctest.ConfigCompose(acctest.ConfigBedrockAgentKnowledgeBaseS3VectorsBase(rName), fmt.Sprintf(` resource "aws_bedrockagent_knowledge_base" "test" { - name = %[1]q - role_arn = aws_iam_role.test.arn + depends_on = [ + aws_iam_role_policy.test, + ] + + name = %[1]q + role_arn = aws_iam_role.test.arn + description = %[3]q knowledge_base_configuration { + type = "VECTOR" + vector_knowledge_base_configuration { embedding_model_arn = "arn:${data.aws_partition.current.partition}:bedrock:${data.aws_region.current.region}::foundation-model/%[2]s" + embedding_model_configuration { + bedrock_embedding_model_configuration { + dimensions = 256 + embedding_data_type = "FLOAT32" + } + } } - type = "VECTOR" } storage_configuration { - type = "RDS" - rds_configuration { - resource_arn = aws_rds_cluster.test.arn - credentials_secret_arn = tolist(aws_rds_cluster.test.master_user_secret)[0].secret_arn - database_name = aws_rds_cluster.test.database_name - table_name = "bedrock_integration.bedrock_kb" - field_mapping { - vector_field = "embedding" - text_field = "chunks" - metadata_field = "metadata" - primary_key_field = "id" - custom_metadata_field = "custom_metadata" - } - } - } + type = "S3_VECTORS" - tags = { - %[3]q = %[4]q + s3_vectors_configuration { + index_arn = aws_s3vectors_index.test.index_arn + } } - - depends_on = [aws_iam_role_policy.test, null_resource.db_setup] } -`, rName, model, tag1Key, tag1Value)) +`, rName, model, description)) } -func testAccKnowledgeBaseConfig_tags2(rName, model, tag1Key, tag1Value, tag2Key, tag2Value string) string { - return acctest.ConfigCompose(acctest.ConfigBedrockAgentKnowledgeBaseRDSBase(rName, model), fmt.Sprintf(` -resource "aws_bedrockagent_knowledge_base" "test" { - name = %[1]q - role_arn = aws_iam_role.test.arn +func testAccKnowledgeBaseConfig_baseRDS(rName, model string) string { + return acctest.ConfigCompose(acctest.ConfigVPCWithSubnetsEnableDNSHostnames(rName, 2), fmt.Sprintf(` +data "aws_partition" "current" {} +data "aws_region" "current" {} - knowledge_base_configuration { - vector_knowledge_base_configuration { - embedding_model_arn = "arn:${data.aws_partition.current.partition}:bedrock:${data.aws_region.current.region}::foundation-model/%[2]s" - } - type = "VECTOR" - } +resource "aws_iam_role" "test" { + name = %[1]q + path = "/service-role/" + assume_role_policy = <