From 76b9bff4b5df73c1a907ab54c3e83236f2451dca Mon Sep 17 00:00:00 2001 From: Anthony Wat Date: Sat, 18 May 2024 15:52:13 -0400 Subject: [PATCH 1/3] feat: Add skip_resource_in_use_check arg to aws_bedrockagent_agent --- .changelog/37586.txt | 3 ++ internal/service/bedrockagent/agent.go | 12 +++++++- internal/service/bedrockagent/agent_test.go | 30 +++++++++++-------- .../docs/r/bedrockagent_agent.html.markdown | 13 ++++---- 4 files changed, 39 insertions(+), 19 deletions(-) create mode 100644 .changelog/37586.txt diff --git a/.changelog/37586.txt b/.changelog/37586.txt new file mode 100644 index 00000000000..ba036e94819 --- /dev/null +++ b/.changelog/37586.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_bedrockagent_agent : Add `skip_resource_in_use_check` argument +``` \ No newline at end of file diff --git a/internal/service/bedrockagent/agent.go b/internal/service/bedrockagent/agent.go index 152acf06537..50b1f61b04f 100644 --- a/internal/service/bedrockagent/agent.go +++ b/internal/service/bedrockagent/agent.go @@ -143,6 +143,14 @@ func (r *agentResource) Schema(ctx context.Context, request resource.SchemaReque boolplanmodifier.UseStateForUnknown(), }, }, + "skip_resource_in_use_check": schema.BoolAttribute{ + Optional: true, + Computed: true, + Default: booldefault.StaticBool(false), + PlanModifiers: []planmodifier.Bool{ + boolplanmodifier.UseStateForUnknown(), + }, + }, names.AttrTags: tftags.TagsAttribute(), names.AttrTagsAll: tftags.TagsAttributeComputedOnly(), }, @@ -344,7 +352,8 @@ func (r *agentResource) Delete(ctx context.Context, request resource.DeleteReque agentID := data.ID.ValueString() _, err := conn.DeleteAgent(ctx, &bedrockagent.DeleteAgentInput{ - AgentId: fwflex.StringFromFramework(ctx, data.AgentID), + AgentId: fwflex.StringFromFramework(ctx, data.AgentID), + SkipResourceInUseCheck: *fwflex.BoolFromFramework(ctx, data.SkipResourceInUseCheck), }) if errs.IsA[*awstypes.ResourceNotFoundException](err) { @@ -544,6 +553,7 @@ type agentResourceModel struct { Instruction types.String `tfsdk:"instruction"` PrepareAgent types.Bool `tfsdk:"prepare_agent"` PromptOverrideConfiguration fwtypes.ListNestedObjectValueOf[promptOverrideConfigurationModel] `tfsdk:"prompt_override_configuration"` + SkipResourceInUseCheck types.Bool `tfsdk:"skip_resource_in_use_check"` Tags types.Map `tfsdk:"tags"` TagsAll types.Map `tfsdk:"tags_all"` Timeouts timeouts.Value `tfsdk:"timeouts"` diff --git a/internal/service/bedrockagent/agent_test.go b/internal/service/bedrockagent/agent_test.go index 13d1adc2fde..95c0b07eb64 100644 --- a/internal/service/bedrockagent/agent_test.go +++ b/internal/service/bedrockagent/agent_test.go @@ -42,9 +42,10 @@ func TestAccBedrockAgentAgent_basic(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"skip_resource_in_use_check"}, }, }, }) @@ -69,12 +70,14 @@ func TestAccBedrockAgentAgent_full(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "agent_name", rName), resource.TestCheckResourceAttr(resourceName, "prompt_override_configuration.#", acctest.Ct1), resource.TestCheckResourceAttr(resourceName, names.AttrDescription, "basic claude"), + resource.TestCheckResourceAttr(resourceName, "skip_resource_in_use_check", "true"), ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"skip_resource_in_use_check"}, }, }, }) @@ -120,9 +123,10 @@ func TestAccBedrockAgentAgent_update(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"skip_resource_in_use_check"}, }, }, }) @@ -149,9 +153,10 @@ func TestAccBedrockAgentAgent_tags(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"skip_resource_in_use_check"}, }, { Config: testAccAgentConfig_tags2(rName, "anthropic.claude-v2", acctest.CtKey1, acctest.CtValue1Updated, acctest.CtKey2, acctest.CtValue2), @@ -335,6 +340,7 @@ resource "aws_bedrockagent_agent" "test" { idle_session_ttl_in_seconds = 500 instruction = file("${path.module}/test-fixtures/instruction.txt") foundation_model = %[2]q + skip_resource_in_use_check = true prompt_override_configuration { override_lambda = null diff --git a/website/docs/r/bedrockagent_agent.html.markdown b/website/docs/r/bedrockagent_agent.html.markdown index 326cdaeaaa5..a304222950a 100644 --- a/website/docs/r/bedrockagent_agent.html.markdown +++ b/website/docs/r/bedrockagent_agent.html.markdown @@ -82,28 +82,29 @@ The following arguments are optional: * `idle_session_ttl_in_seconds` - (Optional) Number of seconds for which Amazon Bedrock keeps information about a user's conversation with the agent. A user interaction remains active for the amount of time specified. If no conversation occurs during this time, the session expires and Amazon Bedrock deletes any data provided before the timeout. * `instruction` - (Optional) Instructions that tell the agent what it should do and how it should interact with users. * `prepare_agent` (Optional) Whether to prepare the agent after creation or modification. Defaults to `true`. -* `prompt_override_configuration` (Optional) Configurations to override prompt templates in different parts of an agent sequence. For more information, see [Advanced prompts](https://docs.aws.amazon.com/bedrock/latest/userguide/advanced-prompts.html). See [`prompt_override_configuration` block](#prompt_override_configuration-block) for details. +* `prompt_override_configuration` (Optional) Configurations to override prompt templates in different parts of an agent sequence. For more information, see [Advanced prompts](https://docs.aws.amazon.com/bedrock/latest/userguide/advanced-prompts.html). See [`prompt_override_configuration` Block](#prompt_override_configuration-block) for details. +* `skip_resource_in_use_check` - (Optional) Whether the in-use check is skipped when deleting the agent. * `tags` - (Optional) Map of tags assigned to the resource. If configured with a provider [`default_tags` configuration block](/docs/providers/aws/index.html#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level. -### `prompt_override_configuration` block +### `prompt_override_configuration` Block The `prompt_override_configuration` configuration block supports the following arguments: -* `prompt_configurations` - (Required) Configurations to override a prompt template in one part of an agent sequence. See [`prompt_configurations` block](#prompt_configurations-block) for details. +* `prompt_configurations` - (Required) Configurations to override a prompt template in one part of an agent sequence. See [`prompt_configurations` Block](#prompt_configurations-block) for details. * `override_lambda` - (Optional) ARN of the Lambda function to use when parsing the raw foundation model output in parts of the agent sequence. If you specify this field, at least one of the `prompt_configurations` block must contain a `parser_mode` value that is set to `OVERRIDDEN`. -### `prompt_configurations` block +### `prompt_configurations` Block The `prompt_configurations` configuration block supports the following arguments: * `base_prompt_template` - (Required) prompt template with which to replace the default prompt template. You can use placeholder variables in the base prompt template to customize the prompt. For more information, see [Prompt template placeholder variables](https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-placeholders.html). -* `inference_configuration` - (Required) Inference parameters to use when the agent invokes a foundation model in the part of the agent sequence defined by the `prompt_type`. For more information, see [Inference parameters for foundation models](https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters.html). See [`inference_configuration` block](#inference_configuration-block) for details. +* `inference_configuration` - (Required) Inference parameters to use when the agent invokes a foundation model in the part of the agent sequence defined by the `prompt_type`. For more information, see [Inference parameters for foundation models](https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters.html). See [`inference_configuration` Block](#inference_configuration-block) for details. * `parser_mode` - (Required) Whether to override the default parser Lambda function when parsing the raw foundation model output in the part of the agent sequence defined by the `prompt_type`. If you set the argument as `OVERRIDDEN`, the `override_lambda` argument in the [`prompt_override_configuration`](#prompt_override_configuration-block) block must be specified with the ARN of a Lambda function. Valid values: `DEFAULT`, `OVERRIDDEN`. * `prompt_creation_mode` - (Required) Whether to override the default prompt template for this `prompt_type`. Set this argument to `OVERRIDDEN` to use the prompt that you provide in the `base_prompt_template`. If you leave it as `DEFAULT`, the agent uses a default prompt template. Valid values: `DEFAULT`, `OVERRIDDEN`. * `prompt_state` - (Required) Whether to allow the agent to carry out the step specified in the `prompt_type`. If you set this argument to `DISABLED`, the agent skips that step. Valid Values: `ENABLED`, `DISABLED`. * `prompt_type` - (Required) Step in the agent sequence that this prompt configuration applies to. Valid values: `PRE_PROCESSING`, `ORCHESTRATION`, `POST_PROCESSING`, `KNOWLEDGE_BASE_RESPONSE_GENERATION`. -### `inference_configuration` block +### `inference_configuration` Block The `inference_configuration` configuration block supports the following arguments: From d6f345a2f1b7506d9440386812dea79a4eb45320 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Thu, 18 Jul 2024 12:38:59 -0400 Subject: [PATCH 2/3] Cosmetics. --- internal/service/bedrockagent/agent.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/bedrockagent/agent.go b/internal/service/bedrockagent/agent.go index fb80f32b02b..d7874690e99 100644 --- a/internal/service/bedrockagent/agent.go +++ b/internal/service/bedrockagent/agent.go @@ -353,7 +353,7 @@ func (r *agentResource) Delete(ctx context.Context, request resource.DeleteReque agentID := data.ID.ValueString() _, err := conn.DeleteAgent(ctx, &bedrockagent.DeleteAgentInput{ AgentId: fwflex.StringFromFramework(ctx, data.AgentID), - SkipResourceInUseCheck: *fwflex.BoolFromFramework(ctx, data.SkipResourceInUseCheck), + SkipResourceInUseCheck: fwflex.BoolValueFromFramework(ctx, data.SkipResourceInUseCheck), }) if errs.IsA[*awstypes.ResourceNotFoundException](err) { From 87b1d55ea697153c5f613215df573c55a0a6fa6f Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Thu, 18 Jul 2024 13:16:35 -0400 Subject: [PATCH 3/3] Run 'make fix-constants PKG=bedrockagent'. --- internal/service/bedrockagent/agent_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/bedrockagent/agent_test.go b/internal/service/bedrockagent/agent_test.go index 6ed0558a73f..f083325f64c 100644 --- a/internal/service/bedrockagent/agent_test.go +++ b/internal/service/bedrockagent/agent_test.go @@ -70,7 +70,7 @@ func TestAccBedrockAgentAgent_full(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "agent_name", rName), resource.TestCheckResourceAttr(resourceName, "prompt_override_configuration.#", acctest.Ct1), resource.TestCheckResourceAttr(resourceName, names.AttrDescription, "basic claude"), - resource.TestCheckResourceAttr(resourceName, "skip_resource_in_use_check", "true"), + resource.TestCheckResourceAttr(resourceName, "skip_resource_in_use_check", acctest.CtTrue), ), }, {