Skip to content

Commit

Permalink
r/aws_bedrockagent_agent: use configured prepare_agent value
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
jar-b committed May 9, 2024
1 parent ef68be1 commit aa32010
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .changelog/37405.txt
Original file line number Diff line number Diff line change
@@ -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
```
10 changes: 7 additions & 3 deletions internal/service/bedrockagent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -55,7 +56,6 @@ func newAgentResource(context.Context) (resource.ResourceWithConfigure, error) {

type agentResource struct {
framework.ResourceWithConfigure
framework.WithImportByID
framework.WithTimeouts
}

Expand Down Expand Up @@ -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)...)
}

Expand Down Expand Up @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions internal/service/bedrockagent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
},
{
Expand Down

0 comments on commit aa32010

Please sign in to comment.