From 66d3136d485b97efe57c0eb2a2d9ebd3eaa29414 Mon Sep 17 00:00:00 2001 From: Anthony Wat Date: Wed, 15 May 2024 02:11:03 -0400 Subject: [PATCH] feat: Add provisioned throughput support to aws_bedrockagent_agent_alias --- .changelog/37520.txt | 3 + internal/service/bedrockagent/agent_alias.go | 3 +- .../service/bedrockagent/agent_alias_test.go | 93 ++++++++++++++++--- .../r/bedrockagent_agent_alias.html.markdown | 7 +- 4 files changed, 91 insertions(+), 15 deletions(-) create mode 100644 .changelog/37520.txt diff --git a/.changelog/37520.txt b/.changelog/37520.txt new file mode 100644 index 00000000000..be76e04c5e1 --- /dev/null +++ b/.changelog/37520.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_bedrockagent_agent_alias : Add `routing_configuration.provisioned_throughput` argument +``` \ No newline at end of file diff --git a/internal/service/bedrockagent/agent_alias.go b/internal/service/bedrockagent/agent_alias.go index 193035bbd0a..906a9c74d38 100644 --- a/internal/service/bedrockagent/agent_alias.go +++ b/internal/service/bedrockagent/agent_alias.go @@ -381,5 +381,6 @@ func (m *agentAliasResourceModel) setID() { } type agentAliasRoutingConfigurationListItemModel struct { - AgentVersion types.String `tfsdk:"agent_version"` + AgentVersion types.String `tfsdk:"agent_version"` + ProvisionedThroughput types.String `tfsdk:"provisioned_throughput"` } diff --git a/internal/service/bedrockagent/agent_alias_test.go b/internal/service/bedrockagent/agent_alias_test.go index 785bfeefeb5..fcade920a89 100644 --- a/internal/service/bedrockagent/agent_alias_test.go +++ b/internal/service/bedrockagent/agent_alias_test.go @@ -148,7 +148,7 @@ func TestAccBedrockAgentAgentAlias_routingUpdate(t *testing.T) { resource.TestCheckResourceAttrSet(resourceName, "agent_alias_arn"), resource.TestCheckResourceAttrSet(resourceName, "agent_alias_id"), resource.TestCheckResourceAttrSet(resourceName, "agent_id"), - resource.TestCheckResourceAttr(resourceName, names.AttrDescription, "Test ALias"), + resource.TestCheckResourceAttr(resourceName, names.AttrDescription, "Test Alias"), resource.TestCheckResourceAttr(resourceName, "routing_configuration.#", acctest.Ct1), resource.TestCheckResourceAttr(resourceName, "routing_configuration.0.agent_version", acctest.Ct1), resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, acctest.Ct0), @@ -167,7 +167,7 @@ func TestAccBedrockAgentAgentAlias_routingUpdate(t *testing.T) { resource.TestCheckResourceAttrSet(resourceName, "agent_alias_arn"), resource.TestCheckResourceAttrSet(resourceName, "agent_alias_id"), resource.TestCheckResourceAttrSet(resourceName, "agent_id"), - resource.TestCheckResourceAttr(resourceName, names.AttrDescription, "Test ALias"), + resource.TestCheckResourceAttr(resourceName, names.AttrDescription, "Test Alias"), resource.TestCheckResourceAttr(resourceName, "routing_configuration.#", acctest.Ct1), resource.TestCheckResourceAttr(resourceName, "routing_configuration.0.agent_version", acctest.Ct2), resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, acctest.Ct0), @@ -223,6 +223,44 @@ func TestAccBedrockAgentAgentAlias_tags(t *testing.T) { }) } +func TestAccBedrockAgentAgentAlias_provisionedThroughput(t *testing.T) { + acctest.Skip(t, "Bedrock Provisioned Model Throughput for Antropic Claude 2 has a minimum 1 month commitment and costs > $45K/month") + + ctx := acctest.Context(t) + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_bedrockagent_agent_alias.test2" + var v awstypes.AgentAlias + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionHasService(t, names.BedrockEndpointID) }, + ErrorCheck: acctest.ErrorCheck(t, names.BedrockAgentServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckAgentAliasDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccAgentAliasConfig_provisionedThroughout(rName, acctest.Ct1), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckAgentAliasExists(ctx, resourceName, &v), + resource.TestCheckResourceAttr(resourceName, "agent_alias_name", rName), + resource.TestCheckResourceAttrSet(resourceName, "agent_alias_arn"), + resource.TestCheckResourceAttrSet(resourceName, "agent_alias_id"), + resource.TestCheckResourceAttrSet(resourceName, "agent_id"), + resource.TestCheckResourceAttr(resourceName, names.AttrDescription, "Test Alias"), + resource.TestCheckResourceAttr(resourceName, "routing_configuration.#", acctest.Ct1), + resource.TestCheckResourceAttr(resourceName, "routing_configuration.0.agent_version", acctest.Ct1), + resource.TestCheckResourceAttrSet(resourceName, "routing_configuration.0.provisioned_throughput"), + resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, acctest.Ct0), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func testAccCheckAgentAliasDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { conn := acctest.Provider.Meta().(*conns.AWSClient).BedrockAgentClient(ctx) @@ -270,31 +308,46 @@ func testAccCheckAgentAliasExists(ctx context.Context, n string, v *awstypes.Age } } +func testAccAgentAliasConfig_provisionedModelThroughputBase(rName string) string { + return fmt.Sprintf(` +data "aws_bedrock_foundation_model" "test" { + model_id = "anthropic.claude-v2:0:18k" +} + +resource "aws_bedrock_provisioned_model_throughput" "test" { + provisioned_model_name = %[1]q + model_arn = data.aws_bedrock_foundation_model.test.model_arn + commitment_duration = "OneMonth" + model_units = 1 +} +`, rName) +} + func testAccAgentAliasConfig_basic(rName string) string { return acctest.ConfigCompose(testAccAgentConfig_basic(rName, "anthropic.claude-v2", "basic claude"), testAccAgentAliasConfig_alias(rName)) } -func testAccAgentAliasConfig_alias(name string) string { +func testAccAgentAliasConfig_alias(rName string) string { return fmt.Sprintf(` resource "aws_bedrockagent_agent_alias" "test" { agent_alias_name = %[1]q agent_id = aws_bedrockagent_agent.test.agent_id - description = "Test ALias" + description = "Test Alias" } -`, name) +`, rName) } -func testAccAgentAliasConfig_routing(name, version string) string { +func testAccAgentAliasConfig_routing(rName, version string) string { return fmt.Sprintf(` resource "aws_bedrockagent_agent_alias" "test" { agent_alias_name = %[1]q agent_id = aws_bedrockagent_agent.test.agent_id - description = "Test ALias" + description = "Test Alias" routing_configuration { agent_version = %[2]q } } -`, name, version) +`, rName, version) } func testAccagentAliasConfig_routingUpdateOne(rName string) string { @@ -305,7 +358,7 @@ func testAccagentAliasConfig_routingUpdateOne(rName string) string { resource "aws_bedrockagent_agent_alias" "second" { agent_alias_name = %[1]q agent_id = aws_bedrockagent_agent.test.agent_id - description = "Test ALias" + description = "Test Alias" depends_on = [aws_bedrockagent_agent_alias.test] } `, rName+acctest.Ct2), @@ -334,7 +387,7 @@ func testAccAgentAliasConfig_tags1(rName, tagKey1, tagValue1 string) string { resource "aws_bedrockagent_agent_alias" "test" { agent_alias_name = %[1]q agent_id = aws_bedrockagent_agent.test.agent_id - description = "Test ALias" + description = "Test Alias" tags = { %[2]q = %[3]q } @@ -347,7 +400,7 @@ func testAccAgentAliasConfig_tags2(rName, tagKey1, tagValue1, tagKey2, tagValue2 resource "aws_bedrockagent_agent_alias" "test" { agent_alias_name = %[1]q agent_id = aws_bedrockagent_agent.test.agent_id - description = "Test ALias" + description = "Test Alias" tags = { %[2]q = %[3]q %[4]q = %[5]q @@ -355,3 +408,21 @@ resource "aws_bedrockagent_agent_alias" "test" { } `, rName, tagKey1, tagValue1, tagKey2, tagValue2)) } + +func testAccAgentAliasConfig_provisionedThroughout(rName, version string) string { + return acctest.ConfigCompose( + testAccAgentAliasConfig_provisionedModelThroughputBase(rName), + testAccAgentConfig_basic(rName, "anthropic.claude-v2", "basic claude"), + testAccAgentAliasConfig_alias(rName), + fmt.Sprintf(` +resource "aws_bedrockagent_agent_alias" "test2" { + agent_alias_name = %[1]q + agent_id = aws_bedrockagent_agent.test.agent_id + description = "Test Alias" + routing_configuration { + agent_version = %[2]q + provisioned_throughput = aws_bedrock_provisioned_model_throughput.test.provisioned_model_arn + } +} +`, rName+acctest.Ct2, version)) +} diff --git a/website/docs/r/bedrockagent_agent_alias.html.markdown b/website/docs/r/bedrockagent_agent_alias.html.markdown index 106b7117faa..2c16da6d08f 100644 --- a/website/docs/r/bedrockagent_agent_alias.html.markdown +++ b/website/docs/r/bedrockagent_agent_alias.html.markdown @@ -83,14 +83,15 @@ The following arguments are required: The following arguments are optional: * `description` - (Optional) Description of the alias. -* `routing_configuration` - (Optional) Details about the routing configuration of the alias. See [`routing_configuration` block](#routing_configuration-block) for details. +* `routing_configuration` - (Optional) Details about the routing configuration of the alias. See [`routing_configuration` Block](#routing_configuration-block) for details. * `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. -### `routing_configuration` block +### `routing_configuration` Block The `routing_configuration` configuration block supports the following arguments: -* `agent_version` - (Required) Version of the agent with which the alias is associated. +* `agent_version` - (Optional) Version of the agent with which the alias is associated. +* `provisioned_throughput` - (Optional) ARN of the Provisioned Throughput assigned to the agent alias. ## Attribute Reference