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

feat: Add provisioned throughput support to aws_bedrockagent_agent_alias #37520

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/37520.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_bedrockagent_agent_alias : Add `routing_configuration.provisioned_throughput` argument
```
3 changes: 2 additions & 1 deletion internal/service/bedrockagent/agent_alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
93 changes: 82 additions & 11 deletions internal/service/bedrockagent/agent_alias_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -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),
Expand Down Expand Up @@ -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
}
Expand All @@ -347,11 +400,29 @@ 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
}
}
`, 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))
}
7 changes: 4 additions & 3 deletions website/docs/r/bedrockagent_agent_alias.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading