From 58bb18f7157e81cda3911e4be9125e9f923726b8 Mon Sep 17 00:00:00 2001 From: Andrew Tulloch Date: Wed, 2 Oct 2024 11:28:42 +0100 Subject: [PATCH 1/7] Add RequiresReplace to attributes that can't be modified by update --- internal/service/bedrockagent/knowledge_base.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/internal/service/bedrockagent/knowledge_base.go b/internal/service/bedrockagent/knowledge_base.go index d3d128d3567..55e92fe4c29 100644 --- a/internal/service/bedrockagent/knowledge_base.go +++ b/internal/service/bedrockagent/knowledge_base.go @@ -7,6 +7,7 @@ import ( "context" "errors" "fmt" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier" "time" "github.com/aws/aws-sdk-go-v2/aws" @@ -102,6 +103,9 @@ func (r *knowledgeBaseResource) Schema(ctx context.Context, request resource.Sch listvalidator.SizeAtLeast(1), listvalidator.SizeAtMost(1), }, + PlanModifiers: []planmodifier.List{ + listplanmodifier.RequiresReplace(), + }, NestedObject: schema.NestedBlockObject{ Attributes: map[string]schema.Attribute{ names.AttrType: schema.StringAttribute{ @@ -135,6 +139,9 @@ func (r *knowledgeBaseResource) Schema(ctx context.Context, request resource.Sch listvalidator.SizeAtLeast(1), listvalidator.SizeAtMost(1), }, + PlanModifiers: []planmodifier.List{ + listplanmodifier.RequiresReplace(), + }, NestedObject: schema.NestedBlockObject{ Attributes: map[string]schema.Attribute{ names.AttrType: schema.StringAttribute{ From fadd64e03d8c72c8b61b621b0d9f15aa10efdc35 Mon Sep 17 00:00:00 2001 From: Andrew Tulloch Date: Wed, 2 Oct 2024 15:48:18 +0100 Subject: [PATCH 2/7] Changelog --- .changelog/39567.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/39567.txt diff --git a/.changelog/39567.txt b/.changelog/39567.txt new file mode 100644 index 00000000000..d2241175c2d --- /dev/null +++ b/.changelog/39567.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_bedrockagent_knowledge_base: Fix ValidationException by marking attributes that cannot be updated as requiring replacement +``` From dc0af62e657d768932facf1526058419befc9edf Mon Sep 17 00:00:00 2001 From: Andrew Tulloch Date: Wed, 2 Oct 2024 15:51:14 +0100 Subject: [PATCH 3/7] Fix imports --- internal/service/bedrockagent/knowledge_base.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/bedrockagent/knowledge_base.go b/internal/service/bedrockagent/knowledge_base.go index 55e92fe4c29..570d9c8c620 100644 --- a/internal/service/bedrockagent/knowledge_base.go +++ b/internal/service/bedrockagent/knowledge_base.go @@ -7,7 +7,6 @@ import ( "context" "errors" "fmt" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier" "time" "github.com/aws/aws-sdk-go-v2/aws" @@ -18,6 +17,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" "github.com/hashicorp/terraform-plugin-framework/schema/validator" From 90119c39e40aff3a4af57101076fe9e002757163 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 2 Oct 2024 13:03:40 -0400 Subject: [PATCH 4/7] Tweak CHANGELOG entry. --- .changelog/39567.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changelog/39567.txt b/.changelog/39567.txt index d2241175c2d..580fbca23d1 100644 --- a/.changelog/39567.txt +++ b/.changelog/39567.txt @@ -1,3 +1,3 @@ ```release-note:bug -resource/aws_bedrockagent_knowledge_base: Fix ValidationException by marking attributes that cannot be updated as requiring replacement +resource/aws_bedrockagent_knowledge_base: Change `knowledge_base_configuration` and `storage_configuration` to [ForceNew](https://developer.hashicorp.com/terraform/plugin/sdkv2/schemas/schema-behaviors#forcenew) ``` From 76399707ef2a4cfc8a5b77e7225929e11933872f Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 2 Oct 2024 13:14:04 -0400 Subject: [PATCH 5/7] r/aws_bedrockagent_knowledge_base: Add ForceNew to all nested attributes of 'knowledge_base_configuration' and 'storage_configuration'. --- .../service/bedrockagent/knowledge_base.go | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) diff --git a/internal/service/bedrockagent/knowledge_base.go b/internal/service/bedrockagent/knowledge_base.go index 570d9c8c620..5989e763f3a 100644 --- a/internal/service/bedrockagent/knowledge_base.go +++ b/internal/service/bedrockagent/knowledge_base.go @@ -110,6 +110,9 @@ func (r *knowledgeBaseResource) Schema(ctx context.Context, request resource.Sch Attributes: map[string]schema.Attribute{ names.AttrType: schema.StringAttribute{ Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, }, Blocks: map[string]schema.Block{ @@ -120,11 +123,17 @@ func (r *knowledgeBaseResource) Schema(ctx context.Context, request resource.Sch listvalidator.SizeAtLeast(1), listvalidator.SizeAtMost(1), }, + PlanModifiers: []planmodifier.List{ + listplanmodifier.RequiresReplace(), + }, NestedObject: schema.NestedBlockObject{ Attributes: map[string]schema.Attribute{ "embedding_model_arn": schema.StringAttribute{ CustomType: fwtypes.ARNType, Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, }, }, @@ -146,6 +155,9 @@ func (r *knowledgeBaseResource) Schema(ctx context.Context, request resource.Sch Attributes: map[string]schema.Attribute{ names.AttrType: schema.StringAttribute{ Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, }, Blocks: map[string]schema.Block{ @@ -154,17 +166,29 @@ func (r *knowledgeBaseResource) Schema(ctx context.Context, request resource.Sch Validators: []validator.List{ listvalidator.SizeAtMost(1), }, + PlanModifiers: []planmodifier.List{ + listplanmodifier.RequiresReplace(), + }, NestedObject: schema.NestedBlockObject{ Attributes: map[string]schema.Attribute{ "connection_string": schema.StringAttribute{ Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, "credentials_secret_arn": schema.StringAttribute{ CustomType: fwtypes.ARNType, Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, names.AttrNamespace: schema.StringAttribute{ Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, }, Blocks: map[string]schema.Block{ @@ -173,13 +197,22 @@ func (r *knowledgeBaseResource) Schema(ctx context.Context, request resource.Sch Validators: []validator.List{ listvalidator.SizeAtMost(1), }, + PlanModifiers: []planmodifier.List{ + listplanmodifier.RequiresReplace(), + }, NestedObject: schema.NestedBlockObject{ Attributes: map[string]schema.Attribute{ "metadata_field": schema.StringAttribute{ Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, "text_field": schema.StringAttribute{ Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, }, }, @@ -192,21 +225,36 @@ func (r *knowledgeBaseResource) Schema(ctx context.Context, request resource.Sch Validators: []validator.List{ listvalidator.SizeAtMost(1), }, + PlanModifiers: []planmodifier.List{ + listplanmodifier.RequiresReplace(), + }, NestedObject: schema.NestedBlockObject{ Attributes: map[string]schema.Attribute{ "credentials_secret_arn": schema.StringAttribute{ CustomType: fwtypes.ARNType, Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, names.AttrDatabaseName: schema.StringAttribute{ Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, names.AttrResourceARN: schema.StringAttribute{ CustomType: fwtypes.ARNType, Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, names.AttrTableName: schema.StringAttribute{ Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, }, Blocks: map[string]schema.Block{ @@ -215,19 +263,34 @@ func (r *knowledgeBaseResource) Schema(ctx context.Context, request resource.Sch Validators: []validator.List{ listvalidator.SizeAtMost(1), }, + PlanModifiers: []planmodifier.List{ + listplanmodifier.RequiresReplace(), + }, NestedObject: schema.NestedBlockObject{ Attributes: map[string]schema.Attribute{ "metadata_field": schema.StringAttribute{ Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, "primary_key_field": schema.StringAttribute{ Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, "text_field": schema.StringAttribute{ Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, "vector_field": schema.StringAttribute{ Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, }, }, @@ -240,17 +303,29 @@ func (r *knowledgeBaseResource) Schema(ctx context.Context, request resource.Sch Validators: []validator.List{ listvalidator.SizeAtMost(1), }, + PlanModifiers: []planmodifier.List{ + listplanmodifier.RequiresReplace(), + }, NestedObject: schema.NestedBlockObject{ Attributes: map[string]schema.Attribute{ "credentials_secret_arn": schema.StringAttribute{ CustomType: fwtypes.ARNType, Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, names.AttrEndpoint: schema.StringAttribute{ Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, "vector_index_name": schema.StringAttribute{ Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, }, Blocks: map[string]schema.Block{ @@ -259,16 +334,28 @@ func (r *knowledgeBaseResource) Schema(ctx context.Context, request resource.Sch Validators: []validator.List{ listvalidator.SizeAtMost(1), }, + PlanModifiers: []planmodifier.List{ + listplanmodifier.RequiresReplace(), + }, NestedObject: schema.NestedBlockObject{ Attributes: map[string]schema.Attribute{ "metadata_field": schema.StringAttribute{ Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, "text_field": schema.StringAttribute{ Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, "vector_field": schema.StringAttribute{ Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, }, }, @@ -281,14 +368,23 @@ func (r *knowledgeBaseResource) Schema(ctx context.Context, request resource.Sch Validators: []validator.List{ listvalidator.SizeAtMost(1), }, + PlanModifiers: []planmodifier.List{ + listplanmodifier.RequiresReplace(), + }, NestedObject: schema.NestedBlockObject{ Attributes: map[string]schema.Attribute{ "collection_arn": schema.StringAttribute{ CustomType: fwtypes.ARNType, Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, "vector_index_name": schema.StringAttribute{ Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, }, Blocks: map[string]schema.Block{ @@ -297,16 +393,28 @@ func (r *knowledgeBaseResource) Schema(ctx context.Context, request resource.Sch Validators: []validator.List{ listvalidator.SizeAtMost(1), }, + PlanModifiers: []planmodifier.List{ + listplanmodifier.RequiresReplace(), + }, NestedObject: schema.NestedBlockObject{ Attributes: map[string]schema.Attribute{ "metadata_field": schema.StringAttribute{ Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, "text_field": schema.StringAttribute{ Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, "vector_field": schema.StringAttribute{ Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, }, }, From 417e20f80cc9a4f2f49a4eb7797fd2ca59a058c4 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 2 Oct 2024 14:29:35 -0400 Subject: [PATCH 6/7] r/aws_bedrockagent_knowledge_base: Acceptance test imporvements. --- .../service/bedrockagent/knowledge_base.go | 4 +- .../bedrockagent/knowledge_base_test.go | 82 ++++++++++++++++--- 2 files changed, 73 insertions(+), 13 deletions(-) diff --git a/internal/service/bedrockagent/knowledge_base.go b/internal/service/bedrockagent/knowledge_base.go index 5989e763f3a..b243a08bca4 100644 --- a/internal/service/bedrockagent/knowledge_base.go +++ b/internal/service/bedrockagent/knowledge_base.go @@ -529,9 +529,7 @@ func (r *knowledgeBaseResource) Update(ctx context.Context, request resource.Upd conn := r.Meta().BedrockAgentClient(ctx) if !new.Description.Equal(old.Description) || - !new.KnowledgeBaseConfiguration.Equal(old.KnowledgeBaseConfiguration) || - !new.Name.Equal(old.Name) || - !new.StorageConfiguration.Equal(old.StorageConfiguration) { + !new.Name.Equal(old.Name) { input := &bedrockagent.UpdateKnowledgeBaseInput{} response.Diagnostics.Append(fwflex.Expand(ctx, new, input)...) if response.Diagnostics.HasError() { diff --git a/internal/service/bedrockagent/knowledge_base_test.go b/internal/service/bedrockagent/knowledge_base_test.go index d771aba4175..4cd2774aa7b 100644 --- a/internal/service/bedrockagent/knowledge_base_test.go +++ b/internal/service/bedrockagent/knowledge_base_test.go @@ -11,7 +11,11 @@ import ( "github.com/aws/aws-sdk-go-v2/service/bedrockagent/types" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/knownvalue" + "github.com/hashicorp/terraform-plugin-testing/plancheck" + "github.com/hashicorp/terraform-plugin-testing/statecheck" "github.com/hashicorp/terraform-plugin-testing/terraform" + "github.com/hashicorp/terraform-plugin-testing/tfjsonpath" "github.com/hashicorp/terraform-provider-aws/internal/acctest" "github.com/hashicorp/terraform-provider-aws/internal/conns" tfbedrockagent "github.com/hashicorp/terraform-provider-aws/internal/service/bedrockagent" @@ -29,7 +33,8 @@ func testAccKnowledgeBase_basicRDS(t *testing.T) { ctx := acctest.Context(t) var knowledgebase types.KnowledgeBase - rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + rName1 := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + rName2 := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_bedrockagent_knowledge_base.test" foundationModel := "amazon.titan-embed-text-v1" @@ -48,13 +53,20 @@ func testAccKnowledgeBase_basicRDS(t *testing.T) { CheckDestroy: testAccCheckKnowledgeBaseDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccKnowledgeBaseConfig_basicRDS(rName, foundationModel), + Config: testAccKnowledgeBaseConfig_basicRDS(rName1, foundationModel), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + }, + }, Check: resource.ComposeTestCheckFunc( testAccCheckKnowledgeBaseExists(ctx, resourceName, &knowledgebase), - resource.TestCheckResourceAttrPair(resourceName, names.AttrRoleARN, "aws_iam_role.test", names.AttrARN), + resource.TestCheckNoResourceAttr(resourceName, names.AttrDescription), resource.TestCheckResourceAttr(resourceName, "knowledge_base_configuration.#", acctest.Ct1), resource.TestCheckResourceAttr(resourceName, "knowledge_base_configuration.0.vector_knowledge_base_configuration.#", acctest.Ct1), resource.TestCheckResourceAttr(resourceName, "knowledge_base_configuration.0.type", "VECTOR"), + resource.TestCheckResourceAttr(resourceName, names.AttrName, rName1), + resource.TestCheckResourceAttrPair(resourceName, names.AttrRoleARN, "aws_iam_role.test", names.AttrARN), resource.TestCheckResourceAttr(resourceName, "storage_configuration.#", acctest.Ct1), resource.TestCheckResourceAttr(resourceName, "storage_configuration.0.type", "RDS"), resource.TestCheckResourceAttr(resourceName, "storage_configuration.0.rds_configuration.#", acctest.Ct1), @@ -71,6 +83,32 @@ func testAccKnowledgeBase_basicRDS(t *testing.T) { ImportState: true, ImportStateVerify: true, }, + { + Config: testAccKnowledgeBaseConfig_basicRDS(rName2, foundationModel), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + }, + }, + Check: resource.ComposeTestCheckFunc( + testAccCheckKnowledgeBaseExists(ctx, resourceName, &knowledgebase), + resource.TestCheckNoResourceAttr(resourceName, names.AttrDescription), + resource.TestCheckResourceAttr(resourceName, "knowledge_base_configuration.#", acctest.Ct1), + resource.TestCheckResourceAttr(resourceName, "knowledge_base_configuration.0.vector_knowledge_base_configuration.#", acctest.Ct1), + resource.TestCheckResourceAttr(resourceName, "knowledge_base_configuration.0.type", "VECTOR"), + resource.TestCheckResourceAttr(resourceName, names.AttrName, rName2), + resource.TestCheckResourceAttrPair(resourceName, names.AttrRoleARN, "aws_iam_role.test", names.AttrARN), + resource.TestCheckResourceAttr(resourceName, "storage_configuration.#", acctest.Ct1), + resource.TestCheckResourceAttr(resourceName, "storage_configuration.0.type", "RDS"), + resource.TestCheckResourceAttr(resourceName, "storage_configuration.0.rds_configuration.#", acctest.Ct1), + resource.TestCheckResourceAttr(resourceName, "storage_configuration.0.rds_configuration.0.table_name", "bedrock_integration.bedrock_kb"), + resource.TestCheckResourceAttr(resourceName, "storage_configuration.0.rds_configuration.0.field_mapping.#", acctest.Ct1), + resource.TestCheckResourceAttr(resourceName, "storage_configuration.0.rds_configuration.0.field_mapping.0.vector_field", "embedding"), + resource.TestCheckResourceAttr(resourceName, "storage_configuration.0.rds_configuration.0.field_mapping.0.text_field", "chunks"), + resource.TestCheckResourceAttr(resourceName, "storage_configuration.0.rds_configuration.0.field_mapping.0.metadata_field", "metadata"), + resource.TestCheckResourceAttr(resourceName, "storage_configuration.0.rds_configuration.0.field_mapping.0.primary_key_field", names.AttrID), + ), + }, }, }) } @@ -145,10 +183,18 @@ func testAccKnowledgeBase_tags(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccKnowledgeBaseConfig_tags1(rName, foundationModel, acctest.CtKey1, acctest.CtValue1), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + }, + }, + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, Check: resource.ComposeTestCheckFunc( testAccCheckKnowledgeBaseExists(ctx, resourceName, &knowledgebase), - resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, acctest.Ct1), - resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey1, acctest.CtValue1), ), }, { @@ -158,19 +204,35 @@ func testAccKnowledgeBase_tags(t *testing.T) { }, { Config: testAccKnowledgeBaseConfig_tags2(rName, foundationModel, acctest.CtKey1, acctest.CtValue1Updated, acctest.CtKey2, acctest.CtValue2), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + }, + }, + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1Updated), + acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), + })), + }, Check: resource.ComposeTestCheckFunc( testAccCheckKnowledgeBaseExists(ctx, resourceName, &knowledgebase), - resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, acctest.Ct2), - resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey1, acctest.CtValue1Updated), - resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey2, acctest.CtValue2), ), }, { Config: testAccKnowledgeBaseConfig_tags1(rName, foundationModel, acctest.CtKey2, acctest.CtValue2), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + }, + }, + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), + })), + }, Check: resource.ComposeTestCheckFunc( testAccCheckKnowledgeBaseExists(ctx, resourceName, &knowledgebase), - resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, acctest.Ct1), - resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey2, acctest.CtValue2), ), }, }, From f16b14601db15eaa6e3de0aa7a73b3c6e6d6dc78 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 2 Oct 2024 15:58:59 -0400 Subject: [PATCH 7/7] Fixup acceptance tests. --- .../agent_knowledge_base_association_test.go | 2 +- .../service/bedrockagent/data_source_test.go | 2 +- .../bedrockagent/knowledge_base_test.go | 30 ++++++++++++------- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/internal/service/bedrockagent/agent_knowledge_base_association_test.go b/internal/service/bedrockagent/agent_knowledge_base_association_test.go index 4c334395ce4..7aa1b457fa3 100644 --- a/internal/service/bedrockagent/agent_knowledge_base_association_test.go +++ b/internal/service/bedrockagent/agent_knowledge_base_association_test.go @@ -222,7 +222,7 @@ func testAccCheckAgentKnowledgeBaseAssociationExists(ctx context.Context, n stri func testAccAgentKnowledgeBaseAssociationConfig_basic(rName, agentModel, embeddingModel, description, state string) string { return acctest.ConfigCompose( testAccAgentConfig_basic(rName, agentModel, description), - testAccKnowledgeBaseConfig_basicRDS(rName, embeddingModel), + testAccKnowledgeBaseConfig_basicRDS(rName, embeddingModel, ""), fmt.Sprintf(` resource "aws_bedrockagent_agent_knowledge_base_association" "test" { agent_id = aws_bedrockagent_agent.test.id diff --git a/internal/service/bedrockagent/data_source_test.go b/internal/service/bedrockagent/data_source_test.go index f3fd86ea602..cf0bb02944a 100644 --- a/internal/service/bedrockagent/data_source_test.go +++ b/internal/service/bedrockagent/data_source_test.go @@ -561,7 +561,7 @@ func testAccCheckDataSourceExists(ctx context.Context, n string, v *types.DataSo } func testAccDataSourceConfig_base(rName, embeddingModel string) string { - return acctest.ConfigCompose(testAccKnowledgeBaseConfig_basicRDS(rName, embeddingModel), fmt.Sprintf(` + return acctest.ConfigCompose(testAccKnowledgeBaseConfig_basicRDS(rName, embeddingModel, ""), fmt.Sprintf(` resource "aws_s3_bucket" "test" { bucket = %[1]q } diff --git a/internal/service/bedrockagent/knowledge_base_test.go b/internal/service/bedrockagent/knowledge_base_test.go index 4cd2774aa7b..57d1d5ea79a 100644 --- a/internal/service/bedrockagent/knowledge_base_test.go +++ b/internal/service/bedrockagent/knowledge_base_test.go @@ -6,6 +6,7 @@ package bedrockagent_test import ( "context" "fmt" + "strconv" "testing" "github.com/aws/aws-sdk-go-v2/service/bedrockagent/types" @@ -33,8 +34,7 @@ func testAccKnowledgeBase_basicRDS(t *testing.T) { ctx := acctest.Context(t) var knowledgebase types.KnowledgeBase - rName1 := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - rName2 := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_bedrockagent_knowledge_base.test" foundationModel := "amazon.titan-embed-text-v1" @@ -53,7 +53,7 @@ func testAccKnowledgeBase_basicRDS(t *testing.T) { CheckDestroy: testAccCheckKnowledgeBaseDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccKnowledgeBaseConfig_basicRDS(rName1, foundationModel), + Config: testAccKnowledgeBaseConfig_basicRDS(rName, foundationModel, ""), ConfigPlanChecks: resource.ConfigPlanChecks{ PreApply: []plancheck.PlanCheck{ plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), @@ -65,7 +65,7 @@ func testAccKnowledgeBase_basicRDS(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "knowledge_base_configuration.#", acctest.Ct1), resource.TestCheckResourceAttr(resourceName, "knowledge_base_configuration.0.vector_knowledge_base_configuration.#", acctest.Ct1), resource.TestCheckResourceAttr(resourceName, "knowledge_base_configuration.0.type", "VECTOR"), - resource.TestCheckResourceAttr(resourceName, names.AttrName, rName1), + resource.TestCheckResourceAttr(resourceName, names.AttrName, rName), resource.TestCheckResourceAttrPair(resourceName, names.AttrRoleARN, "aws_iam_role.test", names.AttrARN), resource.TestCheckResourceAttr(resourceName, "storage_configuration.#", acctest.Ct1), resource.TestCheckResourceAttr(resourceName, "storage_configuration.0.type", "RDS"), @@ -84,7 +84,7 @@ func testAccKnowledgeBase_basicRDS(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccKnowledgeBaseConfig_basicRDS(rName2, foundationModel), + Config: testAccKnowledgeBaseConfig_basicRDS(rName, foundationModel, "test description"), ConfigPlanChecks: resource.ConfigPlanChecks{ PreApply: []plancheck.PlanCheck{ plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), @@ -92,11 +92,11 @@ func testAccKnowledgeBase_basicRDS(t *testing.T) { }, Check: resource.ComposeTestCheckFunc( testAccCheckKnowledgeBaseExists(ctx, resourceName, &knowledgebase), - resource.TestCheckNoResourceAttr(resourceName, names.AttrDescription), + resource.TestCheckResourceAttr(resourceName, names.AttrDescription, "test description"), resource.TestCheckResourceAttr(resourceName, "knowledge_base_configuration.#", acctest.Ct1), resource.TestCheckResourceAttr(resourceName, "knowledge_base_configuration.0.vector_knowledge_base_configuration.#", acctest.Ct1), resource.TestCheckResourceAttr(resourceName, "knowledge_base_configuration.0.type", "VECTOR"), - resource.TestCheckResourceAttr(resourceName, names.AttrName, rName2), + resource.TestCheckResourceAttr(resourceName, names.AttrName, rName), resource.TestCheckResourceAttrPair(resourceName, names.AttrRoleARN, "aws_iam_role.test", names.AttrARN), resource.TestCheckResourceAttr(resourceName, "storage_configuration.#", acctest.Ct1), resource.TestCheckResourceAttr(resourceName, "storage_configuration.0.type", "RDS"), @@ -142,7 +142,7 @@ func testAccKnowledgeBase_disappears(t *testing.T) { CheckDestroy: testAccCheckKnowledgeBaseDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccKnowledgeBaseConfig_basicRDS(rName, foundationModel), + Config: testAccKnowledgeBaseConfig_basicRDS(rName, foundationModel, ""), Check: resource.ComposeTestCheckFunc( testAccCheckKnowledgeBaseExists(ctx, resourceName, &knowledgebase), acctest.CheckFrameworkResourceDisappears(ctx, acctest.Provider, tfbedrockagent.ResourceKnowledgeBase, resourceName), @@ -223,7 +223,7 @@ func testAccKnowledgeBase_tags(t *testing.T) { Config: testAccKnowledgeBaseConfig_tags1(rName, foundationModel, acctest.CtKey2, acctest.CtValue2), ConfigPlanChecks: resource.ConfigPlanChecks{ PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), }, }, ConfigStateChecks: []statecheck.StateCheck{ @@ -567,12 +567,20 @@ resource "null_resource" "db_setup" { `, rName, model)) } -func testAccKnowledgeBaseConfig_basicRDS(rName, model string) string { +func testAccKnowledgeBaseConfig_basicRDS(rName, model, description string) string { + if description == "" { + description = "null" + } else { + description = strconv.Quote(description) + } + return acctest.ConfigCompose(testAccKnowledgeBase_baseRDS(rName, model), fmt.Sprintf(` resource "aws_bedrockagent_knowledge_base" "test" { name = %[1]q role_arn = aws_iam_role.test.arn + description = %[3]s + knowledge_base_configuration { vector_knowledge_base_configuration { embedding_model_arn = "arn:${data.aws_partition.current.partition}:bedrock:${data.aws_region.current.name}::foundation-model/%[2]s" @@ -598,7 +606,7 @@ resource "aws_bedrockagent_knowledge_base" "test" { depends_on = [aws_iam_role_policy.test, null_resource.db_setup] } -`, rName, model)) +`, rName, model, description)) } func testAccKnowledgeBaseConfig_tags1(rName, model, tag1Key, tag1Value string) string {