@aws/nx-plugin 0.46.0 → 0.48.0
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.
- package/package.json +1 -1
- package/src/infra/app/generator.js +4 -1
- package/src/infra/app/generator.js.map +1 -1
- package/src/mcp-server/tools/create-workspace-command.js +4 -0
- package/src/mcp-server/tools/create-workspace-command.js.map +1 -1
- package/src/mcp-server/tools/general-guidance.js +3 -1
- package/src/mcp-server/tools/general-guidance.js.map +1 -1
- package/src/preset/__snapshots__/generator.spec.ts.snap +9 -0
- package/src/preset/generator.d.ts +1 -1
- package/src/preset/generator.js +4 -1
- package/src/preset/generator.js.map +1 -1
- package/src/preset/schema.d.ts +3 -0
- package/src/preset/schema.json +9 -1
- package/src/py/fast-api/__snapshots__/generator.spec.ts.snap +60 -0
- package/src/py/fast-api/generator.js +5 -3
- package/src/py/fast-api/generator.js.map +1 -1
- package/src/py/fast-api/react/__snapshots__/generator.spec.ts.snap +1 -0
- package/src/py/fast-api/schema.d.ts +3 -1
- package/src/py/fast-api/schema.json +4 -4
- package/src/py/lambda-function/__snapshots__/generator.spec.ts.snap +310 -0
- package/src/py/lambda-function/generator.js +17 -25
- package/src/py/lambda-function/generator.js.map +1 -1
- package/src/py/lambda-function/schema.d.ts +3 -0
- package/src/py/lambda-function/schema.json +8 -0
- package/src/py/mcp-server/generator.js +4 -2
- package/src/py/mcp-server/generator.js.map +1 -1
- package/src/py/mcp-server/schema.d.ts +4 -1
- package/src/py/mcp-server/schema.json +4 -4
- package/src/py/strands-agent/generator.js +4 -2
- package/src/py/strands-agent/generator.js.map +1 -1
- package/src/py/strands-agent/schema.d.ts +3 -1
- package/src/py/strands-agent/schema.json +4 -4
- package/src/terraform/project/generator.js +2 -1
- package/src/terraform/project/generator.js.map +1 -1
- package/src/trpc/backend/__snapshots__/generator.spec.ts.snap +60 -0
- package/src/trpc/backend/generator.js +4 -2
- package/src/trpc/backend/generator.js.map +1 -1
- package/src/trpc/backend/schema.d.ts +2 -1
- package/src/trpc/backend/schema.json +4 -4
- package/src/trpc/react/__snapshots__/generator.spec.ts.snap +1 -0
- package/src/ts/lambda-function/__snapshots__/generator.spec.ts.snap +310 -0
- package/src/ts/lambda-function/generator.js +17 -27
- package/src/ts/lambda-function/generator.js.map +1 -1
- package/src/ts/lambda-function/schema.d.ts +3 -0
- package/src/ts/lambda-function/schema.json +8 -0
- package/src/ts/mcp-server/generator.js +4 -2
- package/src/ts/mcp-server/generator.js.map +1 -1
- package/src/ts/mcp-server/schema.d.ts +3 -1
- package/src/ts/mcp-server/schema.json +4 -4
- package/src/ts/nx-generator/__snapshots__/generator.spec.ts.snap +27 -1
- package/src/ts/nx-generator/files/nx-plugin-for-aws/docs/__nameKebabCase__.mdx.template +31 -0
- package/src/ts/nx-generator/files/nx-plugin-for-aws/generator/generator.spec.ts.template +1 -1
- package/src/ts/react-website/app/__snapshots__/generator.spec.ts.snap +756 -0
- package/src/ts/react-website/app/generator.js +44 -43
- package/src/ts/react-website/app/generator.js.map +1 -1
- package/src/ts/react-website/app/schema.d.ts +2 -0
- package/src/ts/react-website/app/schema.json +8 -0
- package/src/ts/react-website/cognito-auth/__snapshots__/generator.spec.ts.snap +259 -0
- package/src/ts/react-website/cognito-auth/generator.js +12 -13
- package/src/ts/react-website/cognito-auth/generator.js.map +1 -1
- package/src/ts/react-website/cognito-auth/schema.d.ts +4 -0
- package/src/ts/react-website/cognito-auth/schema.json +8 -0
- package/src/ts/react-website/runtime-config/__snapshots__/generator.spec.ts.snap +0 -40
- package/src/ts/react-website/runtime-config/generator.js +0 -2
- package/src/ts/react-website/runtime-config/generator.js.map +1 -1
- package/src/utils/agent-core-constructs/agent-core-constructs.d.ts +4 -2
- package/src/utils/agent-core-constructs/agent-core-constructs.js.map +1 -1
- package/src/utils/api-constructs/api-constructs.d.ts +2 -1
- package/src/utils/api-constructs/api-constructs.js.map +1 -1
- package/src/utils/api-constructs/files/terraform/app/apis/http/__apiNameKebabCase__/__apiNameKebabCase__.tf.template +10 -0
- package/src/utils/api-constructs/files/terraform/app/apis/rest/__apiNameKebabCase__/__apiNameKebabCase__.tf.template +10 -0
- package/src/utils/config/index.d.ts +6 -0
- package/src/utils/config/index.js.map +1 -1
- package/src/utils/files/terraform/src/core/runtime-config/entry/entry.tf.template +119 -0
- package/src/utils/files/terraform/src/core/runtime-config/read/read.tf.template +28 -0
- package/src/utils/files/terraform/src/metrics/metrics.tf.template +7 -1
- package/src/{py/lambda-function/files/common/constructs/src/app/lambda-functions/__constructFunctionKebabCase__.ts.template → utils/function-constructs/files/cdk/app/lambda-functions/__functionNameKebabCase__.ts.template} +5 -5
- package/src/utils/function-constructs/files/terraform/app/lambda-functions/__functionNameKebabCase__/__functionNameKebabCase__.tf.template +150 -0
- package/src/utils/function-constructs/function-constructs.d.ts +20 -0
- package/src/utils/function-constructs/function-constructs.js +57 -0
- package/src/utils/function-constructs/function-constructs.js.map +1 -0
- package/src/utils/iac.d.ts +21 -0
- package/src/utils/iac.js +25 -0
- package/src/utils/iac.js.map +1 -0
- package/src/utils/identity-constructs/files/terraform/core/user-identity/add-callback-url/add-callback-url.tf.template +123 -0
- package/src/utils/identity-constructs/files/terraform/core/user-identity/identity/identity.tf.template +421 -0
- package/src/utils/identity-constructs/files/terraform/core/user-identity/main.tf.template +47 -0
- package/src/utils/identity-constructs/identity-constructs.d.ts +16 -0
- package/src/utils/identity-constructs/identity-constructs.js +84 -0
- package/src/utils/identity-constructs/identity-constructs.js.map +1 -0
- package/src/utils/metrics.js +1 -1
- package/src/utils/metrics.js.map +1 -1
- package/src/utils/shared-constructs.d.ts +3 -2
- package/src/utils/shared-constructs.js +27 -3
- package/src/utils/shared-constructs.js.map +1 -1
- package/src/utils/website-constructs/files/terraform/app/static-websites/__websiteNameKebabCase__/__websiteNameKebabCase__.tf.template +42 -0
- package/src/utils/website-constructs/files/terraform/core/static-website/static-website.tf.template +709 -0
- package/src/utils/website-constructs/website-constructs.d.ts +19 -0
- package/src/utils/website-constructs/website-constructs.js +61 -0
- package/src/utils/website-constructs/website-constructs.js.map +1 -0
- package/src/ts/lambda-function/files/common/constructs/src/app/lambda-functions/__constructFunctionNameKebabCase__.ts.template +0 -24
- /package/src/{ts/react-website/cognito-auth/files/common/constructs/src → utils/identity-constructs/files/cdk}/core/user-identity.ts.template +0 -0
- /package/src/{ts/react-website/app/files/common/constructs/src → utils/website-constructs/files/cdk}/app/static-websites/__websiteNameKebabCase__.ts.template +0 -0
- /package/src/{ts/react-website/app/files/common/constructs/src → utils/website-constructs/files/cdk}/core/static-website.ts.template +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/terraform/project/generator.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/terraform/project/generator.ts"],"names":[],"mappings":";;;AAyCA,8DA8OC;;AAvRD;;;GAGG;AACH,uCAYoB;AAEpB,sDAAyD;AACzD,+BAAsC;AACtC,+CAAoD;AACpD,uCAIwB;AACxB,yCAAkD;AAClD,mDAAoD;AACpD,iDAAsE;AACtE,qEAA0E;AAC1E,uCAA4C;AAC5C,yFAGiD;AACjD,6CAA8C;AAE9C,MAAM,gBAAgB,GAAG,sBAAsB,CAAC;AACnC,QAAA,gCAAgC,GAC3C,IAAA,qBAAgB,EAAC,UAAU,CAAC,CAAC;AAE/B,SAAsB,yBAAyB,CAC7C,IAAU,EACV,MAAuC;;;QAEvC,sDAAsD;QACtD,MAAM,GAAG,GAAG,IAAA,2BAAe,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAC1C,MAAM,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,GAAG,IAAA,2BAAe,EAAC,IAAI,EAAE;YACxE,IAAI,EAAE,mDAAqB;SAC5B,CAAC,CAAC;QAEH,MAAM,wBAAwB,GAAG,IAAA,eAAQ,EACvC,IAAA,WAAI,EAAC,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CAClC,CAAA,EACD,CAAC;YACD,MAAM,CAAC,OAAO,GAAG,CAAC,GAAG,CAAC,MAAA,MAAM,CAAC,OAAO,mCAAI,EAAE,CAAC,EAAE,gBAAgB,CAAC,CAAC;YAC/D,IAAA,qBAAY,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAC7B,CAAC;QAED,qDAAqD;QACrD,MAAM,IAAA,6CAAyB,EAAC,IAAI,EAAE,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC,CAAC;QAEpE,wBAAwB;QACxB,MAAM,IAAA,yCAA+B,EAAC,IAAI,EAAE;YAC1C,wCAAgC;SACjC,CAAC,CAAC;QAEH,IAAA,qCAA4B,EAC1B,IAAI,EACJ,EAAE,EACF,IAAA,uBAAY,EAAC,CAAC,sBAAsB,EAAE,cAAc,CAAC,CAAC,CACvD,CAAC;QAEF,OAAO,GAAG,EAAE;YACV,IAAA,4BAAmB,EAAC,IAAI,CAAC,CAAC;QAC5B,CAAC,CAAC;IACJ,CAAC;CAAA;AACD,kBAAe,yBAAyB,CAAC"}
|
|
@@ -2511,6 +2511,16 @@ resource "aws_apigatewayv2_route" "proxy_routes" {
|
|
|
2511
2511
|
depends_on = [aws_apigatewayv2_integration.lambda_integration, aws_apigatewayv2_authorizer.cognito_authorizer]
|
|
2512
2512
|
}
|
|
2513
2513
|
|
|
2514
|
+
# Add API url to runtime config
|
|
2515
|
+
module "add_url_to_runtime_config" {
|
|
2516
|
+
source = "../../../core/runtime-config/entry"
|
|
2517
|
+
|
|
2518
|
+
key_path = "apis.TestApi"
|
|
2519
|
+
value = module.http_api.stage_invoke_url
|
|
2520
|
+
|
|
2521
|
+
depends_on = [module.http_api]
|
|
2522
|
+
}
|
|
2523
|
+
|
|
2514
2524
|
# Lambda permission for API Gateway to invoke the function
|
|
2515
2525
|
resource "aws_lambda_permission" "api_gateway_invoke" {
|
|
2516
2526
|
statement_id = "AllowExecutionFromAPIGateway"
|
|
@@ -3108,6 +3118,16 @@ resource "aws_apigatewayv2_route" "proxy_routes" {
|
|
|
3108
3118
|
depends_on = [aws_apigatewayv2_integration.lambda_integration]
|
|
3109
3119
|
}
|
|
3110
3120
|
|
|
3121
|
+
# Add API url to runtime config
|
|
3122
|
+
module "add_url_to_runtime_config" {
|
|
3123
|
+
source = "../../../core/runtime-config/entry"
|
|
3124
|
+
|
|
3125
|
+
key_path = "apis.TestApi"
|
|
3126
|
+
value = module.http_api.stage_invoke_url
|
|
3127
|
+
|
|
3128
|
+
depends_on = [module.http_api]
|
|
3129
|
+
}
|
|
3130
|
+
|
|
3111
3131
|
# Lambda permission for API Gateway to invoke the function
|
|
3112
3132
|
resource "aws_lambda_permission" "api_gateway_invoke" {
|
|
3113
3133
|
statement_id = "AllowExecutionFromAPIGateway"
|
|
@@ -3707,6 +3727,16 @@ resource "aws_apigatewayv2_route" "proxy_routes" {
|
|
|
3707
3727
|
depends_on = [aws_apigatewayv2_integration.lambda_integration]
|
|
3708
3728
|
}
|
|
3709
3729
|
|
|
3730
|
+
# Add API url to runtime config
|
|
3731
|
+
module "add_url_to_runtime_config" {
|
|
3732
|
+
source = "../../../core/runtime-config/entry"
|
|
3733
|
+
|
|
3734
|
+
key_path = "apis.TestApi"
|
|
3735
|
+
value = module.http_api.stage_invoke_url
|
|
3736
|
+
|
|
3737
|
+
depends_on = [module.http_api]
|
|
3738
|
+
}
|
|
3739
|
+
|
|
3710
3740
|
# Lambda permission for API Gateway to invoke the function
|
|
3711
3741
|
resource "aws_lambda_permission" "api_gateway_invoke" {
|
|
3712
3742
|
statement_id = "AllowExecutionFromAPIGateway"
|
|
@@ -4333,6 +4363,16 @@ resource "aws_lambda_permission" "api_gateway_invoke" {
|
|
|
4333
4363
|
depends_on = [module.rest_api, aws_lambda_function.api_lambda]
|
|
4334
4364
|
}
|
|
4335
4365
|
|
|
4366
|
+
# Add API url to runtime config
|
|
4367
|
+
module "add_url_to_runtime_config" {
|
|
4368
|
+
source = "../../../core/runtime-config/entry"
|
|
4369
|
+
|
|
4370
|
+
key_path = "apis.TestApi"
|
|
4371
|
+
value = aws_api_gateway_stage.api_stage.invoke_url
|
|
4372
|
+
|
|
4373
|
+
depends_on = [aws_api_gateway_stage.api_stage]
|
|
4374
|
+
}
|
|
4375
|
+
|
|
4336
4376
|
# Outputs
|
|
4337
4377
|
|
|
4338
4378
|
# API Gateway Outputs (from core module)
|
|
@@ -4951,6 +4991,16 @@ resource "aws_lambda_permission" "api_gateway_invoke" {
|
|
|
4951
4991
|
depends_on = [module.rest_api, aws_lambda_function.api_lambda]
|
|
4952
4992
|
}
|
|
4953
4993
|
|
|
4994
|
+
# Add API url to runtime config
|
|
4995
|
+
module "add_url_to_runtime_config" {
|
|
4996
|
+
source = "../../../core/runtime-config/entry"
|
|
4997
|
+
|
|
4998
|
+
key_path = "apis.TestApi"
|
|
4999
|
+
value = aws_api_gateway_stage.api_stage.invoke_url
|
|
5000
|
+
|
|
5001
|
+
depends_on = [aws_api_gateway_stage.api_stage]
|
|
5002
|
+
}
|
|
5003
|
+
|
|
4954
5004
|
# Outputs
|
|
4955
5005
|
|
|
4956
5006
|
# API Gateway Outputs (from core module)
|
|
@@ -5560,6 +5610,16 @@ resource "aws_lambda_permission" "api_gateway_invoke" {
|
|
|
5560
5610
|
depends_on = [module.rest_api, aws_lambda_function.api_lambda]
|
|
5561
5611
|
}
|
|
5562
5612
|
|
|
5613
|
+
# Add API url to runtime config
|
|
5614
|
+
module "add_url_to_runtime_config" {
|
|
5615
|
+
source = "../../../core/runtime-config/entry"
|
|
5616
|
+
|
|
5617
|
+
key_path = "apis.TestApi"
|
|
5618
|
+
value = aws_api_gateway_stage.api_stage.invoke_url
|
|
5619
|
+
|
|
5620
|
+
depends_on = [aws_api_gateway_stage.api_stage]
|
|
5621
|
+
}
|
|
5622
|
+
|
|
5563
5623
|
# Outputs
|
|
5564
5624
|
|
|
5565
5625
|
# API Gateway Outputs (from core module)
|
|
@@ -19,12 +19,14 @@ const nx_1 = require("../../utils/nx");
|
|
|
19
19
|
const metrics_1 = require("../../utils/metrics");
|
|
20
20
|
const api_constructs_1 = require("../../utils/api-constructs/api-constructs");
|
|
21
21
|
const port_1 = require("../../utils/port");
|
|
22
|
+
const iac_1 = require("../../utils/iac");
|
|
22
23
|
exports.TRPC_BACKEND_GENERATOR_INFO = (0, nx_1.getGeneratorInfo)(__filename);
|
|
23
24
|
function tsTrpcApiGenerator(tree, options) {
|
|
24
25
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
25
26
|
var _a;
|
|
27
|
+
const iacProvider = yield (0, iac_1.resolveIacProvider)(tree, options.iacProvider);
|
|
26
28
|
yield (0, shared_constructs_1.sharedConstructsGenerator)(tree, {
|
|
27
|
-
iacProvider
|
|
29
|
+
iacProvider,
|
|
28
30
|
});
|
|
29
31
|
const apiNamespace = (0, npm_scope_1.getNpmScopePrefix)(tree);
|
|
30
32
|
const apiNameKebabCase = (0, names_1.kebabCase)(options.name);
|
|
@@ -52,7 +54,7 @@ function tsTrpcApiGenerator(tree, options) {
|
|
|
52
54
|
dir: backendRoot,
|
|
53
55
|
},
|
|
54
56
|
auth: options.auth,
|
|
55
|
-
iacProvider
|
|
57
|
+
iacProvider,
|
|
56
58
|
});
|
|
57
59
|
projectConfig.metadata = Object.assign(Object.assign({}, projectConfig.metadata), { apiName: options.name, apiType: 'trpc', auth: options.auth });
|
|
58
60
|
projectConfig.targets.serve = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/trpc/backend/generator.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/trpc/backend/generator.ts"],"names":[],"mappings":";;;AAoCA,gDAqIC;;AAzKD;;;GAGG;AACH,uCASoB;AAEpB,qEAA0E;AAC1E,+EAAwD;AACxD,qDAAwE;AACxE,mDAAoD;AACpD,6CAA2D;AAC3D,+CAA0D;AAC1D,+CAAoD;A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,EAAE,CAAC;QAC3B,OAAO,yCAAyC,CAAC;IACnD,CAAC;SAAM,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QACtC,OAAO,yCAAyC,CAAC;IACnD,CAAC;IACD,OAAO,wBAAwB,CAAC;AAClC,CAAC,CAAC;AAEF,kBAAe,kBAAkB,CAAC"}
|
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
5
|
import { Linter } from '@nx/eslint';
|
|
6
|
+
import { IacProviderOption } from '../../utils/iac';
|
|
6
7
|
|
|
7
8
|
export interface TsTrpcApiGeneratorSchema {
|
|
8
9
|
name: string;
|
|
9
10
|
computeType: 'ServerlessApiGatewayRestApi' | 'ServerlessApiGatewayHttpApi';
|
|
10
11
|
auth: 'IAM' | 'Cognito' | 'None';
|
|
11
12
|
directory?: TsLibGeneratorSchema['directory'];
|
|
12
|
-
iacProvider:
|
|
13
|
+
iacProvider: IacProviderOption;
|
|
13
14
|
}
|
|
@@ -39,11 +39,11 @@
|
|
|
39
39
|
},
|
|
40
40
|
"iacProvider": {
|
|
41
41
|
"type": "string",
|
|
42
|
-
"description": "The preferred IaC provider",
|
|
43
|
-
"enum": ["CDK", "Terraform"],
|
|
42
|
+
"description": "The preferred IaC provider. By default this is inherited from your initial selection.",
|
|
43
|
+
"enum": ["Inherit", "CDK", "Terraform"],
|
|
44
44
|
"x-priority": "important",
|
|
45
|
-
"default": "
|
|
46
|
-
"x-prompt": "Which provider would you like to manage your infrastructure? (default:
|
|
45
|
+
"default": "Inherit",
|
|
46
|
+
"x-prompt": "Which provider would you like to manage your infrastructure? (default: Inherit)"
|
|
47
47
|
}
|
|
48
48
|
},
|
|
49
49
|
"required": ["name"]
|
|
@@ -221,6 +221,7 @@ exports[`trpc react generator > should modify main.tsx correctly > main.tsx 1`]
|
|
|
221
221
|
"import TestApiClientProvider from './components/TestApiClientProvider';
|
|
222
222
|
import QueryClientProvider from './components/QueryClientProvider';
|
|
223
223
|
import RuntimeConfigProvider from './components/RuntimeConfig';
|
|
224
|
+
|
|
224
225
|
import { RouterProvider } from '@tanstack/react-router';
|
|
225
226
|
|
|
226
227
|
const App = () => <RouterProvider router={router} />;
|
|
@@ -132,3 +132,313 @@ export const handler = middy()
|
|
|
132
132
|
.handler(testFunction);
|
|
133
133
|
"
|
|
134
134
|
`;
|
|
135
|
+
|
|
136
|
+
exports[`ts-lambda-function generator > terraform iacProvider > should generate terraform files for lambda function and snapshot them > terraform-lambda-files 1`] = `
|
|
137
|
+
{
|
|
138
|
+
"test-project-test-function.tf": "variable "tags" {
|
|
139
|
+
description = "Tags to apply to resources"
|
|
140
|
+
type = map(string)
|
|
141
|
+
default = {}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
variable "env" {
|
|
145
|
+
description = "Additional environment variables for the Lambda function"
|
|
146
|
+
type = map(string)
|
|
147
|
+
default = {}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
variable "additional_iam_policy_statements" {
|
|
151
|
+
description = "Additional IAM policy statements to attach to the Lambda role"
|
|
152
|
+
type = list(object({
|
|
153
|
+
Effect = string
|
|
154
|
+
Action = list(string)
|
|
155
|
+
Resource = list(string)
|
|
156
|
+
}))
|
|
157
|
+
default = []
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
data "aws_caller_identity" "current" {}
|
|
161
|
+
data "aws_region" "current" {}
|
|
162
|
+
|
|
163
|
+
locals {
|
|
164
|
+
aws_account_id = data.aws_caller_identity.current.account_id
|
|
165
|
+
aws_region = data.aws_region.current.name
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
resource "random_string" "suffix" {
|
|
169
|
+
length = 8
|
|
170
|
+
special = false
|
|
171
|
+
upper = false
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
resource "aws_iam_role" "lambda_role" {
|
|
175
|
+
name = "test-project-test-function-role-\${random_string.suffix.result}"
|
|
176
|
+
|
|
177
|
+
assume_role_policy = jsonencode({
|
|
178
|
+
Version = "2012-10-17"
|
|
179
|
+
Statement = [
|
|
180
|
+
{
|
|
181
|
+
Sid = "LambdaAssumeRolePolicy"
|
|
182
|
+
Effect = "Allow"
|
|
183
|
+
Principal = {
|
|
184
|
+
Service = "lambda.amazonaws.com"
|
|
185
|
+
}
|
|
186
|
+
Action = "sts:AssumeRole"
|
|
187
|
+
}
|
|
188
|
+
]
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
tags = var.tags
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
resource "aws_iam_policy" "lambda_policy" {
|
|
195
|
+
name = "test-project-test-function-policy-\${random_string.suffix.result}"
|
|
196
|
+
description = "Policy for test-project-test-function Lambda function"
|
|
197
|
+
|
|
198
|
+
policy = jsonencode({
|
|
199
|
+
Version = "2012-10-17"
|
|
200
|
+
Statement = concat([
|
|
201
|
+
{
|
|
202
|
+
Sid = "CloudWatchLogsAccess"
|
|
203
|
+
Effect = "Allow"
|
|
204
|
+
Action = [
|
|
205
|
+
"logs:CreateLogGroup",
|
|
206
|
+
"logs:CreateLogStream",
|
|
207
|
+
"logs:PutLogEvents"
|
|
208
|
+
]
|
|
209
|
+
Resource = [
|
|
210
|
+
"arn:aws:logs:\${local.aws_region}:\${local.aws_account_id}:log-group:/aws/lambda/test-project-test-function-\${random_string.suffix.result}:*"
|
|
211
|
+
]
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
Sid = "XRayAccess"
|
|
215
|
+
Effect = "Allow"
|
|
216
|
+
Action = [
|
|
217
|
+
"xray:PutTraceSegments",
|
|
218
|
+
"xray:PutTelemetryRecords"
|
|
219
|
+
]
|
|
220
|
+
Resource = ["*"]
|
|
221
|
+
}
|
|
222
|
+
], var.additional_iam_policy_statements)
|
|
223
|
+
})
|
|
224
|
+
|
|
225
|
+
tags = var.tags
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
# Attach the policy to the role
|
|
229
|
+
resource "aws_iam_role_policy_attachment" "lambda_policy_attachment" {
|
|
230
|
+
role = aws_iam_role.lambda_role.name
|
|
231
|
+
policy_arn = aws_iam_policy.lambda_policy.arn
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
data "archive_file" "lambda_zip" {
|
|
235
|
+
type = "zip"
|
|
236
|
+
source_dir = "\${path.module}/../../../../../../../dist/packages/test-project/bundle-test-function"
|
|
237
|
+
output_path = "\${path.module}/../../../../../../../dist/packages/common/terraform/lambda-functions/test-project-test-function/lambda.zip"
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
resource "aws_lambda_function" "lambda_function" {
|
|
241
|
+
#checkov:skip=CKV_AWS_117:Lambda function does not need to be in VPC for this use case
|
|
242
|
+
#checkov:skip=CKV_AWS_116:Dead Letter Queue not required for this simple use case
|
|
243
|
+
#checkov:skip=CKV_AWS_272:Code signing not required for this use case
|
|
244
|
+
#checkov:skip=CKV_AWS_115:Concurrent execution limit not required for this use case
|
|
245
|
+
#checkov:skip=CKV_AWS_173:Lambda environment variables encrypted by managed key
|
|
246
|
+
filename = data.archive_file.lambda_zip.output_path
|
|
247
|
+
function_name = "test-project-test-function-\${random_string.suffix.result}"
|
|
248
|
+
role = aws_iam_role.lambda_role.arn
|
|
249
|
+
handler = "index.handler"
|
|
250
|
+
source_code_hash = data.archive_file.lambda_zip.output_base64sha256
|
|
251
|
+
runtime = "nodejs22.x"
|
|
252
|
+
timeout = 30
|
|
253
|
+
|
|
254
|
+
tracing_config {
|
|
255
|
+
mode = "Active"
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
environment {
|
|
259
|
+
variables = merge({
|
|
260
|
+
AWS_CONNECTION_REUSE_ENABLED = "1"
|
|
261
|
+
}, var.env)
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
tags = var.tags
|
|
265
|
+
|
|
266
|
+
depends_on = [aws_iam_role_policy_attachment.lambda_policy_attachment]
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
output "function_name" {
|
|
270
|
+
description = "Name of the Lambda function"
|
|
271
|
+
value = aws_lambda_function.lambda_function.function_name
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
output "function_arn" {
|
|
275
|
+
description = "ARN of the Lambda function"
|
|
276
|
+
value = aws_lambda_function.lambda_function.arn
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
output "role_arn" {
|
|
280
|
+
description = "ARN of the Lambda execution role"
|
|
281
|
+
value = aws_iam_role.lambda_role.arn
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
output "role_name" {
|
|
285
|
+
description = "Name of the Lambda execution role"
|
|
286
|
+
value = aws_iam_role.lambda_role.name
|
|
287
|
+
}
|
|
288
|
+
",
|
|
289
|
+
}
|
|
290
|
+
`;
|
|
291
|
+
|
|
292
|
+
exports[`ts-lambda-function generator > terraform iacProvider > should match snapshot for terraform generated files with different configurations > terraform-lambda-snapshot-function.tf 1`] = `
|
|
293
|
+
"variable "tags" {
|
|
294
|
+
description = "Tags to apply to resources"
|
|
295
|
+
type = map(string)
|
|
296
|
+
default = {}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
variable "env" {
|
|
300
|
+
description = "Additional environment variables for the Lambda function"
|
|
301
|
+
type = map(string)
|
|
302
|
+
default = {}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
variable "additional_iam_policy_statements" {
|
|
306
|
+
description = "Additional IAM policy statements to attach to the Lambda role"
|
|
307
|
+
type = list(object({
|
|
308
|
+
Effect = string
|
|
309
|
+
Action = list(string)
|
|
310
|
+
Resource = list(string)
|
|
311
|
+
}))
|
|
312
|
+
default = []
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
data "aws_caller_identity" "current" {}
|
|
316
|
+
data "aws_region" "current" {}
|
|
317
|
+
|
|
318
|
+
locals {
|
|
319
|
+
aws_account_id = data.aws_caller_identity.current.account_id
|
|
320
|
+
aws_region = data.aws_region.current.name
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
resource "random_string" "suffix" {
|
|
324
|
+
length = 8
|
|
325
|
+
special = false
|
|
326
|
+
upper = false
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
resource "aws_iam_role" "lambda_role" {
|
|
330
|
+
name = "test-project-snapshot-function-role-\${random_string.suffix.result}"
|
|
331
|
+
|
|
332
|
+
assume_role_policy = jsonencode({
|
|
333
|
+
Version = "2012-10-17"
|
|
334
|
+
Statement = [
|
|
335
|
+
{
|
|
336
|
+
Sid = "LambdaAssumeRolePolicy"
|
|
337
|
+
Effect = "Allow"
|
|
338
|
+
Principal = {
|
|
339
|
+
Service = "lambda.amazonaws.com"
|
|
340
|
+
}
|
|
341
|
+
Action = "sts:AssumeRole"
|
|
342
|
+
}
|
|
343
|
+
]
|
|
344
|
+
})
|
|
345
|
+
|
|
346
|
+
tags = var.tags
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
resource "aws_iam_policy" "lambda_policy" {
|
|
350
|
+
name = "test-project-snapshot-function-policy-\${random_string.suffix.result}"
|
|
351
|
+
description = "Policy for test-project-snapshot-function Lambda function"
|
|
352
|
+
|
|
353
|
+
policy = jsonencode({
|
|
354
|
+
Version = "2012-10-17"
|
|
355
|
+
Statement = concat([
|
|
356
|
+
{
|
|
357
|
+
Sid = "CloudWatchLogsAccess"
|
|
358
|
+
Effect = "Allow"
|
|
359
|
+
Action = [
|
|
360
|
+
"logs:CreateLogGroup",
|
|
361
|
+
"logs:CreateLogStream",
|
|
362
|
+
"logs:PutLogEvents"
|
|
363
|
+
]
|
|
364
|
+
Resource = [
|
|
365
|
+
"arn:aws:logs:\${local.aws_region}:\${local.aws_account_id}:log-group:/aws/lambda/test-project-snapshot-function-\${random_string.suffix.result}:*"
|
|
366
|
+
]
|
|
367
|
+
},
|
|
368
|
+
{
|
|
369
|
+
Sid = "XRayAccess"
|
|
370
|
+
Effect = "Allow"
|
|
371
|
+
Action = [
|
|
372
|
+
"xray:PutTraceSegments",
|
|
373
|
+
"xray:PutTelemetryRecords"
|
|
374
|
+
]
|
|
375
|
+
Resource = ["*"]
|
|
376
|
+
}
|
|
377
|
+
], var.additional_iam_policy_statements)
|
|
378
|
+
})
|
|
379
|
+
|
|
380
|
+
tags = var.tags
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
# Attach the policy to the role
|
|
384
|
+
resource "aws_iam_role_policy_attachment" "lambda_policy_attachment" {
|
|
385
|
+
role = aws_iam_role.lambda_role.name
|
|
386
|
+
policy_arn = aws_iam_policy.lambda_policy.arn
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
data "archive_file" "lambda_zip" {
|
|
390
|
+
type = "zip"
|
|
391
|
+
source_dir = "\${path.module}/../../../../../../../dist/packages/test-project/bundle-snapshot-function"
|
|
392
|
+
output_path = "\${path.module}/../../../../../../../dist/packages/common/terraform/lambda-functions/test-project-snapshot-function/lambda.zip"
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
resource "aws_lambda_function" "lambda_function" {
|
|
396
|
+
#checkov:skip=CKV_AWS_117:Lambda function does not need to be in VPC for this use case
|
|
397
|
+
#checkov:skip=CKV_AWS_116:Dead Letter Queue not required for this simple use case
|
|
398
|
+
#checkov:skip=CKV_AWS_272:Code signing not required for this use case
|
|
399
|
+
#checkov:skip=CKV_AWS_115:Concurrent execution limit not required for this use case
|
|
400
|
+
#checkov:skip=CKV_AWS_173:Lambda environment variables encrypted by managed key
|
|
401
|
+
filename = data.archive_file.lambda_zip.output_path
|
|
402
|
+
function_name = "test-project-snapshot-function-\${random_string.suffix.result}"
|
|
403
|
+
role = aws_iam_role.lambda_role.arn
|
|
404
|
+
handler = "index.handler"
|
|
405
|
+
source_code_hash = data.archive_file.lambda_zip.output_base64sha256
|
|
406
|
+
runtime = "nodejs22.x"
|
|
407
|
+
timeout = 30
|
|
408
|
+
|
|
409
|
+
tracing_config {
|
|
410
|
+
mode = "Active"
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
environment {
|
|
414
|
+
variables = merge({
|
|
415
|
+
AWS_CONNECTION_REUSE_ENABLED = "1"
|
|
416
|
+
}, var.env)
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
tags = var.tags
|
|
420
|
+
|
|
421
|
+
depends_on = [aws_iam_role_policy_attachment.lambda_policy_attachment]
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
output "function_name" {
|
|
425
|
+
description = "Name of the Lambda function"
|
|
426
|
+
value = aws_lambda_function.lambda_function.function_name
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
output "function_arn" {
|
|
430
|
+
description = "ARN of the Lambda function"
|
|
431
|
+
value = aws_lambda_function.lambda_function.arn
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
output "role_arn" {
|
|
435
|
+
description = "ARN of the Lambda execution role"
|
|
436
|
+
value = aws_iam_role.lambda_role.arn
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
output "role_name" {
|
|
440
|
+
description = "Name of the Lambda execution role"
|
|
441
|
+
value = aws_iam_role.lambda_role.name
|
|
442
|
+
}
|
|
443
|
+
"
|
|
444
|
+
`;
|
|
@@ -8,9 +8,7 @@ const tslib_1 = require("tslib");
|
|
|
8
8
|
*/
|
|
9
9
|
const devkit_1 = require("@nx/devkit");
|
|
10
10
|
const shared_constructs_1 = require("../../utils/shared-constructs");
|
|
11
|
-
const shared_constructs_constants_1 = require("../../utils/shared-constructs-constants");
|
|
12
11
|
const names_1 = require("../../utils/names");
|
|
13
|
-
const ast_1 = require("../../utils/ast");
|
|
14
12
|
const format_1 = require("../../utils/format");
|
|
15
13
|
const object_1 = require("../../utils/object");
|
|
16
14
|
const nx_1 = require("../../utils/nx");
|
|
@@ -19,6 +17,8 @@ const versions_1 = require("../../utils/versions");
|
|
|
19
17
|
const lodash_camelcase_1 = tslib_1.__importDefault(require("lodash.camelcase"));
|
|
20
18
|
const io_1 = require("./io");
|
|
21
19
|
const esbuild_1 = require("../../utils/esbuild");
|
|
20
|
+
const function_constructs_1 = require("../../utils/function-constructs/function-constructs");
|
|
21
|
+
const iac_1 = require("../../utils/iac");
|
|
22
22
|
exports.TS_LAMBDA_FUNCTION_GENERATOR_INFO = (0, nx_1.getGeneratorInfo)(__filename);
|
|
23
23
|
/**
|
|
24
24
|
* Generates a TypeScript Lambda Function to add to a TypeScript project
|
|
@@ -48,16 +48,24 @@ const tsLambdaFunctionGenerator = (tree, schema) => tslib_1.__awaiter(void 0, vo
|
|
|
48
48
|
if (tree.exists(functionPath)) {
|
|
49
49
|
throw new Error(`This project already has a lambda function with the name ${functionNameKebabCase}. Please remove the lambda function before running this generator or use a different name.`);
|
|
50
50
|
}
|
|
51
|
-
yield (0,
|
|
51
|
+
const iacProvider = yield (0, iac_1.resolveIacProvider)(tree, schema.iacProvider);
|
|
52
|
+
yield (0, shared_constructs_1.sharedConstructsGenerator)(tree, {
|
|
53
|
+
iacProvider,
|
|
54
|
+
});
|
|
52
55
|
// Add bundle-<name> target for this specific lambda function
|
|
53
56
|
const bundleTargetName = `bundle-${lambdaFunctionKebabCase}`;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
(0, function_constructs_1.addLambdaFunctionInfra)(tree, {
|
|
58
|
+
functionProjectName: projectConfig.name,
|
|
59
|
+
functionNameClassName: constructFunctionClassName,
|
|
60
|
+
functionNameKebabCase: constructFunctionNameKebabCase,
|
|
61
|
+
handler: 'index.handler',
|
|
62
|
+
runtime: 'node',
|
|
63
|
+
bundlePathFromRoot: (0, devkit_1.joinPathFragments)('dist', dir, bundleTargetName),
|
|
64
|
+
iacProvider,
|
|
65
|
+
});
|
|
66
|
+
const enhancedOptions = Object.assign(Object.assign({}, schema), { lambdaFunctionCamelCase,
|
|
58
67
|
lambdaFunctionClassName,
|
|
59
|
-
lambdaFunctionKebabCase,
|
|
60
|
-
bundleTargetName, returnType: io_1.TS_HANDLER_RETURN_TYPES[schema.eventSource] });
|
|
68
|
+
lambdaFunctionKebabCase, returnType: io_1.TS_HANDLER_RETURN_TYPES[schema.eventSource] });
|
|
61
69
|
// Add a bundle target for the function
|
|
62
70
|
(0, esbuild_1.addEsbuildBundleTarget)(projectConfig, {
|
|
63
71
|
bundleTargetName,
|
|
@@ -68,24 +76,6 @@ const tsLambdaFunctionGenerator = (tree, schema) => tslib_1.__awaiter(void 0, vo
|
|
|
68
76
|
(0, devkit_1.updateProjectConfiguration)(tree, projectConfig.name, projectConfig);
|
|
69
77
|
// Generate the lambda handler file
|
|
70
78
|
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files', 'handler'), (0, devkit_1.joinPathFragments)(projectConfig.sourceRoot, (_b = schema.functionPath) !== null && _b !== void 0 ? _b : ''), enhancedOptions, { overwriteStrategy: devkit_1.OverwriteStrategy.KeepExisting });
|
|
71
|
-
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files', shared_constructs_constants_1.SHARED_CONSTRUCTS_DIR, 'src', 'app'), (0, devkit_1.joinPathFragments)(shared_constructs_constants_1.PACKAGES_DIR, shared_constructs_constants_1.SHARED_CONSTRUCTS_DIR, 'src', 'app'), enhancedOptions, { overwriteStrategy: devkit_1.OverwriteStrategy.KeepExisting });
|
|
72
|
-
(0, ast_1.addStarExport)(tree, (0, devkit_1.joinPathFragments)(shared_constructs_constants_1.PACKAGES_DIR, shared_constructs_constants_1.SHARED_CONSTRUCTS_DIR, 'src', 'app', 'index.ts'), './lambda-functions/index.js');
|
|
73
|
-
(0, ast_1.addStarExport)(tree, (0, devkit_1.joinPathFragments)(shared_constructs_constants_1.PACKAGES_DIR, shared_constructs_constants_1.SHARED_CONSTRUCTS_DIR, 'src', 'app', 'lambda-functions', 'index.ts'), `./${constructFunctionNameKebabCase}.js`);
|
|
74
|
-
// Ensure common constructs builds after our lambda function project
|
|
75
|
-
(0, devkit_1.updateJson)(tree, (0, devkit_1.joinPathFragments)(shared_constructs_constants_1.PACKAGES_DIR, shared_constructs_constants_1.SHARED_CONSTRUCTS_DIR, 'project.json'), (config) => {
|
|
76
|
-
var _a;
|
|
77
|
-
if (!config.targets) {
|
|
78
|
-
config.targets = {};
|
|
79
|
-
}
|
|
80
|
-
if (!config.targets.build) {
|
|
81
|
-
config.targets.build = {};
|
|
82
|
-
}
|
|
83
|
-
config.targets.build.dependsOn = [
|
|
84
|
-
...((_a = config.targets.build.dependsOn) !== null && _a !== void 0 ? _a : []).filter((t) => t !== `${projectConfig.name}:build`),
|
|
85
|
-
`${projectConfig.name}:build`,
|
|
86
|
-
];
|
|
87
|
-
return config;
|
|
88
|
-
});
|
|
89
79
|
(0, devkit_1.addDependenciesToPackageJson)(tree, (0, versions_1.withVersions)([
|
|
90
80
|
'@aws-lambda-powertools/tracer',
|
|
91
81
|
'@aws-lambda-powertools/logger',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/ts/lambda-function/generator.ts"],"names":[],"mappings":";;;;AAAA;;;GAGG;AACH,
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/ts/lambda-function/generator.ts"],"names":[],"mappings":";;;;AAAA;;;GAGG;AACH,uCASoB;AAEpB,qEAA0E;AAC1E,6CAAyE;AACzE,+CAA0D;AAC1D,+CAAoD;AACpD,uCAIwB;AACxB,iDAAsE;AACtE,mDAAoD;AACpD,gFAAyC;AACzC,6BAA+C;AAC/C,iDAA6D;AAC7D,6FAA6F;AAC7F,yCAAqD;AAExC,QAAA,iCAAiC,GAC5C,IAAA,qBAAgB,EAAC,UAAU,CAAC,CAAC;AAE/B;;GAEG;AACI,MAAM,yBAAyB,GAAG,CACvC,IAAU,EACV,MAAuC,EACX,EAAE;;IAC9B,MAAM,aAAa,GAAG,IAAA,wCAAmC,EACvD,IAAI,EACJ,MAAM,CAAC,OAAO,CACf,CAAC;IAEF,MAAM,YAAY,GAAG,IAAA,0BAAiB,EAAC,aAAa,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC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,YAAY,EAAE,CACtD,CAAC;IAEF,IAAA,qCAA4B,EAC1B,IAAI,EACJ,IAAA,uBAAY,EAAC;QACX,+BAA+B;QAC/B,+BAA+B;QAC/B,gCAAgC;QAChC,+BAA+B;QAC/B,aAAa;QACb,KAAK;KACN,CAAC,EACF,IAAA,uBAAY,EAAC,CAAC,SAAS,EAAE,mBAAmB,CAAC,CAAC,CAC/C,CAAC;IAEF,MAAM,IAAA,yCAA+B,EAAC,IAAI,EAAE;QAC1C,yCAAiC;KAClC,CAAC,CAAC;IAEH,MAAM,IAAA,6BAAoB,EAAC,IAAI,CAAC,CAAC;IAEjC,OAAO,GAAG,EAAE;QACV,IAAA,4BAAmB,EAAC,IAAI,CAAC,CAAC;IAC5B,CAAC,CAAC;AACJ,CAAC,CAAA,CAAC;AAtHW,QAAA,yBAAyB,6BAsHpC;AAEF,kBAAe,iCAAyB,CAAC"}
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import { IacProviderOption } from '../../utils/iac';
|
|
7
|
+
|
|
6
8
|
export type EventSource =
|
|
7
9
|
| 'Any'
|
|
8
10
|
| 'AlbSchema'
|
|
@@ -52,4 +54,5 @@ export interface TsLambdaFunctionGeneratorSchema {
|
|
|
52
54
|
readonly functionName: string;
|
|
53
55
|
readonly functionPath?: string;
|
|
54
56
|
readonly eventSource?: EventSource;
|
|
57
|
+
readonly iacProvider: IacProviderOption;
|
|
55
58
|
}
|
|
@@ -76,6 +76,14 @@
|
|
|
76
76
|
],
|
|
77
77
|
"default": "Any",
|
|
78
78
|
"x-prompt": "Enter the event source schema to use for the lambda function"
|
|
79
|
+
},
|
|
80
|
+
"iacProvider": {
|
|
81
|
+
"type": "string",
|
|
82
|
+
"description": "The preferred IaC provider. By default this is inherited from your initial selection.",
|
|
83
|
+
"enum": ["Inherit", "CDK", "Terraform"],
|
|
84
|
+
"x-priority": "important",
|
|
85
|
+
"default": "Inherit",
|
|
86
|
+
"x-prompt": "Which provider would you like to manage your infrastructure? (default: Inherit)"
|
|
79
87
|
}
|
|
80
88
|
},
|
|
81
89
|
"required": ["project", "functionName"]
|