@aws/nx-plugin 1.0.0-rc.83 → 1.0.0-rc.85

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/generators.json +7 -0
  2. package/migrations.json +31 -1
  3. package/package.json +1 -1
  4. package/src/agentcore-gateway/__snapshots__/generator.spec.ts.snap +51 -2
  5. package/src/agentcore-harness/__snapshots__/generator.spec.ts.snap +4 -5
  6. package/src/agentcore-harness/files/project/README.md.template +4 -5
  7. package/src/internal/test-matrix/generator.js +16 -0
  8. package/src/internal/test-matrix/generator.js.map +1 -1
  9. package/src/migrations/latest/agentcore-harness-no-tools-by-default/__snapshots__/migration.spec.ts.snap +79 -0
  10. package/src/migrations/latest/agentcore-harness-no-tools-by-default/metadata.json +3 -0
  11. package/src/migrations/latest/agentcore-harness-no-tools-by-default/migration.d.ts +6 -0
  12. package/src/migrations/latest/agentcore-harness-no-tools-by-default/migration.js +87 -0
  13. package/src/migrations/latest/agentcore-harness-no-tools-by-default/migration.js.map +1 -0
  14. package/src/migrations/latest/rdb-terraform-aurora-app-module-defaults/__snapshots__/migration.spec.ts.snap +54 -0
  15. package/src/migrations/latest/rdb-terraform-aurora-app-module-defaults/metadata.json +3 -0
  16. package/src/migrations/latest/rdb-terraform-aurora-app-module-defaults/migration.d.ts +6 -0
  17. package/src/migrations/latest/rdb-terraform-aurora-app-module-defaults/migration.js +86 -0
  18. package/src/migrations/latest/rdb-terraform-aurora-app-module-defaults/migration.js.map +1 -0
  19. package/src/migrations/latest/terraform-declare-used-providers/metadata.json +3 -0
  20. package/src/migrations/latest/terraform-declare-used-providers/migration.d.ts +6 -0
  21. package/src/migrations/latest/terraform-declare-used-providers/migration.js +147 -0
  22. package/src/migrations/latest/terraform-declare-used-providers/migration.js.map +1 -0
  23. package/src/migrations/latest/terraform-harness-vpc-role-and-memory-grant/__snapshots__/migration.spec.ts.snap +521 -0
  24. package/src/migrations/latest/terraform-harness-vpc-role-and-memory-grant/metadata.json +3 -0
  25. package/src/migrations/latest/terraform-harness-vpc-role-and-memory-grant/migration.d.ts +6 -0
  26. package/src/migrations/latest/terraform-harness-vpc-role-and-memory-grant/migration.js +504 -0
  27. package/src/migrations/latest/terraform-harness-vpc-role-and-memory-grant/migration.js.map +1 -0
  28. package/src/migrations/latest/terraform-project-checkov-target-and-bootstrap-destroy/metadata.json +3 -0
  29. package/src/migrations/latest/terraform-project-checkov-target-and-bootstrap-destroy/migration.d.ts +6 -0
  30. package/src/migrations/latest/terraform-project-checkov-target-and-bootstrap-destroy/migration.js +146 -0
  31. package/src/migrations/latest/terraform-project-checkov-target-and-bootstrap-destroy/migration.js.map +1 -0
  32. package/src/migrations/latest/waf-log-group-cmk-encryption/__snapshots__/migration.spec.ts.snap +286 -0
  33. package/src/migrations/latest/waf-log-group-cmk-encryption/metadata.json +3 -0
  34. package/src/migrations/latest/waf-log-group-cmk-encryption/migration.d.ts +6 -0
  35. package/src/migrations/latest/waf-log-group-cmk-encryption/migration.js +238 -0
  36. package/src/migrations/latest/waf-log-group-cmk-encryption/migration.js.map +1 -0
  37. package/src/open-api/json-metadata/generator.d.ts +24 -0
  38. package/src/open-api/json-metadata/generator.js +37 -0
  39. package/src/open-api/json-metadata/generator.js.map +1 -0
  40. package/src/open-api/json-metadata/schema.d.js +6 -0
  41. package/src/open-api/json-metadata/schema.d.js.map +1 -0
  42. package/src/open-api/json-metadata/schema.d.ts +9 -0
  43. package/src/open-api/json-metadata/schema.json +20 -0
  44. package/src/py/agent/__snapshots__/generator.protocols.spec.ts.snap +12 -0
  45. package/src/py/fast-api/__snapshots__/generator.terraform.spec.ts.snap +1875 -623
  46. package/src/py/fast-api/generator.js +2 -1
  47. package/src/py/fast-api/generator.js.map +1 -1
  48. package/src/py/lambda-function/__snapshots__/generator.spec.ts.snap +8 -0
  49. package/src/py/mcp-server/__snapshots__/generator.spec.ts.snap +4 -0
  50. package/src/py/rdb/__snapshots__/generator.spec.ts.snap +31 -2
  51. package/src/sdk/open-api.d.ts +2 -0
  52. package/src/sdk/open-api.js +2 -1
  53. package/src/sdk/open-api.js.map +1 -1
  54. package/src/smithy/ts/api/__snapshots__/generator.spec.ts.snap +1756 -457
  55. package/src/smithy/ts/api/generator.js +2 -1
  56. package/src/smithy/ts/api/generator.js.map +1 -1
  57. package/src/terraform/project/files/application/bootstrap/providers.tf.template +11 -0
  58. package/src/terraform/project/files/application/scripts/bootstrap-destroy.ts.template +111 -0
  59. package/src/terraform/project/files/application/src/providers.tf.template +6 -0
  60. package/src/terraform/project/files/checkov/checkov.yml.template +8 -0
  61. package/src/terraform/project/files/library/src/main.tf.template +9 -0
  62. package/src/terraform/project/generator.js +47 -4
  63. package/src/terraform/project/generator.js.map +1 -1
  64. package/src/trpc/backend/__snapshots__/generator.spec.ts.snap +1848 -614
  65. package/src/trpc/backend/files-operations/scripts/generate-operations.ts.template +40 -0
  66. package/src/trpc/backend/generator.js +10 -0
  67. package/src/trpc/backend/generator.js.map +1 -1
  68. package/src/ts/agent/__snapshots__/generator.spec.ts.snap +8 -0
  69. package/src/ts/dcr-proxy/__snapshots__/generator.spec.ts.snap +4 -0
  70. package/src/ts/lambda-function/__snapshots__/generator.spec.ts.snap +8 -0
  71. package/src/ts/mcp-server/__snapshots__/generator.spec.ts.snap +4 -0
  72. package/src/ts/rdb/__snapshots__/generator.spec.ts.snap +62 -4
  73. package/src/ts/react-website/app/__snapshots__/generator.spec.ts.snap +4 -0
  74. package/src/ts/react-website/cognito-auth/__snapshots__/generator.spec.ts.snap +35 -8
  75. package/src/ts/react-website/cognito-auth/__snapshots__/generator.terraform.spec.ts.snap +4 -0
  76. package/src/utils/agent-core-constructs/files/cdk/app/agentcore-harness/__nameKebabCase__/__nameKebabCase__.ts.template +39 -1
  77. package/src/utils/agent-core-constructs/files/terraform/app/agent-core/__nameKebabCase__/__nameKebabCase__.tf.template +8 -1
  78. package/src/utils/agent-core-constructs/files/terraform/app/agentcore-gateway/__nameKebabCase__/__nameKebabCase__.tf.template +57 -2
  79. package/src/utils/agent-core-constructs/files/terraform/app/agentcore-harness/__nameKebabCase__/__nameKebabCase__.tf.template +258 -24
  80. package/src/utils/agent-core-constructs/files/terraform/core/agent-core/runtime.tf.template +4 -0
  81. package/src/utils/api-constructs/api-constructs.js +11 -0
  82. package/src/utils/api-constructs/api-constructs.js.map +1 -1
  83. package/src/utils/api-constructs/files/terraform/app/apis/http/__apiNameKebabCase__/__apiNameKebabCase__.tf.template +251 -3
  84. package/src/utils/api-constructs/files/terraform/app/apis/rest/__apiNameKebabCase__/__apiNameKebabCase__.tf.template +437 -2
  85. package/src/utils/api-constructs/files/terraform/core/api/rest/rest-api/rest-api.tf.template +60 -7
  86. package/src/utils/api-constructs/open-api-metadata.d.ts +20 -3
  87. package/src/utils/api-constructs/open-api-metadata.js +64 -8
  88. package/src/utils/api-constructs/open-api-metadata.js.map +1 -1
  89. package/src/utils/api-constructs/trpc-operations-metadata.d.ts +21 -0
  90. package/src/utils/api-constructs/trpc-operations-metadata.js +55 -0
  91. package/src/utils/api-constructs/trpc-operations-metadata.js.map +1 -0
  92. package/src/utils/dcr-proxy-constructs/files/terraform/app/dcr-proxies/__nameKebabCase__/__nameKebabCase__.tf.template +4 -0
  93. package/src/utils/files/terraform/src/metrics/providers.tf.template +12 -0
  94. package/src/utils/function-constructs/files/terraform/app/lambda-functions/__nameKebabCase__/__nameKebabCase__.tf.template +4 -0
  95. package/src/utils/identity-constructs/files/cdk/core/user-identity.ts.template +33 -8
  96. package/src/utils/identity-constructs/files/terraform/core/user-identity/add-callback-url/add-callback-url.tf.template +4 -0
  97. package/src/utils/identity-constructs/files/terraform/core/user-identity/identity/identity.tf.template +51 -2
  98. package/src/utils/rdb-constructs/files/cdk/core/rdb/aurora.ts.template +18 -0
  99. package/src/utils/rdb-constructs/files/terraform/app/dbs/__nameKebabCase__/__nameKebabCase__.tf.template +15 -4
  100. package/src/utils/rdb-constructs/files/terraform/core/rdb/aurora/aurora.tf.template +2 -2
  101. package/src/utils/rdb-constructs/rdb-constructs.d.ts +12 -0
  102. package/src/utils/rdb-constructs/rdb-constructs.js +24 -3
  103. package/src/utils/rdb-constructs/rdb-constructs.js.map +1 -1
  104. package/src/utils/website-constructs/files/terraform/core/static-website/static-website.tf.template +4 -0
@@ -0,0 +1,521 @@
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
+
3
+ exports[`terraform-harness-vpc-role-and-memory-grant migration > snapshots the migrated module 1`] = `
4
+ "terraform {
5
+ required_version = ">= 1.0"
6
+
7
+ required_providers {
8
+ aws = {
9
+ source = "hashicorp/aws"
10
+ version = "6.61.0"
11
+ }
12
+ random = {
13
+ source = "hashicorp/random"
14
+ version = "3.6.3"
15
+ }
16
+ }
17
+ }
18
+
19
+ variable "model_id" {
20
+ description = "Amazon Bedrock model or inference profile used by default."
21
+ type = string
22
+ default = "global.anthropic.claude-sonnet-4-6"
23
+ }
24
+
25
+ variable "allowed_tools" {
26
+ description = "Tools the Harness may use. Defaults to none; set [\\"@builtin\\"] for every built-in tool, or name individual tools. Always sent explicitly, since the service treats an absent value as every tool."
27
+ type = list(string)
28
+ default = []
29
+ }
30
+
31
+ variable "memory" {
32
+ description = "Memory configuration for the Harness. Null leaves the service to provision managed memory with default strategies. Set exactly one field: managed_memory_configuration to tune that managed memory, agentcore_memory_configuration to use a memory resource you own, or disabled to turn memory off."
33
+ type = object({
34
+ managed_memory_configuration = optional(object({
35
+ strategies = optional(set(string))
36
+ event_expiry_duration = optional(number)
37
+ encryption_key_arn = optional(string)
38
+ }))
39
+ agentcore_memory_configuration = optional(object({
40
+ arn = string
41
+ actor_id = optional(string)
42
+ messages_count = optional(number)
43
+ }))
44
+ disabled = optional(bool, false)
45
+ })
46
+ default = null
47
+
48
+ validation {
49
+ condition = var.memory == null || length([
50
+ for configured in [
51
+ var.memory.managed_memory_configuration != null,
52
+ var.memory.agentcore_memory_configuration != null,
53
+ var.memory.disabled,
54
+ ] : configured if configured
55
+ ]) == 1
56
+ error_message = "Set exactly one of memory.managed_memory_configuration, memory.agentcore_memory_configuration or memory.disabled."
57
+ }
58
+ }
59
+
60
+ variable "environment_variables" {
61
+ description = "Environment variables available to the Harness."
62
+ type = map(string)
63
+ default = null
64
+ sensitive = true
65
+ }
66
+
67
+ variable "max_iterations" {
68
+ description = "Maximum agent loop iterations per invocation. Uses the service default when null."
69
+ type = number
70
+ default = null
71
+ }
72
+
73
+ variable "timeout_seconds" {
74
+ description = "Maximum seconds an invocation may run. Uses the service default when null."
75
+ type = number
76
+ default = null
77
+ }
78
+
79
+ variable "create_execution_role" {
80
+ description = "Create the execution role with the baseline permissions below. Set false alongside execution_role_arn to use a role you already have, which is then used as-is."
81
+ type = bool
82
+ default = true
83
+
84
+ validation {
85
+ condition = var.create_execution_role || var.execution_role_arn != null
86
+ error_message = "execution_role_arn must be set when create_execution_role is false."
87
+ }
88
+
89
+ validation {
90
+ condition = var.create_execution_role || (
91
+ var.model_resource_arns == null && length(var.additional_execution_role_policy_statements) == 0
92
+ )
93
+ error_message = "model_resource_arns and additional_execution_role_policy_statements configure the generated execution role, which is not created when create_execution_role is false. Grant those permissions on the supplied role instead."
94
+ }
95
+ }
96
+
97
+ variable "execution_role_arn" {
98
+ description = "ARN of an existing IAM role for the Harness to assume. Requires create_execution_role = false."
99
+ type = string
100
+ default = null
101
+ }
102
+
103
+ variable "model_resource_arns" {
104
+ description = "Bedrock model and inference-profile ARNs the execution role may invoke. Defaults to every foundation model plus this account's Bedrock resources in the deployment region; replace with narrower ARNs to restrict baseline model access."
105
+ type = set(string)
106
+ default = null
107
+ }
108
+
109
+ variable "additional_execution_role_policy_statements" {
110
+ description = "Additional least-privilege IAM policy statements required by configured optional capabilities (e.g. customer-owned Gateways, memory, custom browsers or code interpreters, skills, secrets). Sid and Condition are optional; null fields are omitted from the rendered policy."
111
+ type = list(object({
112
+ Sid = optional(string)
113
+ Effect = string
114
+ Action = list(string)
115
+ Resource = list(string)
116
+ Condition = optional(any)
117
+ }))
118
+ default = []
119
+ }
120
+
121
+ # VPC Configuration (optional)
122
+ variable "enable_vpc" {
123
+ description = "Run the Harness inside a VPC so it can reach private resources. Set alongside vpc_id/subnet_ids."
124
+ type = bool
125
+ default = false
126
+ }
127
+
128
+ variable "vpc_id" {
129
+ description = "VPC ID to run the Harness in. Required when enable_vpc is true."
130
+ type = string
131
+ default = null
132
+
133
+ validation {
134
+ condition = !var.enable_vpc || (var.vpc_id != null && var.subnet_ids != null)
135
+ error_message = "vpc_id and subnet_ids must be set when enable_vpc is true."
136
+ }
137
+ }
138
+
139
+ variable "subnet_ids" {
140
+ description = "Subnet IDs to run the Harness in. Required when enable_vpc is true."
141
+ type = list(string)
142
+ default = null
143
+ }
144
+
145
+ variable "tags" {
146
+ description = "Tags to apply to resources"
147
+ type = map(string)
148
+ default = {}
149
+ }
150
+
151
+ data "aws_caller_identity" "current" {}
152
+ data "aws_partition" "current" {}
153
+ data "aws_region" "current" {}
154
+
155
+ resource "random_id" "unique_suffix" {
156
+ byte_length = 4
157
+ }
158
+
159
+ locals {
160
+ account_id = data.aws_caller_identity.current.account_id
161
+ partition = data.aws_partition.current.partition
162
+ region = data.aws_region.current.region
163
+
164
+ # Capped at 31 characters so the suffix keeps the deployed Harness name
165
+ # within its 40-character limit.
166
+ harness_name_prefix = "MyHarness"
167
+ harness_name = "\${local.harness_name_prefix}_\${random_id.unique_suffix.hex}"
168
+
169
+ # Set var.model_resource_arns to narrow the default model access.
170
+ model_resource_arns = var.model_resource_arns != null ? var.model_resource_arns : [
171
+ "arn:\${local.partition}:bedrock:*::foundation-model/*",
172
+ "arn:\${local.partition}:bedrock:\${local.region}:\${local.account_id}:*",
173
+ ]
174
+
175
+ execution_role_arn = var.create_execution_role ? aws_iam_role.execution_role[0].arn : var.execution_role_arn
176
+
177
+ # The service provisions managed memory unless var.memory redirects it
178
+ # elsewhere or turns it off.
179
+ has_managed_memory = var.memory == null || var.memory.managed_memory_configuration != null
180
+ }
181
+
182
+ resource "aws_iam_role" "execution_role" {
183
+ count = var.create_execution_role ? 1 : 0
184
+
185
+ name = "\${local.harness_name_prefix}-HarnessRole-\${random_id.unique_suffix.hex}"
186
+
187
+ assume_role_policy = jsonencode({
188
+ Version = "2012-10-17"
189
+ Statement = [{
190
+ Effect = "Allow"
191
+ Principal = {
192
+ Service = "bedrock-agentcore.amazonaws.com"
193
+ }
194
+ Action = "sts:AssumeRole"
195
+ Condition = {
196
+ StringEquals = {
197
+ "aws:SourceAccount" = local.account_id
198
+ }
199
+ ArnLike = {
200
+ "aws:SourceArn" = "arn:\${local.partition}:bedrock-agentcore:\${local.region}:\${local.account_id}:*"
201
+ }
202
+ }
203
+ }]
204
+ })
205
+
206
+ tags = var.tags
207
+ }
208
+
209
+ # Baseline permissions per the AgentCore Harness security guidance; extend for
210
+ # customer-owned resources via var.additional_execution_role_policy_statements.
211
+ # https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/harness-security.html
212
+ resource "aws_iam_role_policy" "execution_role" {
213
+ count = var.create_execution_role ? 1 : 0
214
+
215
+ name = "\${local.harness_name_prefix}-HarnessPolicy"
216
+ role = aws_iam_role.execution_role[0].id
217
+
218
+ policy = jsonencode({
219
+ Version = "2012-10-17"
220
+ Statement = concat([
221
+ {
222
+ Sid = "BedrockModelInvocation"
223
+ Effect = "Allow"
224
+ Action = [
225
+ "bedrock:InvokeModel",
226
+ "bedrock:InvokeModelWithResponseStream",
227
+ ]
228
+ Resource = local.model_resource_arns
229
+ },
230
+ {
231
+ #checkov:skip=CKV_AWS_355:EcrPublicTokenAccess requires a wildcard resource; ecr-public:GetAuthorizationToken has no resource-level permission
232
+ Sid = "EcrPublicTokenAccess"
233
+ Effect = "Allow"
234
+ Action = ["ecr-public:GetAuthorizationToken"]
235
+ Resource = ["*"]
236
+ },
237
+ {
238
+ #checkov:skip=CKV_AWS_355:StsForEcrPublicPull requires a wildcard resource; sts:GetServiceBearerToken has no resource-level permission
239
+ Sid = "StsForEcrPublicPull"
240
+ Effect = "Allow"
241
+ Action = ["sts:GetServiceBearerToken"]
242
+ Resource = ["*"]
243
+ },
244
+ {
245
+ #checkov:skip=CKV_AWS_355:XRayTracingAccess requires a wildcard resource; the X-Ray segment and sampling APIs have no resource-level permission
246
+ #checkov:skip=CKV_AWS_290:XRayTracingAccess requires a wildcard resource; the X-Ray segment and sampling APIs have no resource-level permission
247
+ Sid = "XRayTracingAccess"
248
+ Effect = "Allow"
249
+ Action = [
250
+ "xray:PutTraceSegments",
251
+ "xray:PutTelemetryRecords",
252
+ "xray:GetSamplingRules",
253
+ "xray:GetSamplingTargets",
254
+ ]
255
+ Resource = ["*"]
256
+ },
257
+ {
258
+ Sid = "CloudWatchLogsGroup"
259
+ Effect = "Allow"
260
+ Action = [
261
+ "logs:CreateLogGroup",
262
+ "logs:DescribeLogStreams",
263
+ ]
264
+ Resource = [
265
+ "arn:\${local.partition}:logs:\${local.region}:\${local.account_id}:log-group:/aws/bedrock-agentcore/runtimes/*",
266
+ ]
267
+ },
268
+ {
269
+ Sid = "CloudWatchLogsDescribeGroups"
270
+ Effect = "Allow"
271
+ Action = ["logs:DescribeLogGroups"]
272
+ Resource = ["arn:\${local.partition}:logs:\${local.region}:\${local.account_id}:log-group:*"]
273
+ },
274
+ {
275
+ Sid = "CloudWatchLogsStream"
276
+ Effect = "Allow"
277
+ Action = [
278
+ "logs:CreateLogStream",
279
+ "logs:PutLogEvents",
280
+ ]
281
+ Resource = [
282
+ "arn:\${local.partition}:logs:\${local.region}:\${local.account_id}:log-group:/aws/bedrock-agentcore/runtimes/*:log-stream:*",
283
+ ]
284
+ },
285
+ {
286
+ #checkov:skip=CKV_AWS_355:CloudWatchMetricsPublish requires a wildcard resource; cloudwatch:PutMetricData is scoped by the namespace condition instead
287
+ #checkov:skip=CKV_AWS_290:CloudWatchMetricsPublish requires a wildcard resource; cloudwatch:PutMetricData is scoped by the namespace condition instead
288
+ Sid = "CloudWatchMetricsPublish"
289
+ Effect = "Allow"
290
+ Action = ["cloudwatch:PutMetricData"]
291
+ Resource = ["*"]
292
+ Condition = {
293
+ StringEquals = {
294
+ "cloudwatch:namespace" = "bedrock-agentcore"
295
+ }
296
+ }
297
+ },
298
+ {
299
+ Sid = "AgentCoreWorkloadIdentity"
300
+ Effect = "Allow"
301
+ Action = [
302
+ "bedrock-agentcore:GetWorkloadAccessToken",
303
+ "bedrock-agentcore:GetWorkloadAccessTokenForJWT",
304
+ ]
305
+ Resource = [
306
+ "arn:\${local.partition}:bedrock-agentcore:\${local.region}:\${local.account_id}:workload-identity-directory/default",
307
+ "arn:\${local.partition}:bedrock-agentcore:\${local.region}:\${local.account_id}:workload-identity-directory/default/workload-identity/harness_\${local.harness_name}-*",
308
+ ]
309
+ },
310
+ {
311
+ Sid = "AgentCoreBrowserDefault"
312
+ Effect = "Allow"
313
+ Action = [
314
+ "bedrock-agentcore:StartBrowserSession",
315
+ "bedrock-agentcore:StopBrowserSession",
316
+ "bedrock-agentcore:GetBrowserSession",
317
+ "bedrock-agentcore:ListBrowserSessions",
318
+ "bedrock-agentcore:UpdateBrowserStream",
319
+ "bedrock-agentcore:ConnectBrowserAutomationStream",
320
+ "bedrock-agentcore:ConnectBrowserLiveViewStream",
321
+ ]
322
+ Resource = [
323
+ "arn:\${local.partition}:bedrock-agentcore:\${local.region}:aws:browser/*",
324
+ ]
325
+ },
326
+ {
327
+ Sid = "AgentCoreCodeInterpreterDefault"
328
+ Effect = "Allow"
329
+ Action = [
330
+ "bedrock-agentcore:StartCodeInterpreterSession",
331
+ "bedrock-agentcore:StopCodeInterpreterSession",
332
+ "bedrock-agentcore:GetCodeInterpreterSession",
333
+ "bedrock-agentcore:ListCodeInterpreterSessions",
334
+ "bedrock-agentcore:InvokeCodeInterpreter",
335
+ ]
336
+ Resource = [
337
+ "arn:\${local.partition}:bedrock-agentcore:\${local.region}:aws:code-interpreter/*",
338
+ ]
339
+ },
340
+ ],
341
+ # In VPC mode the Harness pulls its managed container from a private ECR
342
+ # repository in the region rather than ECR Public, so it needs pull
343
+ # permissions on it. The repository is service-owned, hence the wildcard
344
+ # account.
345
+ var.enable_vpc ? [
346
+ {
347
+ Sid = "EcrManagedImagePull"
348
+ Effect = "Allow"
349
+ Action = [
350
+ "ecr:BatchGetImage",
351
+ "ecr:GetDownloadUrlForLayer",
352
+ "ecr:BatchCheckLayerAvailability",
353
+ ]
354
+ Resource = ["arn:\${local.partition}:ecr:\${local.region}:*:repository/harness-*"]
355
+ },
356
+ {
357
+ #checkov:skip=CKV_AWS_355:EcrManagedImageToken requires a wildcard resource; ecr:GetAuthorizationToken has no resource-level permission
358
+ Sid = "EcrManagedImageToken"
359
+ Effect = "Allow"
360
+ Action = ["ecr:GetAuthorizationToken"]
361
+ Resource = ["*"]
362
+ },
363
+ ] : [],
364
+ [
365
+ # Null Sid/Condition fields are dropped from the rendered policy.
366
+ for statement in var.additional_execution_role_policy_statements :
367
+ { for key, value in statement : key => value if value != null }
368
+ ])
369
+ })
370
+ }
371
+
372
+ # Security group for the Harness, used when running inside a VPC
373
+ resource "aws_security_group" "harness" {
374
+ count = var.enable_vpc ? 1 : 0
375
+
376
+ #checkov:skip=CKV2_AWS_5:Attached to the Harness via its network configuration; Checkov cannot resolve this reference
377
+ name_prefix = "\${local.harness_name_prefix}-harness-"
378
+ description = "Security group for the \${local.harness_name_prefix} Harness"
379
+ vpc_id = var.vpc_id
380
+ tags = var.tags
381
+ }
382
+
383
+ resource "aws_vpc_security_group_egress_rule" "harness_https" {
384
+ count = var.enable_vpc ? 1 : 0
385
+
386
+ security_group_id = aws_security_group.harness[0].id
387
+ cidr_ipv4 = "0.0.0.0/0"
388
+ from_port = 443
389
+ to_port = 443
390
+ ip_protocol = "tcp"
391
+ description = "Allow outbound HTTPS to AWS service endpoints"
392
+ }
393
+
394
+ # Omitting authorizer_configuration uses IAM inbound authorization; add a
395
+ # custom_jwt_authorizer block to change that.
396
+ resource "aws_bedrockagentcore_harness" "this" {
397
+ harness_name = local.harness_name
398
+ execution_role_arn = local.execution_role_arn
399
+
400
+ allowed_tools = var.allowed_tools
401
+ environment_variables = var.environment_variables
402
+ max_iterations = var.max_iterations
403
+ timeout_seconds = var.timeout_seconds
404
+
405
+ model {
406
+ bedrock_model_config {
407
+ model_id = var.model_id
408
+ }
409
+ }
410
+
411
+ # Read at plan time; the walk up from path.module reaches the workspace root.
412
+ system_prompt {
413
+ text = file("\${path.module}/../../../../../../../packages/my-harness/src/PROMPT.md")
414
+ }
415
+
416
+ dynamic "memory" {
417
+ for_each = var.memory != null ? [var.memory] : []
418
+ content {
419
+ dynamic "managed_memory_configuration" {
420
+ for_each = memory.value.managed_memory_configuration != null ? [memory.value.managed_memory_configuration] : []
421
+ content {
422
+ strategies = managed_memory_configuration.value.strategies
423
+ event_expiry_duration = managed_memory_configuration.value.event_expiry_duration
424
+ encryption_key_arn = managed_memory_configuration.value.encryption_key_arn
425
+ }
426
+ }
427
+
428
+ dynamic "agentcore_memory_configuration" {
429
+ for_each = memory.value.agentcore_memory_configuration != null ? [memory.value.agentcore_memory_configuration] : []
430
+ content {
431
+ arn = agentcore_memory_configuration.value.arn
432
+ actor_id = agentcore_memory_configuration.value.actor_id
433
+ messages_count = agentcore_memory_configuration.value.messages_count
434
+ }
435
+ }
436
+
437
+ dynamic "disabled" {
438
+ for_each = memory.value.disabled ? [1] : []
439
+ content {}
440
+ }
441
+ }
442
+ }
443
+
444
+ dynamic "environment" {
445
+ for_each = var.enable_vpc ? [1] : []
446
+ content {
447
+ agentcore_runtime_environment {
448
+ network_configuration {
449
+ network_mode = "VPC"
450
+ network_mode_config {
451
+ security_groups = [aws_security_group.harness[0].id]
452
+ subnets = var.subnet_ids
453
+ }
454
+ }
455
+ }
456
+ }
457
+ }
458
+
459
+ tags = var.tags
460
+
461
+ depends_on = [aws_iam_role_policy.execution_role]
462
+ }
463
+
464
+ # Scoped to the memory ARN the service assigns, which is only readable after the
465
+ # Harness exists, so this is a policy of its own rather than a baseline
466
+ # statement. Skipped when the Harness uses a role or memory the module did not
467
+ # create.
468
+ resource "aws_iam_role_policy" "managed_memory" {
469
+ count = var.create_execution_role && local.has_managed_memory ? 1 : 0
470
+
471
+ name = "\${local.harness_name_prefix}-HarnessManagedMemoryPolicy"
472
+ role = aws_iam_role.execution_role[0].id
473
+
474
+ policy = jsonencode({
475
+ Version = "2012-10-17"
476
+ Statement = [{
477
+ Sid = "AgentCoreManagedMemory"
478
+ Effect = "Allow"
479
+ Action = [
480
+ "bedrock-agentcore:CreateEvent",
481
+ "bedrock-agentcore:DeleteEvent",
482
+ "bedrock-agentcore:GetEvent",
483
+ "bedrock-agentcore:ListEvents",
484
+ "bedrock-agentcore:RetrieveMemoryRecords",
485
+ ]
486
+ Resource = [
487
+ aws_bedrockagentcore_harness.this.memory_actual[0].managed_memory_configuration[0].arn,
488
+ ]
489
+ }]
490
+ })
491
+ }
492
+
493
+ module "add_harness_arn_to_runtime_config" {
494
+ source = "../../../core/runtime-config/entry"
495
+
496
+ namespace = "agentcore"
497
+ key = "harnesses"
498
+ value = { "MyHarness" = aws_bedrockagentcore_harness.this.arn }
499
+ }
500
+
501
+ output "harness_id" {
502
+ description = "ID of the Amazon Bedrock AgentCore Harness"
503
+ value = aws_bedrockagentcore_harness.this.harness_id
504
+ }
505
+
506
+ output "harness_arn" {
507
+ description = "ARN of the Amazon Bedrock AgentCore Harness"
508
+ value = aws_bedrockagentcore_harness.this.arn
509
+ }
510
+
511
+ output "execution_role_arn" {
512
+ description = "ARN of the IAM role assumed by the Harness, whether generated or supplied via var.execution_role_arn"
513
+ value = local.execution_role_arn
514
+ }
515
+
516
+ output "security_group_id" {
517
+ description = "Security group ID of the Harness, for use in ingress rules on resources it must reach (e.g. a database). Null unless enable_vpc is true."
518
+ value = var.enable_vpc ? aws_security_group.harness[0].id : null
519
+ }
520
+ "
521
+ `;
@@ -0,0 +1,3 @@
1
+ {
2
+ "description": "Add VPC, execution role and native field support to the vended Terraform AgentCore Harness module, and scope its managed-memory grant to the service-assigned ARN"
3
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import { type MigrationReturnObject, type Tree } from '@nx/devkit';
6
+ export default function migration(tree: Tree): Promise<MigrationReturnObject>;