Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/aws_bedrockagent_agent: use configured prepare_agent value #37405

Merged
merged 2 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
jar-b marked this conversation as resolved.
Show resolved Hide resolved
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
14 changes: 8 additions & 6 deletions website/docs/r/bedrockagent_agent.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ The following arguments are optional:
* `description` - (Optional) Description of the agent.
* `idle_session_ttl_in_seconds` - (Optional) TTL in seconds for the agent to idle.
* `instruction` - (Optional) Instructions to tell agent what it should do.
* `prompt_override_configuration` (Optional) Prompt Override Configuration
* `prepare_agent` (Optional) Whether or not to prepare the agent after creation or modification. Defaults to `true`.
* `prompt_override_configuration` (Optional) Prompt override configuration.
* `tags` - (Optional) Key-value tags for the place index. If configured with a provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level.

### prompt_override_configuration
Expand All @@ -105,7 +106,7 @@ The following arguments are required:
* `parser_mode` - (Required) DEFAULT or OVERRIDDEN to control if the `override_lambda` is used.
* `prompt_creation_mode` - (Required) DEFAULT or OVERRIDDEN to control if the default or provided `base_prompt_template` is used,
* `prompt_state` - (Required) ENABLED or DISABLED to allow the agent to carry out the step in `prompt_type`.
* `prompt_type` - (Required) The step this prompt applies to. PRE_PROCESSING | ORCHESTRATION | POST_PROCESSING | KNOWLEDGE_BASE_RESPONSE_GENERATION
* `prompt_type` - (Required) The step this prompt applies to. Valid values are `PRE_PROCESSING`, `ORCHESTRATION`, `POST_PROCESSING`, and `KNOWLEDGE_BASE_RESPONSE_GENERATION`.
* `inference_configuration` - (Required) Configures inference for the agent

### inference_configuration
Expand All @@ -126,6 +127,7 @@ This resource exports the following attributes in addition to the arguments abov

* `agent_arn` - ARN of the Agent.
* `agent_id` - ID of the Agent.
* `id` - ID of the Agent.
* `agent_version` - Version of the Agent.

## Timeouts
Expand All @@ -138,17 +140,17 @@ This resource exports the following attributes in addition to the arguments abov

## Import

In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import Agents for Amazon Bedrock Agent using the `example_id_arg`. For example:
In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import Agents for Amazon Bedrock Agent using the `id`. For example:

```terraform
import {
to = aws_bedrockagent_agent.example
id = "abcdef1234"
id = "agent-abcd1234"
}
```

Using `terraform import`, import Agents for Amazon Bedrock Agent using the `abcdef1234`. For example:
Using `terraform import`, import Agents for Amazon Bedrock Agent using the `id`. For example:

```console
% terraform import aws_bedrockagent_agent.example abcdef1234
% terraform import aws_bedrockagent_agent.example agent-abcd1234
```
Loading