From aa32010c3a6e11f49fc7689bc13f2adbe52538ec Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Thu, 9 May 2024 15:40:21 -0400 Subject: [PATCH] r/aws_bedrockagent_agent: use configured `prepare_agent` value This changes removes logic in the read operation which adjusted the `prepare_agent` argument based on whether or not the agent status was `Prepared`. Now the configured `prepare_agent` value is always used, regardless of the status of the agent. If omitted, the default value of `true` is inherited, meaning that by default agents will always be prepared as part of the create or update operation. The `prepare_agent` value is now also set to `true` when an agent is imported. ```console % make testacc PKG=bedrockagent TESTS=TestAccBedrockAgentAgent_ ==> Checking that code complies with gofmt requirements... TF_ACC=1 go1.22.2 test ./internal/service/bedrockagent/... -v -count 1 -parallel 20 -run='TestAccBedrockAgentAgent_' -timeout 360m --- PASS: TestAccBedrockAgentAgent_basic (19.66s) --- PASS: TestAccBedrockAgentAgent_full (19.67s) --- PASS: TestAccBedrockAgentAgent_tags (35.51s) --- PASS: TestAccBedrockAgentAgent_update (37.46s) PASS ok github.com/hashicorp/terraform-provider-aws/internal/service/bedrockagent 42.493s ``` --- .changelog/37405.txt | 3 +++ internal/service/bedrockagent/agent.go | 10 +++++++--- internal/service/bedrockagent/agent_test.go | 1 + 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 .changelog/37405.txt diff --git a/.changelog/37405.txt b/.changelog/37405.txt new file mode 100644 index 00000000000..ef647d65c11 --- /dev/null +++ b/.changelog/37405.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_bedrockagent_agent: Fix to use the configured `prepare_agent` value (or default value of `true` when omitted) for all create and update operations +``` diff --git a/internal/service/bedrockagent/agent.go b/internal/service/bedrockagent/agent.go index d0518045612..152acf06537 100644 --- a/internal/service/bedrockagent/agent.go +++ b/internal/service/bedrockagent/agent.go @@ -17,6 +17,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework-validators/int64validator" "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" + "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" @@ -55,7 +56,6 @@ func newAgentResource(context.Context) (resource.ResourceWithConfigure, error) { type agentResource struct { framework.ResourceWithConfigure - framework.WithImportByID framework.WithTimeouts } @@ -249,8 +249,6 @@ func (r *agentResource) Read(ctx context.Context, request resource.ReadRequest, return } - data.PrepareAgent = types.BoolValue(agent.AgentStatus == awstypes.AgentStatusPrepared) - response.Diagnostics.Append(response.State.Set(ctx, &data)...) } @@ -366,6 +364,12 @@ func (r *agentResource) Delete(ctx context.Context, request resource.DeleteReque } } +func (r *agentResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root(names.AttrID), req.ID)...) + // Set prepare_agent to default value on import + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("prepare_agent"), true)...) +} + func (r *agentResource) ModifyPlan(ctx context.Context, request resource.ModifyPlanRequest, response *resource.ModifyPlanResponse) { r.SetTagsAll(ctx, request, response) } diff --git a/internal/service/bedrockagent/agent_test.go b/internal/service/bedrockagent/agent_test.go index f44ca5e77f5..19975f58e3c 100644 --- a/internal/service/bedrockagent/agent_test.go +++ b/internal/service/bedrockagent/agent_test.go @@ -38,6 +38,7 @@ func TestAccBedrockAgentAgent_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "agent_name", rName), resource.TestCheckResourceAttr(resourceName, "prompt_override_configuration.#", "1"), resource.TestCheckResourceAttr(resourceName, names.AttrDescription, "basic claude"), + resource.TestCheckResourceAttr(resourceName, "prepare_agent", "true"), ), }, {