@aws/nx-plugin 1.0.0-rc.31 → 1.0.0-rc.32

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.
@@ -689,6 +689,30 @@ variable "asset_bucket_name" {
689
689
  type = string
690
690
  }
691
691
 
692
+ # VPC Configuration (optional)
693
+ variable "enable_vpc" {
694
+ description = "Deploy the Lambda function into a VPC. Set alongside vpc_id/subnet_ids."
695
+ type = bool
696
+ default = false
697
+ }
698
+
699
+ variable "vpc_id" {
700
+ description = "VPC ID to deploy the Lambda function into. Required when enable_vpc is true."
701
+ type = string
702
+ default = null
703
+
704
+ validation {
705
+ condition = !var.enable_vpc || (var.vpc_id != null && var.subnet_ids != null)
706
+ error_message = "vpc_id and subnet_ids must be set when enable_vpc is true."
707
+ }
708
+ }
709
+
710
+ variable "subnet_ids" {
711
+ description = "Subnet IDs to deploy the Lambda function into. Required when enable_vpc is true."
712
+ type = list(string)
713
+ default = null
714
+ }
715
+
692
716
  # CORS Configuration (passed to core module)
693
717
 
694
718
  variable "cors_allow_headers" {
@@ -785,9 +809,31 @@ resource "aws_wafv2_web_acl_association" "api_waf_association" {
785
809
  depends_on = [aws_api_gateway_stage.api_stage]
786
810
  }
787
811
 
812
+ # Security group for the API Lambda function, used when deployed into a VPC
813
+ resource "aws_security_group" "api_lambda" {
814
+ count = var.enable_vpc ? 1 : 0
815
+
816
+ #checkov:skip=CKV2_AWS_5:Attached to api_lambda via vpc_config block; Checkov cannot resolve this reference
817
+ name_prefix = "test-api-lambda-"
818
+ description = "Security group for the TestApi API Lambda function"
819
+ vpc_id = var.vpc_id
820
+ tags = var.tags
821
+ }
822
+
823
+ resource "aws_vpc_security_group_egress_rule" "api_lambda_https" {
824
+ count = var.enable_vpc ? 1 : 0
825
+
826
+ security_group_id = aws_security_group.api_lambda[0].id
827
+ cidr_ipv4 = "0.0.0.0/0"
828
+ from_port = 443
829
+ to_port = 443
830
+ ip_protocol = "tcp"
831
+ description = "Allow outbound HTTPS to AWS service endpoints"
832
+ }
833
+
788
834
  # Lambda function
789
835
  resource "aws_lambda_function" "api_lambda" {
790
- #checkov:skip=CKV_AWS_117:Lambda function does not need to be in VPC for this use case
836
+ #checkov:skip=CKV_AWS_117:Lambda function is optionally deployed into a VPC via vpc_id/subnet_ids; not required for this use case
791
837
  #checkov:skip=CKV_AWS_116:Dead Letter Queue not required for this simple API use case
792
838
  #checkov:skip=CKV_AWS_272:Code signing not required for this use case
793
839
  #checkov:skip=CKV_AWS_115:Concurrent execution limit not required for this use case
@@ -809,6 +855,14 @@ resource "aws_lambda_function" "api_lambda" {
809
855
  mode = "Active"
810
856
  }
811
857
 
858
+ dynamic "vpc_config" {
859
+ for_each = var.enable_vpc ? [1] : []
860
+ content {
861
+ subnet_ids = var.subnet_ids
862
+ security_group_ids = [aws_security_group.api_lambda[0].id]
863
+ }
864
+ }
865
+
812
866
 
813
867
  environment {
814
868
  variables = merge({
@@ -816,6 +870,8 @@ resource "aws_lambda_function" "api_lambda" {
816
870
  }
817
871
 
818
872
  tags = var.tags
873
+
874
+ depends_on = [aws_iam_role_policy_attachment.lambda_vpc_access]
819
875
  }
820
876
 
821
877
  # IAM role for Lambda execution
@@ -850,6 +906,13 @@ resource "aws_iam_role_policy_attachment" "lambda_xray_execution" {
850
906
  role = aws_iam_role.lambda_execution_role.name
851
907
  }
852
908
 
909
+ # Attach VPC access policy to Lambda role when deployed into a VPC
910
+ resource "aws_iam_role_policy_attachment" "lambda_vpc_access" {
911
+ count = var.enable_vpc ? 1 : 0
912
+ policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole"
913
+ role = aws_iam_role.lambda_execution_role.name
914
+ }
915
+
853
916
  # Additional IAM policies for Lambda (if provided)
854
917
  resource "aws_iam_role_policy" "lambda_additional_policies" {
855
918
  count = length(var.additional_iam_policy_statements) > 0 ? 1 : 0
@@ -1316,6 +1379,11 @@ output "lambda_execution_role_name" {
1316
1379
  value = aws_iam_role.lambda_execution_role.name
1317
1380
  }
1318
1381
 
1382
+ output "security_group_id" {
1383
+ description = "Security group ID of the API Lambda function, for use in ingress rules on resources it must reach (e.g. a database). Null unless enable_vpc is true."
1384
+ value = var.enable_vpc ? aws_security_group.api_lambda[0].id : null
1385
+ }
1386
+
1319
1387
  # Integration Outputs
1320
1388
  output "integration_id" {
1321
1389
  description = "ID of the Lambda integration"
@@ -2052,6 +2120,30 @@ variable "asset_bucket_name" {
2052
2120
  type = string
2053
2121
  }
2054
2122
 
2123
+ # VPC Configuration (optional)
2124
+ variable "enable_vpc" {
2125
+ description = "Deploy the Lambda function into a VPC. Set alongside vpc_id/subnet_ids."
2126
+ type = bool
2127
+ default = false
2128
+ }
2129
+
2130
+ variable "vpc_id" {
2131
+ description = "VPC ID to deploy the Lambda function into. Required when enable_vpc is true."
2132
+ type = string
2133
+ default = null
2134
+
2135
+ validation {
2136
+ condition = !var.enable_vpc || (var.vpc_id != null && var.subnet_ids != null)
2137
+ error_message = "vpc_id and subnet_ids must be set when enable_vpc is true."
2138
+ }
2139
+ }
2140
+
2141
+ variable "subnet_ids" {
2142
+ description = "Subnet IDs to deploy the Lambda function into. Required when enable_vpc is true."
2143
+ type = list(string)
2144
+ default = null
2145
+ }
2146
+
2055
2147
  # CORS Configuration (passed to core module)
2056
2148
 
2057
2149
  variable "cors_allow_headers" {
@@ -2148,9 +2240,31 @@ resource "aws_wafv2_web_acl_association" "api_waf_association" {
2148
2240
  depends_on = [aws_api_gateway_stage.api_stage]
2149
2241
  }
2150
2242
 
2243
+ # Security group for the API Lambda function, used when deployed into a VPC
2244
+ resource "aws_security_group" "api_lambda" {
2245
+ count = var.enable_vpc ? 1 : 0
2246
+
2247
+ #checkov:skip=CKV2_AWS_5:Attached to api_lambda via vpc_config block; Checkov cannot resolve this reference
2248
+ name_prefix = "test-api-lambda-"
2249
+ description = "Security group for the TestApi API Lambda function"
2250
+ vpc_id = var.vpc_id
2251
+ tags = var.tags
2252
+ }
2253
+
2254
+ resource "aws_vpc_security_group_egress_rule" "api_lambda_https" {
2255
+ count = var.enable_vpc ? 1 : 0
2256
+
2257
+ security_group_id = aws_security_group.api_lambda[0].id
2258
+ cidr_ipv4 = "0.0.0.0/0"
2259
+ from_port = 443
2260
+ to_port = 443
2261
+ ip_protocol = "tcp"
2262
+ description = "Allow outbound HTTPS to AWS service endpoints"
2263
+ }
2264
+
2151
2265
  # Lambda function
2152
2266
  resource "aws_lambda_function" "api_lambda" {
2153
- #checkov:skip=CKV_AWS_117:Lambda function does not need to be in VPC for this use case
2267
+ #checkov:skip=CKV_AWS_117:Lambda function is optionally deployed into a VPC via vpc_id/subnet_ids; not required for this use case
2154
2268
  #checkov:skip=CKV_AWS_116:Dead Letter Queue not required for this simple API use case
2155
2269
  #checkov:skip=CKV_AWS_272:Code signing not required for this use case
2156
2270
  #checkov:skip=CKV_AWS_115:Concurrent execution limit not required for this use case
@@ -2172,6 +2286,14 @@ resource "aws_lambda_function" "api_lambda" {
2172
2286
  mode = "Active"
2173
2287
  }
2174
2288
 
2289
+ dynamic "vpc_config" {
2290
+ for_each = var.enable_vpc ? [1] : []
2291
+ content {
2292
+ subnet_ids = var.subnet_ids
2293
+ security_group_ids = [aws_security_group.api_lambda[0].id]
2294
+ }
2295
+ }
2296
+
2175
2297
 
2176
2298
  environment {
2177
2299
  variables = merge({
@@ -2179,6 +2301,8 @@ resource "aws_lambda_function" "api_lambda" {
2179
2301
  }
2180
2302
 
2181
2303
  tags = var.tags
2304
+
2305
+ depends_on = [aws_iam_role_policy_attachment.lambda_vpc_access]
2182
2306
  }
2183
2307
 
2184
2308
  # IAM role for Lambda execution
@@ -2213,6 +2337,13 @@ resource "aws_iam_role_policy_attachment" "lambda_xray_execution" {
2213
2337
  role = aws_iam_role.lambda_execution_role.name
2214
2338
  }
2215
2339
 
2340
+ # Attach VPC access policy to Lambda role when deployed into a VPC
2341
+ resource "aws_iam_role_policy_attachment" "lambda_vpc_access" {
2342
+ count = var.enable_vpc ? 1 : 0
2343
+ policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole"
2344
+ role = aws_iam_role.lambda_execution_role.name
2345
+ }
2346
+
2216
2347
  # Additional IAM policies for Lambda (if provided)
2217
2348
  resource "aws_iam_role_policy" "lambda_additional_policies" {
2218
2349
  count = length(var.additional_iam_policy_statements) > 0 ? 1 : 0
@@ -2597,6 +2728,11 @@ output "lambda_execution_role_name" {
2597
2728
  value = aws_iam_role.lambda_execution_role.name
2598
2729
  }
2599
2730
 
2731
+ output "security_group_id" {
2732
+ description = "Security group ID of the API Lambda function, for use in ingress rules on resources it must reach (e.g. a database). Null unless enable_vpc is true."
2733
+ value = var.enable_vpc ? aws_security_group.api_lambda[0].id : null
2734
+ }
2735
+
2600
2736
  # Integration Outputs
2601
2737
  output "integration_id" {
2602
2738
  description = "ID of the Lambda integration"
@@ -2921,6 +3057,30 @@ variable "asset_bucket_name" {
2921
3057
  type = string
2922
3058
  }
2923
3059
 
3060
+ # VPC Configuration (optional)
3061
+ variable "enable_vpc" {
3062
+ description = "Deploy the Lambda function into a VPC. Set alongside vpc_id/subnet_ids."
3063
+ type = bool
3064
+ default = false
3065
+ }
3066
+
3067
+ variable "vpc_id" {
3068
+ description = "VPC ID to deploy the Lambda function into. Required when enable_vpc is true."
3069
+ type = string
3070
+ default = null
3071
+
3072
+ validation {
3073
+ condition = !var.enable_vpc || (var.vpc_id != null && var.subnet_ids != null)
3074
+ error_message = "vpc_id and subnet_ids must be set when enable_vpc is true."
3075
+ }
3076
+ }
3077
+
3078
+ variable "subnet_ids" {
3079
+ description = "Subnet IDs to deploy the Lambda function into. Required when enable_vpc is true."
3080
+ type = list(string)
3081
+ default = null
3082
+ }
3083
+
2924
3084
  # CORS Configuration (passed to core module)
2925
3085
 
2926
3086
  variable "cors_allow_headers" {
@@ -3017,9 +3177,31 @@ resource "aws_wafv2_web_acl_association" "api_waf_association" {
3017
3177
  depends_on = [aws_api_gateway_stage.api_stage]
3018
3178
  }
3019
3179
 
3180
+ # Security group for the API Lambda function, used when deployed into a VPC
3181
+ resource "aws_security_group" "api_lambda" {
3182
+ count = var.enable_vpc ? 1 : 0
3183
+
3184
+ #checkov:skip=CKV2_AWS_5:Attached to api_lambda via vpc_config block; Checkov cannot resolve this reference
3185
+ name_prefix = "test-api-lambda-"
3186
+ description = "Security group for the TestApi API Lambda function"
3187
+ vpc_id = var.vpc_id
3188
+ tags = var.tags
3189
+ }
3190
+
3191
+ resource "aws_vpc_security_group_egress_rule" "api_lambda_https" {
3192
+ count = var.enable_vpc ? 1 : 0
3193
+
3194
+ security_group_id = aws_security_group.api_lambda[0].id
3195
+ cidr_ipv4 = "0.0.0.0/0"
3196
+ from_port = 443
3197
+ to_port = 443
3198
+ ip_protocol = "tcp"
3199
+ description = "Allow outbound HTTPS to AWS service endpoints"
3200
+ }
3201
+
3020
3202
  # Lambda function
3021
3203
  resource "aws_lambda_function" "api_lambda" {
3022
- #checkov:skip=CKV_AWS_117:Lambda function does not need to be in VPC for this use case
3204
+ #checkov:skip=CKV_AWS_117:Lambda function is optionally deployed into a VPC via vpc_id/subnet_ids; not required for this use case
3023
3205
  #checkov:skip=CKV_AWS_116:Dead Letter Queue not required for this simple API use case
3024
3206
  #checkov:skip=CKV_AWS_272:Code signing not required for this use case
3025
3207
  #checkov:skip=CKV_AWS_115:Concurrent execution limit not required for this use case
@@ -3041,6 +3223,14 @@ resource "aws_lambda_function" "api_lambda" {
3041
3223
  mode = "Active"
3042
3224
  }
3043
3225
 
3226
+ dynamic "vpc_config" {
3227
+ for_each = var.enable_vpc ? [1] : []
3228
+ content {
3229
+ subnet_ids = var.subnet_ids
3230
+ security_group_ids = [aws_security_group.api_lambda[0].id]
3231
+ }
3232
+ }
3233
+
3044
3234
 
3045
3235
  environment {
3046
3236
  variables = merge({
@@ -3048,6 +3238,8 @@ resource "aws_lambda_function" "api_lambda" {
3048
3238
  }
3049
3239
 
3050
3240
  tags = var.tags
3241
+
3242
+ depends_on = [aws_iam_role_policy_attachment.lambda_vpc_access]
3051
3243
  }
3052
3244
 
3053
3245
  # IAM role for Lambda execution
@@ -3082,6 +3274,13 @@ resource "aws_iam_role_policy_attachment" "lambda_xray_execution" {
3082
3274
  role = aws_iam_role.lambda_execution_role.name
3083
3275
  }
3084
3276
 
3277
+ # Attach VPC access policy to Lambda role when deployed into a VPC
3278
+ resource "aws_iam_role_policy_attachment" "lambda_vpc_access" {
3279
+ count = var.enable_vpc ? 1 : 0
3280
+ policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole"
3281
+ role = aws_iam_role.lambda_execution_role.name
3282
+ }
3283
+
3085
3284
  # Additional IAM policies for Lambda (if provided)
3086
3285
  resource "aws_iam_role_policy" "lambda_additional_policies" {
3087
3286
  count = length(var.additional_iam_policy_statements) > 0 ? 1 : 0
@@ -3465,6 +3664,11 @@ output "lambda_execution_role_name" {
3465
3664
  value = aws_iam_role.lambda_execution_role.name
3466
3665
  }
3467
3666
 
3667
+ output "security_group_id" {
3668
+ description = "Security group ID of the API Lambda function, for use in ingress rules on resources it must reach (e.g. a database). Null unless enable_vpc is true."
3669
+ value = var.enable_vpc ? aws_security_group.api_lambda[0].id : null
3670
+ }
3671
+
3468
3672
  # Integration Outputs
3469
3673
  output "integration_id" {
3470
3674
  description = "ID of the Lambda integration"
@@ -3529,6 +3733,30 @@ variable "asset_bucket_name" {
3529
3733
  type = string
3530
3734
  }
3531
3735
 
3736
+ # VPC Configuration (optional)
3737
+ variable "enable_vpc" {
3738
+ description = "Deploy the Lambda function into a VPC. Set alongside vpc_id/subnet_ids."
3739
+ type = bool
3740
+ default = false
3741
+ }
3742
+
3743
+ variable "vpc_id" {
3744
+ description = "VPC ID to deploy the Lambda function into. Required when enable_vpc is true."
3745
+ type = string
3746
+ default = null
3747
+
3748
+ validation {
3749
+ condition = !var.enable_vpc || (var.vpc_id != null && var.subnet_ids != null)
3750
+ error_message = "vpc_id and subnet_ids must be set when enable_vpc is true."
3751
+ }
3752
+ }
3753
+
3754
+ variable "subnet_ids" {
3755
+ description = "Subnet IDs to deploy the Lambda function into. Required when enable_vpc is true."
3756
+ type = list(string)
3757
+ default = null
3758
+ }
3759
+
3532
3760
  # CORS Configuration (passed to core module)
3533
3761
 
3534
3762
  variable "cors_allow_headers" {
@@ -3625,9 +3853,31 @@ resource "aws_wafv2_web_acl_association" "api_waf_association" {
3625
3853
  depends_on = [aws_api_gateway_stage.api_stage]
3626
3854
  }
3627
3855
 
3856
+ # Security group for the API Lambda function, used when deployed into a VPC
3857
+ resource "aws_security_group" "api_lambda" {
3858
+ count = var.enable_vpc ? 1 : 0
3859
+
3860
+ #checkov:skip=CKV2_AWS_5:Attached to api_lambda via vpc_config block; Checkov cannot resolve this reference
3861
+ name_prefix = "custom-api-lambda-"
3862
+ description = "Security group for the CustomApi API Lambda function"
3863
+ vpc_id = var.vpc_id
3864
+ tags = var.tags
3865
+ }
3866
+
3867
+ resource "aws_vpc_security_group_egress_rule" "api_lambda_https" {
3868
+ count = var.enable_vpc ? 1 : 0
3869
+
3870
+ security_group_id = aws_security_group.api_lambda[0].id
3871
+ cidr_ipv4 = "0.0.0.0/0"
3872
+ from_port = 443
3873
+ to_port = 443
3874
+ ip_protocol = "tcp"
3875
+ description = "Allow outbound HTTPS to AWS service endpoints"
3876
+ }
3877
+
3628
3878
  # Lambda function
3629
3879
  resource "aws_lambda_function" "api_lambda" {
3630
- #checkov:skip=CKV_AWS_117:Lambda function does not need to be in VPC for this use case
3880
+ #checkov:skip=CKV_AWS_117:Lambda function is optionally deployed into a VPC via vpc_id/subnet_ids; not required for this use case
3631
3881
  #checkov:skip=CKV_AWS_116:Dead Letter Queue not required for this simple API use case
3632
3882
  #checkov:skip=CKV_AWS_272:Code signing not required for this use case
3633
3883
  #checkov:skip=CKV_AWS_115:Concurrent execution limit not required for this use case
@@ -3649,6 +3899,14 @@ resource "aws_lambda_function" "api_lambda" {
3649
3899
  mode = "Active"
3650
3900
  }
3651
3901
 
3902
+ dynamic "vpc_config" {
3903
+ for_each = var.enable_vpc ? [1] : []
3904
+ content {
3905
+ subnet_ids = var.subnet_ids
3906
+ security_group_ids = [aws_security_group.api_lambda[0].id]
3907
+ }
3908
+ }
3909
+
3652
3910
 
3653
3911
  environment {
3654
3912
  variables = merge({
@@ -3656,6 +3914,8 @@ resource "aws_lambda_function" "api_lambda" {
3656
3914
  }
3657
3915
 
3658
3916
  tags = var.tags
3917
+
3918
+ depends_on = [aws_iam_role_policy_attachment.lambda_vpc_access]
3659
3919
  }
3660
3920
 
3661
3921
  # IAM role for Lambda execution
@@ -3690,6 +3950,13 @@ resource "aws_iam_role_policy_attachment" "lambda_xray_execution" {
3690
3950
  role = aws_iam_role.lambda_execution_role.name
3691
3951
  }
3692
3952
 
3953
+ # Attach VPC access policy to Lambda role when deployed into a VPC
3954
+ resource "aws_iam_role_policy_attachment" "lambda_vpc_access" {
3955
+ count = var.enable_vpc ? 1 : 0
3956
+ policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole"
3957
+ role = aws_iam_role.lambda_execution_role.name
3958
+ }
3959
+
3693
3960
  # Additional IAM policies for Lambda (if provided)
3694
3961
  resource "aws_iam_role_policy" "lambda_additional_policies" {
3695
3962
  count = length(var.additional_iam_policy_statements) > 0 ? 1 : 0
@@ -4156,6 +4423,11 @@ output "lambda_execution_role_name" {
4156
4423
  value = aws_iam_role.lambda_execution_role.name
4157
4424
  }
4158
4425
 
4426
+ output "security_group_id" {
4427
+ description = "Security group ID of the API Lambda function, for use in ingress rules on resources it must reach (e.g. a database). Null unless enable_vpc is true."
4428
+ value = var.enable_vpc ? aws_security_group.api_lambda[0].id : null
4429
+ }
4430
+
4159
4431
  # Integration Outputs
4160
4432
  output "integration_id" {
4161
4433
  description = "ID of the Lambda integration"