Skip to content

Commit eb40a41

Browse files
authored
Merge pull request #9 from aws-ia/feat/updates
fix: agentcore runtime regex conditions
2 parents 8766602 + f4ce5a7 commit eb40a41

File tree

5 files changed

+42
-14
lines changed

5 files changed

+42
-14
lines changed

.header.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ This module simplifies the process of:
3636
```hcl
3737
module "agentcore" {
3838
source = "aws-ia/agentcore/aws"
39-
version = "0.0.1"
39+
version = "0.0.2"
4040
4141
# Enable Agent Core Runtime
4242
create_runtime = true
@@ -61,7 +61,7 @@ module "agentcore" {
6161
```hcl
6262
module "agentcore" {
6363
source = "aws-ia/agentcore/aws"
64-
version = "0.0.1"
64+
version = "0.0.2"
6565
6666
# Enable Agent Core Runtime
6767
create_runtime = true
@@ -87,7 +87,7 @@ module "agentcore" {
8787
```hcl
8888
module "agentcore" {
8989
source = "aws-ia/agentcore/aws"
90-
version = "0.0.1"
90+
version = "0.0.2"
9191
9292
# Enable Agent Core Runtime with custom IAM role
9393
create_runtime = true
@@ -108,7 +108,7 @@ Create and configure an MCP gateway:
108108
```hcl
109109
module "agentcore" {
110110
source = "aws-ia/agentcore/aws"
111-
version = "0.0.1"
111+
version = "0.0.2"
112112
113113
# Enable Agent Core Gateway
114114
create_gateway = true
@@ -150,7 +150,7 @@ The module can automatically create a Cognito User Pool to handle JWT authentica
150150
```hcl
151151
module "agentcore" {
152152
source = "aws-ia/agentcore/aws"
153-
version = "0.0.1"
153+
version = "0.0.2"
154154
155155
# Enable Agent Core Gateway
156156
create_gateway = true

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ This module simplifies the process of:
3737
```hcl
3838
module "agentcore" {
3939
source = "aws-ia/agentcore/aws"
40-
version = "0.0.1"
40+
version = "0.0.2"
4141
4242
# Enable Agent Core Runtime
4343
create_runtime = true
@@ -62,7 +62,7 @@ module "agentcore" {
6262
```hcl
6363
module "agentcore" {
6464
source = "aws-ia/agentcore/aws"
65-
version = "0.0.1"
65+
version = "0.0.2"
6666
6767
# Enable Agent Core Runtime
6868
create_runtime = true
@@ -88,7 +88,7 @@ module "agentcore" {
8888
```hcl
8989
module "agentcore" {
9090
source = "aws-ia/agentcore/aws"
91-
version = "0.0.1"
91+
version = "0.0.2"
9292
9393
# Enable Agent Core Runtime with custom IAM role
9494
create_runtime = true
@@ -109,7 +109,7 @@ Create and configure an MCP gateway:
109109
```hcl
110110
module "agentcore" {
111111
source = "aws-ia/agentcore/aws"
112-
version = "0.0.1"
112+
version = "0.0.2"
113113
114114
# Enable Agent Core Gateway
115115
create_gateway = true
@@ -151,7 +151,7 @@ The module can automatically create a Cognito User Pool to handle JWT authentica
151151
```hcl
152152
module "agentcore" {
153153
source = "aws-ia/agentcore/aws"
154-
version = "0.0.1"
154+
version = "0.0.2"
155155
156156
# Enable Agent Core Gateway
157157
create_gateway = true
@@ -275,6 +275,7 @@ gateway_tags = {
275275
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.0.0 |
276276
| <a name="requirement_awscc"></a> [awscc](#requirement\_awscc) | >= 0.24.0 |
277277
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 3.6.0 |
278+
| <a name="requirement_time"></a> [time](#requirement\_time) | >= 0.9.0 |
278279

279280
## Providers
280281

@@ -283,6 +284,7 @@ gateway_tags = {
283284
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.0.0 |
284285
| <a name="provider_awscc"></a> [awscc](#provider\_awscc) | >= 0.24.0 |
285286
| <a name="provider_random"></a> [random](#provider\_random) | >= 3.6.0 |
287+
| <a name="provider_time"></a> [time](#provider\_time) | >= 0.9.0 |
286288

287289
## Modules
288290

@@ -307,6 +309,7 @@ No modules.
307309
| [awscc_bedrockagentcore_runtime_endpoint.agent_runtime_endpoint](https://registry.terraform.io/providers/hashicorp/awscc/latest/docs/resources/bedrockagentcore_runtime_endpoint) | resource |
308310
| [random_password.password](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/password) | resource |
309311
| [random_string.solution_prefix](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string) | resource |
312+
| [time_sleep.iam_role_propagation](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep) | resource |
310313
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
311314
| [aws_iam_policy_document.service_linked_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
312315
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.0.1
1+
v0.0.2

main.tf

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ resource "random_string" "solution_prefix" {
66
length = 4
77
special = false
88
upper = false
9+
numeric = false
910
}
1011

1112
locals {
1213
create_runtime = var.create_runtime
14+
# Sanitize runtime name to ensure it follows the regex pattern ^[a-zA-Z][a-zA-Z0-9_]{0,47}$
15+
sanitized_runtime_name = replace(var.runtime_name, "-", "_")
1316
}
1417

1518
# IAM Policy for creating the Service-Linked Role
@@ -38,9 +41,18 @@ data "aws_iam_policy_document" "service_linked_role" {
3841

3942
resource "awscc_bedrockagentcore_runtime" "agent_runtime" {
4043
count = local.create_runtime ? 1 : 0
41-
agent_runtime_name = "${random_string.solution_prefix.result}_${var.runtime_name}"
44+
agent_runtime_name = "${random_string.solution_prefix.result}_${local.sanitized_runtime_name}"
4245
description = var.runtime_description
4346
role_arn = var.runtime_role_arn != null ? var.runtime_role_arn : aws_iam_role.runtime_role[0].arn
47+
48+
# Explicit dependency to avoid race conditions with IAM role creation
49+
# Include the time_sleep resource to ensure IAM role propagation
50+
depends_on = [
51+
aws_iam_role.runtime_role,
52+
aws_iam_role_policy.runtime_role_policy,
53+
aws_iam_role_policy.runtime_slr_policy,
54+
time_sleep.iam_role_propagation
55+
]
4456

4557
agent_runtime_artifact = {
4658
container_configuration = {
@@ -109,6 +121,13 @@ resource "aws_iam_role_policy" "runtime_slr_policy" {
109121
policy = data.aws_iam_policy_document.service_linked_role[0].json
110122
}
111123

124+
# Add a time delay to ensure IAM role propagation
125+
resource "time_sleep" "iam_role_propagation" {
126+
count = local.create_runtime && var.runtime_role_arn == null ? 1 : 0
127+
depends_on = [aws_iam_role.runtime_role, aws_iam_role_policy.runtime_role_policy, aws_iam_role_policy.runtime_slr_policy]
128+
create_duration = "20s"
129+
}
130+
112131
resource "aws_iam_role_policy" "runtime_role_policy" {
113132
count = local.create_runtime && var.runtime_role_arn == null ? 1 : 0
114133
name = "${random_string.solution_prefix.result}-bedrock-agent-runtime-policy"
@@ -195,7 +214,7 @@ resource "aws_iam_role_policy" "runtime_role_policy" {
195214
]
196215
Resource = [
197216
"arn:aws:bedrock-agentcore:${data.aws_region.current.region}:${data.aws_caller_identity.current.account_id}:workload-identity-directory/default",
198-
"arn:aws:bedrock-agentcore:${data.aws_region.current.region}:${data.aws_caller_identity.current.account_id}:workload-identity-directory/default/workload-identity/${random_string.solution_prefix.result}_${var.runtime_name}-*"
217+
"arn:aws:bedrock-agentcore:${data.aws_region.current.region}:${data.aws_caller_identity.current.account_id}:workload-identity-directory/default/workload-identity/${random_string.solution_prefix.result}_${local.sanitized_runtime_name}-*"
199218
]
200219
},
201220
{
@@ -218,11 +237,13 @@ resource "aws_iam_role_policy" "runtime_role_policy" {
218237

219238
locals {
220239
create_runtime_endpoint = var.create_runtime_endpoint
240+
# Sanitize runtime endpoint name to ensure it follows the regex pattern ^[a-zA-Z][a-zA-Z0-9_]{0,47}$
241+
sanitized_runtime_endpoint_name = replace(var.runtime_endpoint_name, "-", "_")
221242
}
222243

223244
resource "awscc_bedrockagentcore_runtime_endpoint" "agent_runtime_endpoint" {
224245
count = local.create_runtime_endpoint ? 1 : 0
225-
name = "${random_string.solution_prefix.result}_${var.runtime_endpoint_name}"
246+
name = "${random_string.solution_prefix.result}_${local.sanitized_runtime_endpoint_name}"
226247
description = var.runtime_endpoint_description
227248
agent_runtime_id = var.runtime_endpoint_agent_runtime_id != null ? var.runtime_endpoint_agent_runtime_id : try(awscc_bedrockagentcore_runtime.agent_runtime[0].agent_runtime_id, null)
228249
tags = var.runtime_endpoint_tags

providers.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,9 @@ terraform {
1313
source = "hashicorp/random"
1414
version = ">= 3.6.0"
1515
}
16+
time = {
17+
source = "hashicorp/time"
18+
version = ">= 0.9.0"
19+
}
1620
}
1721
}

0 commit comments

Comments
 (0)