@aws/nx-plugin 1.0.0-rc.34 → 1.0.0-rc.35

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws/nx-plugin",
3
- "version": "1.0.0-rc.34",
3
+ "version": "1.0.0-rc.35",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/awslabs/nx-plugin-for-aws.git",
@@ -290,6 +290,18 @@ variable "additional_iam_policy_statements" {
290
290
  default = []
291
291
  }
292
292
 
293
+ variable "appconfig_application_id" {
294
+ description = "ID of the shared runtime-config AppConfig application (from \`core/runtime-config/appconfig.application_id\`). When set, the Lambda functions receive \`RUNTIME_CONFIG_APP_ID\` and read access to the application."
295
+ type = string
296
+ default = null
297
+ }
298
+
299
+ variable "appconfig_application_arn" {
300
+ description = "ARN of the shared runtime-config AppConfig application (from \`core/runtime-config/appconfig.application_arn\`). Used to scope the IAM read permission granted to the Lambda functions."
301
+ type = string
302
+ default = null
303
+ }
304
+
293
305
  variable "asset_bucket_name" {
294
306
  description = "Name of the shared asset S3 bucket used to stage the Lambda deployment zip. Instantiate the \`core/asset-bucket\` module once per deployment and pass its \`bucket_name\` output here."
295
307
  type = string
@@ -472,7 +484,9 @@ resource "aws_lambda_function" "api_lambda" {
472
484
  PORT = "8000"
473
485
  AWS_LWA_INVOKE_MODE = "buffered"
474
486
  AWS_LAMBDA_EXEC_WRAPPER = "/opt/bootstrap"
475
- }, var.env)
487
+ }, var.appconfig_application_id != null ? {
488
+ RUNTIME_CONFIG_APP_ID = var.appconfig_application_id
489
+ } : {}, var.env)
476
490
  }
477
491
 
478
492
  tags = var.tags
@@ -521,16 +535,30 @@ resource "aws_iam_role_policy_attachment" "lambda_vpc_access" {
521
535
 
522
536
  # Additional IAM policies for Lambda (if provided)
523
537
  resource "aws_iam_role_policy" "lambda_additional_policies" {
524
- count = length(var.additional_iam_policy_statements) > 0 ? 1 : 0
538
+ count = length(local.lambda_policy_statements) > 0 ? 1 : 0
525
539
  name = "TestApiHandler-additional-policies-\${random_string.suffix.result}"
526
540
  role = aws_iam_role.lambda_execution_role.id
527
541
 
528
542
  policy = jsonencode({
529
543
  Version = "2012-10-17"
530
- Statement = var.additional_iam_policy_statements
544
+ Statement = local.lambda_policy_statements
531
545
  })
532
546
  }
533
547
 
548
+ locals {
549
+ # Grant read access to the runtime-config AppConfig application when wired
550
+ lambda_policy_statements = concat(var.appconfig_application_arn != null ? [
551
+ {
552
+ Effect = "Allow"
553
+ Action = [
554
+ "appconfig:StartConfigurationSession",
555
+ "appconfig:GetLatestConfiguration"
556
+ ]
557
+ Resource = ["\${var.appconfig_application_arn}/*"]
558
+ }
559
+ ] : [], var.additional_iam_policy_statements)
560
+ }
561
+
534
562
  # CloudWatch Log Group for Lambda
535
563
  resource "aws_cloudwatch_log_group" "lambda_logs" {
536
564
  #checkov:skip=CKV_AWS_158:Using default CloudWatch log encryption
@@ -1012,6 +1040,18 @@ variable "additional_iam_policy_statements" {
1012
1040
  default = []
1013
1041
  }
1014
1042
 
1043
+ variable "appconfig_application_id" {
1044
+ description = "ID of the shared runtime-config AppConfig application (from \`core/runtime-config/appconfig.application_id\`). When set, the Lambda functions receive \`RUNTIME_CONFIG_APP_ID\` and read access to the application."
1045
+ type = string
1046
+ default = null
1047
+ }
1048
+
1049
+ variable "appconfig_application_arn" {
1050
+ description = "ARN of the shared runtime-config AppConfig application (from \`core/runtime-config/appconfig.application_arn\`). Used to scope the IAM read permission granted to the Lambda functions."
1051
+ type = string
1052
+ default = null
1053
+ }
1054
+
1015
1055
  variable "asset_bucket_name" {
1016
1056
  description = "Name of the shared asset S3 bucket used to stage the Lambda deployment zip. Instantiate the \`core/asset-bucket\` module once per deployment and pass its \`bucket_name\` output here."
1017
1057
  type = string
@@ -1194,7 +1234,9 @@ resource "aws_lambda_function" "api_lambda" {
1194
1234
  PORT = "8000"
1195
1235
  AWS_LWA_INVOKE_MODE = "buffered"
1196
1236
  AWS_LAMBDA_EXEC_WRAPPER = "/opt/bootstrap"
1197
- }, var.env)
1237
+ }, var.appconfig_application_id != null ? {
1238
+ RUNTIME_CONFIG_APP_ID = var.appconfig_application_id
1239
+ } : {}, var.env)
1198
1240
  }
1199
1241
 
1200
1242
  tags = var.tags
@@ -1243,16 +1285,30 @@ resource "aws_iam_role_policy_attachment" "lambda_vpc_access" {
1243
1285
 
1244
1286
  # Additional IAM policies for Lambda (if provided)
1245
1287
  resource "aws_iam_role_policy" "lambda_additional_policies" {
1246
- count = length(var.additional_iam_policy_statements) > 0 ? 1 : 0
1288
+ count = length(local.lambda_policy_statements) > 0 ? 1 : 0
1247
1289
  name = "TestApiHandler-additional-policies-\${random_string.suffix.result}"
1248
1290
  role = aws_iam_role.lambda_execution_role.id
1249
1291
 
1250
1292
  policy = jsonencode({
1251
1293
  Version = "2012-10-17"
1252
- Statement = var.additional_iam_policy_statements
1294
+ Statement = local.lambda_policy_statements
1253
1295
  })
1254
1296
  }
1255
1297
 
1298
+ locals {
1299
+ # Grant read access to the runtime-config AppConfig application when wired
1300
+ lambda_policy_statements = concat(var.appconfig_application_arn != null ? [
1301
+ {
1302
+ Effect = "Allow"
1303
+ Action = [
1304
+ "appconfig:StartConfigurationSession",
1305
+ "appconfig:GetLatestConfiguration"
1306
+ ]
1307
+ Resource = ["\${var.appconfig_application_arn}/*"]
1308
+ }
1309
+ ] : [], var.additional_iam_policy_statements)
1310
+ }
1311
+
1256
1312
  # CloudWatch Log Group for Lambda
1257
1313
  resource "aws_cloudwatch_log_group" "lambda_logs" {
1258
1314
  #checkov:skip=CKV_AWS_158:Using default CloudWatch log encryption
@@ -1816,6 +1872,18 @@ variable "additional_iam_policy_statements" {
1816
1872
  default = []
1817
1873
  }
1818
1874
 
1875
+ variable "appconfig_application_id" {
1876
+ description = "ID of the shared runtime-config AppConfig application (from \`core/runtime-config/appconfig.application_id\`). When set, the Lambda functions receive \`RUNTIME_CONFIG_APP_ID\` and read access to the application."
1877
+ type = string
1878
+ default = null
1879
+ }
1880
+
1881
+ variable "appconfig_application_arn" {
1882
+ description = "ARN of the shared runtime-config AppConfig application (from \`core/runtime-config/appconfig.application_arn\`). Used to scope the IAM read permission granted to the Lambda functions."
1883
+ type = string
1884
+ default = null
1885
+ }
1886
+
1819
1887
  variable "asset_bucket_name" {
1820
1888
  description = "Name of the shared asset S3 bucket used to stage the Lambda deployment zip. Instantiate the \`core/asset-bucket\` module once per deployment and pass its \`bucket_name\` output here."
1821
1889
  type = string
@@ -1998,7 +2066,9 @@ resource "aws_lambda_function" "api_lambda" {
1998
2066
  PORT = "8000"
1999
2067
  AWS_LWA_INVOKE_MODE = "buffered"
2000
2068
  AWS_LAMBDA_EXEC_WRAPPER = "/opt/bootstrap"
2001
- }, var.env)
2069
+ }, var.appconfig_application_id != null ? {
2070
+ RUNTIME_CONFIG_APP_ID = var.appconfig_application_id
2071
+ } : {}, var.env)
2002
2072
  }
2003
2073
 
2004
2074
  tags = var.tags
@@ -2047,16 +2117,30 @@ resource "aws_iam_role_policy_attachment" "lambda_vpc_access" {
2047
2117
 
2048
2118
  # Additional IAM policies for Lambda (if provided)
2049
2119
  resource "aws_iam_role_policy" "lambda_additional_policies" {
2050
- count = length(var.additional_iam_policy_statements) > 0 ? 1 : 0
2120
+ count = length(local.lambda_policy_statements) > 0 ? 1 : 0
2051
2121
  name = "TestApiHandler-additional-policies-\${random_string.suffix.result}"
2052
2122
  role = aws_iam_role.lambda_execution_role.id
2053
2123
 
2054
2124
  policy = jsonencode({
2055
2125
  Version = "2012-10-17"
2056
- Statement = var.additional_iam_policy_statements
2126
+ Statement = local.lambda_policy_statements
2057
2127
  })
2058
2128
  }
2059
2129
 
2130
+ locals {
2131
+ # Grant read access to the runtime-config AppConfig application when wired
2132
+ lambda_policy_statements = concat(var.appconfig_application_arn != null ? [
2133
+ {
2134
+ Effect = "Allow"
2135
+ Action = [
2136
+ "appconfig:StartConfigurationSession",
2137
+ "appconfig:GetLatestConfiguration"
2138
+ ]
2139
+ Resource = ["\${var.appconfig_application_arn}/*"]
2140
+ }
2141
+ ] : [], var.additional_iam_policy_statements)
2142
+ }
2143
+
2060
2144
  # CloudWatch Log Group for Lambda
2061
2145
  resource "aws_cloudwatch_log_group" "lambda_logs" {
2062
2146
  #checkov:skip=CKV_AWS_158:Using default CloudWatch log encryption
@@ -2544,6 +2628,18 @@ variable "additional_iam_policy_statements" {
2544
2628
  default = []
2545
2629
  }
2546
2630
 
2631
+ variable "appconfig_application_id" {
2632
+ description = "ID of the shared runtime-config AppConfig application (from \`core/runtime-config/appconfig.application_id\`). When set, the Lambda functions receive \`RUNTIME_CONFIG_APP_ID\` and read access to the application."
2633
+ type = string
2634
+ default = null
2635
+ }
2636
+
2637
+ variable "appconfig_application_arn" {
2638
+ description = "ARN of the shared runtime-config AppConfig application (from \`core/runtime-config/appconfig.application_arn\`). Used to scope the IAM read permission granted to the Lambda functions."
2639
+ type = string
2640
+ default = null
2641
+ }
2642
+
2547
2643
  variable "asset_bucket_name" {
2548
2644
  description = "Name of the shared asset S3 bucket used to stage the Lambda deployment zip. Instantiate the \`core/asset-bucket\` module once per deployment and pass its \`bucket_name\` output here."
2549
2645
  type = string
@@ -2735,7 +2831,9 @@ resource "aws_lambda_function" "api_lambda" {
2735
2831
  PORT = "8000"
2736
2832
  AWS_LWA_INVOKE_MODE = "response_stream"
2737
2833
  AWS_LAMBDA_EXEC_WRAPPER = "/opt/bootstrap"
2738
- }, var.env)
2834
+ }, var.appconfig_application_id != null ? {
2835
+ RUNTIME_CONFIG_APP_ID = var.appconfig_application_id
2836
+ } : {}, var.env)
2739
2837
  }
2740
2838
 
2741
2839
  tags = var.tags
@@ -2784,16 +2882,30 @@ resource "aws_iam_role_policy_attachment" "lambda_vpc_access" {
2784
2882
 
2785
2883
  # Additional IAM policies for Lambda (if provided)
2786
2884
  resource "aws_iam_role_policy" "lambda_additional_policies" {
2787
- count = length(var.additional_iam_policy_statements) > 0 ? 1 : 0
2885
+ count = length(local.lambda_policy_statements) > 0 ? 1 : 0
2788
2886
  name = "TestApiHandler-additional-policies-\${random_string.suffix.result}"
2789
2887
  role = aws_iam_role.lambda_execution_role.id
2790
2888
 
2791
2889
  policy = jsonencode({
2792
2890
  Version = "2012-10-17"
2793
- Statement = var.additional_iam_policy_statements
2891
+ Statement = local.lambda_policy_statements
2794
2892
  })
2795
2893
  }
2796
2894
 
2895
+ locals {
2896
+ # Grant read access to the runtime-config AppConfig application when wired
2897
+ lambda_policy_statements = concat(var.appconfig_application_arn != null ? [
2898
+ {
2899
+ Effect = "Allow"
2900
+ Action = [
2901
+ "appconfig:StartConfigurationSession",
2902
+ "appconfig:GetLatestConfiguration"
2903
+ ]
2904
+ Resource = ["\${var.appconfig_application_arn}/*"]
2905
+ }
2906
+ ] : [], var.additional_iam_policy_statements)
2907
+ }
2908
+
2797
2909
  # CloudWatch Log Group for Lambda
2798
2910
  resource "aws_cloudwatch_log_group" "lambda_logs" {
2799
2911
  #checkov:skip=CKV_AWS_158:Using default CloudWatch log encryption
@@ -3512,6 +3624,18 @@ variable "additional_iam_policy_statements" {
3512
3624
  default = []
3513
3625
  }
3514
3626
 
3627
+ variable "appconfig_application_id" {
3628
+ description = "ID of the shared runtime-config AppConfig application (from \`core/runtime-config/appconfig.application_id\`). When set, the Lambda functions receive \`RUNTIME_CONFIG_APP_ID\` and read access to the application."
3629
+ type = string
3630
+ default = null
3631
+ }
3632
+
3633
+ variable "appconfig_application_arn" {
3634
+ description = "ARN of the shared runtime-config AppConfig application (from \`core/runtime-config/appconfig.application_arn\`). Used to scope the IAM read permission granted to the Lambda functions."
3635
+ type = string
3636
+ default = null
3637
+ }
3638
+
3515
3639
  variable "asset_bucket_name" {
3516
3640
  description = "Name of the shared asset S3 bucket used to stage the Lambda deployment zip. Instantiate the \`core/asset-bucket\` module once per deployment and pass its \`bucket_name\` output here."
3517
3641
  type = string
@@ -3703,7 +3827,9 @@ resource "aws_lambda_function" "api_lambda" {
3703
3827
  PORT = "8000"
3704
3828
  AWS_LWA_INVOKE_MODE = "response_stream"
3705
3829
  AWS_LAMBDA_EXEC_WRAPPER = "/opt/bootstrap"
3706
- }, var.env)
3830
+ }, var.appconfig_application_id != null ? {
3831
+ RUNTIME_CONFIG_APP_ID = var.appconfig_application_id
3832
+ } : {}, var.env)
3707
3833
  }
3708
3834
 
3709
3835
  tags = var.tags
@@ -3752,16 +3878,30 @@ resource "aws_iam_role_policy_attachment" "lambda_vpc_access" {
3752
3878
 
3753
3879
  # Additional IAM policies for Lambda (if provided)
3754
3880
  resource "aws_iam_role_policy" "lambda_additional_policies" {
3755
- count = length(var.additional_iam_policy_statements) > 0 ? 1 : 0
3881
+ count = length(local.lambda_policy_statements) > 0 ? 1 : 0
3756
3882
  name = "TestApiHandler-additional-policies-\${random_string.suffix.result}"
3757
3883
  role = aws_iam_role.lambda_execution_role.id
3758
3884
 
3759
3885
  policy = jsonencode({
3760
3886
  Version = "2012-10-17"
3761
- Statement = var.additional_iam_policy_statements
3887
+ Statement = local.lambda_policy_statements
3762
3888
  })
3763
3889
  }
3764
3890
 
3891
+ locals {
3892
+ # Grant read access to the runtime-config AppConfig application when wired
3893
+ lambda_policy_statements = concat(var.appconfig_application_arn != null ? [
3894
+ {
3895
+ Effect = "Allow"
3896
+ Action = [
3897
+ "appconfig:StartConfigurationSession",
3898
+ "appconfig:GetLatestConfiguration"
3899
+ ]
3900
+ Resource = ["\${var.appconfig_application_arn}/*"]
3901
+ }
3902
+ ] : [], var.additional_iam_policy_statements)
3903
+ }
3904
+
3765
3905
  # CloudWatch Log Group for Lambda
3766
3906
  resource "aws_cloudwatch_log_group" "lambda_logs" {
3767
3907
  #checkov:skip=CKV_AWS_158:Using default CloudWatch log encryption
@@ -4479,6 +4619,18 @@ variable "additional_iam_policy_statements" {
4479
4619
  default = []
4480
4620
  }
4481
4621
 
4622
+ variable "appconfig_application_id" {
4623
+ description = "ID of the shared runtime-config AppConfig application (from \`core/runtime-config/appconfig.application_id\`). When set, the Lambda functions receive \`RUNTIME_CONFIG_APP_ID\` and read access to the application."
4624
+ type = string
4625
+ default = null
4626
+ }
4627
+
4628
+ variable "appconfig_application_arn" {
4629
+ description = "ARN of the shared runtime-config AppConfig application (from \`core/runtime-config/appconfig.application_arn\`). Used to scope the IAM read permission granted to the Lambda functions."
4630
+ type = string
4631
+ default = null
4632
+ }
4633
+
4482
4634
  variable "asset_bucket_name" {
4483
4635
  description = "Name of the shared asset S3 bucket used to stage the Lambda deployment zip. Instantiate the \`core/asset-bucket\` module once per deployment and pass its \`bucket_name\` output here."
4484
4636
  type = string
@@ -4670,7 +4822,9 @@ resource "aws_lambda_function" "api_lambda" {
4670
4822
  PORT = "8000"
4671
4823
  AWS_LWA_INVOKE_MODE = "response_stream"
4672
4824
  AWS_LAMBDA_EXEC_WRAPPER = "/opt/bootstrap"
4673
- }, var.env)
4825
+ }, var.appconfig_application_id != null ? {
4826
+ RUNTIME_CONFIG_APP_ID = var.appconfig_application_id
4827
+ } : {}, var.env)
4674
4828
  }
4675
4829
 
4676
4830
  tags = var.tags
@@ -4719,16 +4873,30 @@ resource "aws_iam_role_policy_attachment" "lambda_vpc_access" {
4719
4873
 
4720
4874
  # Additional IAM policies for Lambda (if provided)
4721
4875
  resource "aws_iam_role_policy" "lambda_additional_policies" {
4722
- count = length(var.additional_iam_policy_statements) > 0 ? 1 : 0
4876
+ count = length(local.lambda_policy_statements) > 0 ? 1 : 0
4723
4877
  name = "TestApiHandler-additional-policies-\${random_string.suffix.result}"
4724
4878
  role = aws_iam_role.lambda_execution_role.id
4725
4879
 
4726
4880
  policy = jsonencode({
4727
4881
  Version = "2012-10-17"
4728
- Statement = var.additional_iam_policy_statements
4882
+ Statement = local.lambda_policy_statements
4729
4883
  })
4730
4884
  }
4731
4885
 
4886
+ locals {
4887
+ # Grant read access to the runtime-config AppConfig application when wired
4888
+ lambda_policy_statements = concat(var.appconfig_application_arn != null ? [
4889
+ {
4890
+ Effect = "Allow"
4891
+ Action = [
4892
+ "appconfig:StartConfigurationSession",
4893
+ "appconfig:GetLatestConfiguration"
4894
+ ]
4895
+ Resource = ["\${var.appconfig_application_arn}/*"]
4896
+ }
4897
+ ] : [], var.additional_iam_policy_statements)
4898
+ }
4899
+
4732
4900
  # CloudWatch Log Group for Lambda
4733
4901
  resource "aws_cloudwatch_log_group" "lambda_logs" {
4734
4902
  #checkov:skip=CKV_AWS_158:Using default CloudWatch log encryption
@@ -684,6 +684,18 @@ variable "additional_iam_policy_statements" {
684
684
  default = []
685
685
  }
686
686
 
687
+ variable "appconfig_application_id" {
688
+ description = "ID of the shared runtime-config AppConfig application (from \`core/runtime-config/appconfig.application_id\`). When set, the Lambda functions receive \`RUNTIME_CONFIG_APP_ID\` and read access to the application."
689
+ type = string
690
+ default = null
691
+ }
692
+
693
+ variable "appconfig_application_arn" {
694
+ description = "ARN of the shared runtime-config AppConfig application (from \`core/runtime-config/appconfig.application_arn\`). Used to scope the IAM read permission granted to the Lambda functions."
695
+ type = string
696
+ default = null
697
+ }
698
+
687
699
  variable "asset_bucket_name" {
688
700
  description = "Name of the shared asset S3 bucket used to stage the Lambda deployment zip. Instantiate the \`core/asset-bucket\` module once per deployment and pass its \`bucket_name\` output here."
689
701
  type = string
@@ -866,7 +878,9 @@ resource "aws_lambda_function" "api_lambda" {
866
878
 
867
879
  environment {
868
880
  variables = merge({
869
- }, var.env)
881
+ }, var.appconfig_application_id != null ? {
882
+ RUNTIME_CONFIG_APP_ID = var.appconfig_application_id
883
+ } : {}, var.env)
870
884
  }
871
885
 
872
886
  tags = var.tags
@@ -915,16 +929,30 @@ resource "aws_iam_role_policy_attachment" "lambda_vpc_access" {
915
929
 
916
930
  # Additional IAM policies for Lambda (if provided)
917
931
  resource "aws_iam_role_policy" "lambda_additional_policies" {
918
- count = length(var.additional_iam_policy_statements) > 0 ? 1 : 0
932
+ count = length(local.lambda_policy_statements) > 0 ? 1 : 0
919
933
  name = "TestApiHandler-additional-policies-\${random_string.suffix.result}"
920
934
  role = aws_iam_role.lambda_execution_role.id
921
935
 
922
936
  policy = jsonencode({
923
937
  Version = "2012-10-17"
924
- Statement = var.additional_iam_policy_statements
938
+ Statement = local.lambda_policy_statements
925
939
  })
926
940
  }
927
941
 
942
+ locals {
943
+ # Grant read access to the runtime-config AppConfig application when wired
944
+ lambda_policy_statements = concat(var.appconfig_application_arn != null ? [
945
+ {
946
+ Effect = "Allow"
947
+ Action = [
948
+ "appconfig:StartConfigurationSession",
949
+ "appconfig:GetLatestConfiguration"
950
+ ]
951
+ Resource = ["\${var.appconfig_application_arn}/*"]
952
+ }
953
+ ] : [], var.additional_iam_policy_statements)
954
+ }
955
+
928
956
  # CloudWatch Log Group for Lambda
929
957
  resource "aws_cloudwatch_log_group" "lambda_logs" {
930
958
  #checkov:skip=CKV_AWS_158:Using default CloudWatch log encryption
@@ -2115,6 +2143,18 @@ variable "additional_iam_policy_statements" {
2115
2143
  default = []
2116
2144
  }
2117
2145
 
2146
+ variable "appconfig_application_id" {
2147
+ description = "ID of the shared runtime-config AppConfig application (from \`core/runtime-config/appconfig.application_id\`). When set, the Lambda functions receive \`RUNTIME_CONFIG_APP_ID\` and read access to the application."
2148
+ type = string
2149
+ default = null
2150
+ }
2151
+
2152
+ variable "appconfig_application_arn" {
2153
+ description = "ARN of the shared runtime-config AppConfig application (from \`core/runtime-config/appconfig.application_arn\`). Used to scope the IAM read permission granted to the Lambda functions."
2154
+ type = string
2155
+ default = null
2156
+ }
2157
+
2118
2158
  variable "asset_bucket_name" {
2119
2159
  description = "Name of the shared asset S3 bucket used to stage the Lambda deployment zip. Instantiate the \`core/asset-bucket\` module once per deployment and pass its \`bucket_name\` output here."
2120
2160
  type = string
@@ -2297,7 +2337,9 @@ resource "aws_lambda_function" "api_lambda" {
2297
2337
 
2298
2338
  environment {
2299
2339
  variables = merge({
2300
- }, var.env)
2340
+ }, var.appconfig_application_id != null ? {
2341
+ RUNTIME_CONFIG_APP_ID = var.appconfig_application_id
2342
+ } : {}, var.env)
2301
2343
  }
2302
2344
 
2303
2345
  tags = var.tags
@@ -2346,16 +2388,30 @@ resource "aws_iam_role_policy_attachment" "lambda_vpc_access" {
2346
2388
 
2347
2389
  # Additional IAM policies for Lambda (if provided)
2348
2390
  resource "aws_iam_role_policy" "lambda_additional_policies" {
2349
- count = length(var.additional_iam_policy_statements) > 0 ? 1 : 0
2391
+ count = length(local.lambda_policy_statements) > 0 ? 1 : 0
2350
2392
  name = "TestApiHandler-additional-policies-\${random_string.suffix.result}"
2351
2393
  role = aws_iam_role.lambda_execution_role.id
2352
2394
 
2353
2395
  policy = jsonencode({
2354
2396
  Version = "2012-10-17"
2355
- Statement = var.additional_iam_policy_statements
2397
+ Statement = local.lambda_policy_statements
2356
2398
  })
2357
2399
  }
2358
2400
 
2401
+ locals {
2402
+ # Grant read access to the runtime-config AppConfig application when wired
2403
+ lambda_policy_statements = concat(var.appconfig_application_arn != null ? [
2404
+ {
2405
+ Effect = "Allow"
2406
+ Action = [
2407
+ "appconfig:StartConfigurationSession",
2408
+ "appconfig:GetLatestConfiguration"
2409
+ ]
2410
+ Resource = ["\${var.appconfig_application_arn}/*"]
2411
+ }
2412
+ ] : [], var.additional_iam_policy_statements)
2413
+ }
2414
+
2359
2415
  # CloudWatch Log Group for Lambda
2360
2416
  resource "aws_cloudwatch_log_group" "lambda_logs" {
2361
2417
  #checkov:skip=CKV_AWS_158:Using default CloudWatch log encryption
@@ -3052,6 +3108,18 @@ variable "additional_iam_policy_statements" {
3052
3108
  default = []
3053
3109
  }
3054
3110
 
3111
+ variable "appconfig_application_id" {
3112
+ description = "ID of the shared runtime-config AppConfig application (from \`core/runtime-config/appconfig.application_id\`). When set, the Lambda functions receive \`RUNTIME_CONFIG_APP_ID\` and read access to the application."
3113
+ type = string
3114
+ default = null
3115
+ }
3116
+
3117
+ variable "appconfig_application_arn" {
3118
+ description = "ARN of the shared runtime-config AppConfig application (from \`core/runtime-config/appconfig.application_arn\`). Used to scope the IAM read permission granted to the Lambda functions."
3119
+ type = string
3120
+ default = null
3121
+ }
3122
+
3055
3123
  variable "asset_bucket_name" {
3056
3124
  description = "Name of the shared asset S3 bucket used to stage the Lambda deployment zip. Instantiate the \`core/asset-bucket\` module once per deployment and pass its \`bucket_name\` output here."
3057
3125
  type = string
@@ -3234,7 +3302,9 @@ resource "aws_lambda_function" "api_lambda" {
3234
3302
 
3235
3303
  environment {
3236
3304
  variables = merge({
3237
- }, var.env)
3305
+ }, var.appconfig_application_id != null ? {
3306
+ RUNTIME_CONFIG_APP_ID = var.appconfig_application_id
3307
+ } : {}, var.env)
3238
3308
  }
3239
3309
 
3240
3310
  tags = var.tags
@@ -3283,16 +3353,30 @@ resource "aws_iam_role_policy_attachment" "lambda_vpc_access" {
3283
3353
 
3284
3354
  # Additional IAM policies for Lambda (if provided)
3285
3355
  resource "aws_iam_role_policy" "lambda_additional_policies" {
3286
- count = length(var.additional_iam_policy_statements) > 0 ? 1 : 0
3356
+ count = length(local.lambda_policy_statements) > 0 ? 1 : 0
3287
3357
  name = "TestApiHandler-additional-policies-\${random_string.suffix.result}"
3288
3358
  role = aws_iam_role.lambda_execution_role.id
3289
3359
 
3290
3360
  policy = jsonencode({
3291
3361
  Version = "2012-10-17"
3292
- Statement = var.additional_iam_policy_statements
3362
+ Statement = local.lambda_policy_statements
3293
3363
  })
3294
3364
  }
3295
3365
 
3366
+ locals {
3367
+ # Grant read access to the runtime-config AppConfig application when wired
3368
+ lambda_policy_statements = concat(var.appconfig_application_arn != null ? [
3369
+ {
3370
+ Effect = "Allow"
3371
+ Action = [
3372
+ "appconfig:StartConfigurationSession",
3373
+ "appconfig:GetLatestConfiguration"
3374
+ ]
3375
+ Resource = ["\${var.appconfig_application_arn}/*"]
3376
+ }
3377
+ ] : [], var.additional_iam_policy_statements)
3378
+ }
3379
+
3296
3380
  # CloudWatch Log Group for Lambda
3297
3381
  resource "aws_cloudwatch_log_group" "lambda_logs" {
3298
3382
  #checkov:skip=CKV_AWS_158:Using default CloudWatch log encryption
@@ -3728,6 +3812,18 @@ variable "additional_iam_policy_statements" {
3728
3812
  default = []
3729
3813
  }
3730
3814
 
3815
+ variable "appconfig_application_id" {
3816
+ description = "ID of the shared runtime-config AppConfig application (from \`core/runtime-config/appconfig.application_id\`). When set, the Lambda functions receive \`RUNTIME_CONFIG_APP_ID\` and read access to the application."
3817
+ type = string
3818
+ default = null
3819
+ }
3820
+
3821
+ variable "appconfig_application_arn" {
3822
+ description = "ARN of the shared runtime-config AppConfig application (from \`core/runtime-config/appconfig.application_arn\`). Used to scope the IAM read permission granted to the Lambda functions."
3823
+ type = string
3824
+ default = null
3825
+ }
3826
+
3731
3827
  variable "asset_bucket_name" {
3732
3828
  description = "Name of the shared asset S3 bucket used to stage the Lambda deployment zip. Instantiate the \`core/asset-bucket\` module once per deployment and pass its \`bucket_name\` output here."
3733
3829
  type = string
@@ -3910,7 +4006,9 @@ resource "aws_lambda_function" "api_lambda" {
3910
4006
 
3911
4007
  environment {
3912
4008
  variables = merge({
3913
- }, var.env)
4009
+ }, var.appconfig_application_id != null ? {
4010
+ RUNTIME_CONFIG_APP_ID = var.appconfig_application_id
4011
+ } : {}, var.env)
3914
4012
  }
3915
4013
 
3916
4014
  tags = var.tags
@@ -3959,16 +4057,30 @@ resource "aws_iam_role_policy_attachment" "lambda_vpc_access" {
3959
4057
 
3960
4058
  # Additional IAM policies for Lambda (if provided)
3961
4059
  resource "aws_iam_role_policy" "lambda_additional_policies" {
3962
- count = length(var.additional_iam_policy_statements) > 0 ? 1 : 0
4060
+ count = length(local.lambda_policy_statements) > 0 ? 1 : 0
3963
4061
  name = "CustomApiHandler-additional-policies-\${random_string.suffix.result}"
3964
4062
  role = aws_iam_role.lambda_execution_role.id
3965
4063
 
3966
4064
  policy = jsonencode({
3967
4065
  Version = "2012-10-17"
3968
- Statement = var.additional_iam_policy_statements
4066
+ Statement = local.lambda_policy_statements
3969
4067
  })
3970
4068
  }
3971
4069
 
4070
+ locals {
4071
+ # Grant read access to the runtime-config AppConfig application when wired
4072
+ lambda_policy_statements = concat(var.appconfig_application_arn != null ? [
4073
+ {
4074
+ Effect = "Allow"
4075
+ Action = [
4076
+ "appconfig:StartConfigurationSession",
4077
+ "appconfig:GetLatestConfiguration"
4078
+ ]
4079
+ Resource = ["\${var.appconfig_application_arn}/*"]
4080
+ }
4081
+ ] : [], var.additional_iam_policy_statements)
4082
+ }
4083
+
3972
4084
  # CloudWatch Log Group for Lambda
3973
4085
  resource "aws_cloudwatch_log_group" "lambda_logs" {
3974
4086
  #checkov:skip=CKV_AWS_158:Using default CloudWatch log encryption
@@ -3421,6 +3421,18 @@ variable "additional_iam_policy_statements" {
3421
3421
  default = []
3422
3422
  }
3423
3423
 
3424
+ variable "appconfig_application_id" {
3425
+ description = "ID of the shared runtime-config AppConfig application (from \`core/runtime-config/appconfig.application_id\`). When set, the Lambda functions receive \`RUNTIME_CONFIG_APP_ID\` and read access to the application."
3426
+ type = string
3427
+ default = null
3428
+ }
3429
+
3430
+ variable "appconfig_application_arn" {
3431
+ description = "ARN of the shared runtime-config AppConfig application (from \`core/runtime-config/appconfig.application_arn\`). Used to scope the IAM read permission granted to the Lambda functions."
3432
+ type = string
3433
+ default = null
3434
+ }
3435
+
3424
3436
  variable "asset_bucket_name" {
3425
3437
  description = "Name of the shared asset S3 bucket used to stage the Lambda deployment zip. Instantiate the \`core/asset-bucket\` module once per deployment and pass its \`bucket_name\` output here."
3426
3438
  type = string
@@ -3594,7 +3606,9 @@ resource "aws_lambda_function" "api_lambda" {
3594
3606
 
3595
3607
  environment {
3596
3608
  variables = merge({
3597
- }, var.env)
3609
+ }, var.appconfig_application_id != null ? {
3610
+ RUNTIME_CONFIG_APP_ID = var.appconfig_application_id
3611
+ } : {}, var.env)
3598
3612
  }
3599
3613
 
3600
3614
  tags = var.tags
@@ -3643,16 +3657,30 @@ resource "aws_iam_role_policy_attachment" "lambda_vpc_access" {
3643
3657
 
3644
3658
  # Additional IAM policies for Lambda (if provided)
3645
3659
  resource "aws_iam_role_policy" "lambda_additional_policies" {
3646
- count = length(var.additional_iam_policy_statements) > 0 ? 1 : 0
3660
+ count = length(local.lambda_policy_statements) > 0 ? 1 : 0
3647
3661
  name = "TestApiHandler-additional-policies-\${random_string.suffix.result}"
3648
3662
  role = aws_iam_role.lambda_execution_role.id
3649
3663
 
3650
3664
  policy = jsonencode({
3651
3665
  Version = "2012-10-17"
3652
- Statement = var.additional_iam_policy_statements
3666
+ Statement = local.lambda_policy_statements
3653
3667
  })
3654
3668
  }
3655
3669
 
3670
+ locals {
3671
+ # Grant read access to the runtime-config AppConfig application when wired
3672
+ lambda_policy_statements = concat(var.appconfig_application_arn != null ? [
3673
+ {
3674
+ Effect = "Allow"
3675
+ Action = [
3676
+ "appconfig:StartConfigurationSession",
3677
+ "appconfig:GetLatestConfiguration"
3678
+ ]
3679
+ Resource = ["\${var.appconfig_application_arn}/*"]
3680
+ }
3681
+ ] : [], var.additional_iam_policy_statements)
3682
+ }
3683
+
3656
3684
  # CloudWatch Log Group for Lambda
3657
3685
  resource "aws_cloudwatch_log_group" "lambda_logs" {
3658
3686
  #checkov:skip=CKV_AWS_158:Using default CloudWatch log encryption
@@ -4125,6 +4153,18 @@ variable "additional_iam_policy_statements" {
4125
4153
  default = []
4126
4154
  }
4127
4155
 
4156
+ variable "appconfig_application_id" {
4157
+ description = "ID of the shared runtime-config AppConfig application (from \`core/runtime-config/appconfig.application_id\`). When set, the Lambda functions receive \`RUNTIME_CONFIG_APP_ID\` and read access to the application."
4158
+ type = string
4159
+ default = null
4160
+ }
4161
+
4162
+ variable "appconfig_application_arn" {
4163
+ description = "ARN of the shared runtime-config AppConfig application (from \`core/runtime-config/appconfig.application_arn\`). Used to scope the IAM read permission granted to the Lambda functions."
4164
+ type = string
4165
+ default = null
4166
+ }
4167
+
4128
4168
  variable "asset_bucket_name" {
4129
4169
  description = "Name of the shared asset S3 bucket used to stage the Lambda deployment zip. Instantiate the \`core/asset-bucket\` module once per deployment and pass its \`bucket_name\` output here."
4130
4170
  type = string
@@ -4298,7 +4338,9 @@ resource "aws_lambda_function" "api_lambda" {
4298
4338
 
4299
4339
  environment {
4300
4340
  variables = merge({
4301
- }, var.env)
4341
+ }, var.appconfig_application_id != null ? {
4342
+ RUNTIME_CONFIG_APP_ID = var.appconfig_application_id
4343
+ } : {}, var.env)
4302
4344
  }
4303
4345
 
4304
4346
  tags = var.tags
@@ -4347,16 +4389,30 @@ resource "aws_iam_role_policy_attachment" "lambda_vpc_access" {
4347
4389
 
4348
4390
  # Additional IAM policies for Lambda (if provided)
4349
4391
  resource "aws_iam_role_policy" "lambda_additional_policies" {
4350
- count = length(var.additional_iam_policy_statements) > 0 ? 1 : 0
4392
+ count = length(local.lambda_policy_statements) > 0 ? 1 : 0
4351
4393
  name = "TestApiHandler-additional-policies-\${random_string.suffix.result}"
4352
4394
  role = aws_iam_role.lambda_execution_role.id
4353
4395
 
4354
4396
  policy = jsonencode({
4355
4397
  Version = "2012-10-17"
4356
- Statement = var.additional_iam_policy_statements
4398
+ Statement = local.lambda_policy_statements
4357
4399
  })
4358
4400
  }
4359
4401
 
4402
+ locals {
4403
+ # Grant read access to the runtime-config AppConfig application when wired
4404
+ lambda_policy_statements = concat(var.appconfig_application_arn != null ? [
4405
+ {
4406
+ Effect = "Allow"
4407
+ Action = [
4408
+ "appconfig:StartConfigurationSession",
4409
+ "appconfig:GetLatestConfiguration"
4410
+ ]
4411
+ Resource = ["\${var.appconfig_application_arn}/*"]
4412
+ }
4413
+ ] : [], var.additional_iam_policy_statements)
4414
+ }
4415
+
4360
4416
  # CloudWatch Log Group for Lambda
4361
4417
  resource "aws_cloudwatch_log_group" "lambda_logs" {
4362
4418
  #checkov:skip=CKV_AWS_158:Using default CloudWatch log encryption
@@ -4911,6 +4967,18 @@ variable "additional_iam_policy_statements" {
4911
4967
  default = []
4912
4968
  }
4913
4969
 
4970
+ variable "appconfig_application_id" {
4971
+ description = "ID of the shared runtime-config AppConfig application (from \`core/runtime-config/appconfig.application_id\`). When set, the Lambda functions receive \`RUNTIME_CONFIG_APP_ID\` and read access to the application."
4972
+ type = string
4973
+ default = null
4974
+ }
4975
+
4976
+ variable "appconfig_application_arn" {
4977
+ description = "ARN of the shared runtime-config AppConfig application (from \`core/runtime-config/appconfig.application_arn\`). Used to scope the IAM read permission granted to the Lambda functions."
4978
+ type = string
4979
+ default = null
4980
+ }
4981
+
4914
4982
  variable "asset_bucket_name" {
4915
4983
  description = "Name of the shared asset S3 bucket used to stage the Lambda deployment zip. Instantiate the \`core/asset-bucket\` module once per deployment and pass its \`bucket_name\` output here."
4916
4984
  type = string
@@ -5084,7 +5152,9 @@ resource "aws_lambda_function" "api_lambda" {
5084
5152
 
5085
5153
  environment {
5086
5154
  variables = merge({
5087
- }, var.env)
5155
+ }, var.appconfig_application_id != null ? {
5156
+ RUNTIME_CONFIG_APP_ID = var.appconfig_application_id
5157
+ } : {}, var.env)
5088
5158
  }
5089
5159
 
5090
5160
  tags = var.tags
@@ -5133,16 +5203,30 @@ resource "aws_iam_role_policy_attachment" "lambda_vpc_access" {
5133
5203
 
5134
5204
  # Additional IAM policies for Lambda (if provided)
5135
5205
  resource "aws_iam_role_policy" "lambda_additional_policies" {
5136
- count = length(var.additional_iam_policy_statements) > 0 ? 1 : 0
5206
+ count = length(local.lambda_policy_statements) > 0 ? 1 : 0
5137
5207
  name = "TestApiHandler-additional-policies-\${random_string.suffix.result}"
5138
5208
  role = aws_iam_role.lambda_execution_role.id
5139
5209
 
5140
5210
  policy = jsonencode({
5141
5211
  Version = "2012-10-17"
5142
- Statement = var.additional_iam_policy_statements
5212
+ Statement = local.lambda_policy_statements
5143
5213
  })
5144
5214
  }
5145
5215
 
5216
+ locals {
5217
+ # Grant read access to the runtime-config AppConfig application when wired
5218
+ lambda_policy_statements = concat(var.appconfig_application_arn != null ? [
5219
+ {
5220
+ Effect = "Allow"
5221
+ Action = [
5222
+ "appconfig:StartConfigurationSession",
5223
+ "appconfig:GetLatestConfiguration"
5224
+ ]
5225
+ Resource = ["\${var.appconfig_application_arn}/*"]
5226
+ }
5227
+ ] : [], var.additional_iam_policy_statements)
5228
+ }
5229
+
5146
5230
  # CloudWatch Log Group for Lambda
5147
5231
  resource "aws_cloudwatch_log_group" "lambda_logs" {
5148
5232
  #checkov:skip=CKV_AWS_158:Using default CloudWatch log encryption
@@ -5621,6 +5705,18 @@ variable "additional_iam_policy_statements" {
5621
5705
  default = []
5622
5706
  }
5623
5707
 
5708
+ variable "appconfig_application_id" {
5709
+ description = "ID of the shared runtime-config AppConfig application (from \`core/runtime-config/appconfig.application_id\`). When set, the Lambda functions receive \`RUNTIME_CONFIG_APP_ID\` and read access to the application."
5710
+ type = string
5711
+ default = null
5712
+ }
5713
+
5714
+ variable "appconfig_application_arn" {
5715
+ description = "ARN of the shared runtime-config AppConfig application (from \`core/runtime-config/appconfig.application_arn\`). Used to scope the IAM read permission granted to the Lambda functions."
5716
+ type = string
5717
+ default = null
5718
+ }
5719
+
5624
5720
  variable "asset_bucket_name" {
5625
5721
  description = "Name of the shared asset S3 bucket used to stage the Lambda deployment zip. Instantiate the \`core/asset-bucket\` module once per deployment and pass its \`bucket_name\` output here."
5626
5722
  type = string
@@ -5803,7 +5899,9 @@ resource "aws_lambda_function" "api_lambda" {
5803
5899
 
5804
5900
  environment {
5805
5901
  variables = merge({
5806
- }, var.env)
5902
+ }, var.appconfig_application_id != null ? {
5903
+ RUNTIME_CONFIG_APP_ID = var.appconfig_application_id
5904
+ } : {}, var.env)
5807
5905
  }
5808
5906
 
5809
5907
  tags = var.tags
@@ -5852,16 +5950,30 @@ resource "aws_iam_role_policy_attachment" "lambda_vpc_access" {
5852
5950
 
5853
5951
  # Additional IAM policies for Lambda (if provided)
5854
5952
  resource "aws_iam_role_policy" "lambda_additional_policies" {
5855
- count = length(var.additional_iam_policy_statements) > 0 ? 1 : 0
5953
+ count = length(local.lambda_policy_statements) > 0 ? 1 : 0
5856
5954
  name = "TestApiHandler-additional-policies-\${random_string.suffix.result}"
5857
5955
  role = aws_iam_role.lambda_execution_role.id
5858
5956
 
5859
5957
  policy = jsonencode({
5860
5958
  Version = "2012-10-17"
5861
- Statement = var.additional_iam_policy_statements
5959
+ Statement = local.lambda_policy_statements
5862
5960
  })
5863
5961
  }
5864
5962
 
5963
+ locals {
5964
+ # Grant read access to the runtime-config AppConfig application when wired
5965
+ lambda_policy_statements = concat(var.appconfig_application_arn != null ? [
5966
+ {
5967
+ Effect = "Allow"
5968
+ Action = [
5969
+ "appconfig:StartConfigurationSession",
5970
+ "appconfig:GetLatestConfiguration"
5971
+ ]
5972
+ Resource = ["\${var.appconfig_application_arn}/*"]
5973
+ }
5974
+ ] : [], var.additional_iam_policy_statements)
5975
+ }
5976
+
5865
5977
  # CloudWatch Log Group for Lambda
5866
5978
  resource "aws_cloudwatch_log_group" "lambda_logs" {
5867
5979
  #checkov:skip=CKV_AWS_158:Using default CloudWatch log encryption
@@ -6559,6 +6671,18 @@ variable "additional_iam_policy_statements" {
6559
6671
  default = []
6560
6672
  }
6561
6673
 
6674
+ variable "appconfig_application_id" {
6675
+ description = "ID of the shared runtime-config AppConfig application (from \`core/runtime-config/appconfig.application_id\`). When set, the Lambda functions receive \`RUNTIME_CONFIG_APP_ID\` and read access to the application."
6676
+ type = string
6677
+ default = null
6678
+ }
6679
+
6680
+ variable "appconfig_application_arn" {
6681
+ description = "ARN of the shared runtime-config AppConfig application (from \`core/runtime-config/appconfig.application_arn\`). Used to scope the IAM read permission granted to the Lambda functions."
6682
+ type = string
6683
+ default = null
6684
+ }
6685
+
6562
6686
  variable "asset_bucket_name" {
6563
6687
  description = "Name of the shared asset S3 bucket used to stage the Lambda deployment zip. Instantiate the \`core/asset-bucket\` module once per deployment and pass its \`bucket_name\` output here."
6564
6688
  type = string
@@ -6741,7 +6865,9 @@ resource "aws_lambda_function" "api_lambda" {
6741
6865
 
6742
6866
  environment {
6743
6867
  variables = merge({
6744
- }, var.env)
6868
+ }, var.appconfig_application_id != null ? {
6869
+ RUNTIME_CONFIG_APP_ID = var.appconfig_application_id
6870
+ } : {}, var.env)
6745
6871
  }
6746
6872
 
6747
6873
  tags = var.tags
@@ -6790,16 +6916,30 @@ resource "aws_iam_role_policy_attachment" "lambda_vpc_access" {
6790
6916
 
6791
6917
  # Additional IAM policies for Lambda (if provided)
6792
6918
  resource "aws_iam_role_policy" "lambda_additional_policies" {
6793
- count = length(var.additional_iam_policy_statements) > 0 ? 1 : 0
6919
+ count = length(local.lambda_policy_statements) > 0 ? 1 : 0
6794
6920
  name = "TestApiHandler-additional-policies-\${random_string.suffix.result}"
6795
6921
  role = aws_iam_role.lambda_execution_role.id
6796
6922
 
6797
6923
  policy = jsonencode({
6798
6924
  Version = "2012-10-17"
6799
- Statement = var.additional_iam_policy_statements
6925
+ Statement = local.lambda_policy_statements
6800
6926
  })
6801
6927
  }
6802
6928
 
6929
+ locals {
6930
+ # Grant read access to the runtime-config AppConfig application when wired
6931
+ lambda_policy_statements = concat(var.appconfig_application_arn != null ? [
6932
+ {
6933
+ Effect = "Allow"
6934
+ Action = [
6935
+ "appconfig:StartConfigurationSession",
6936
+ "appconfig:GetLatestConfiguration"
6937
+ ]
6938
+ Resource = ["\${var.appconfig_application_arn}/*"]
6939
+ }
6940
+ ] : [], var.additional_iam_policy_statements)
6941
+ }
6942
+
6803
6943
  # CloudWatch Log Group for Lambda
6804
6944
  resource "aws_cloudwatch_log_group" "lambda_logs" {
6805
6945
  #checkov:skip=CKV_AWS_158:Using default CloudWatch log encryption
@@ -7496,6 +7636,18 @@ variable "additional_iam_policy_statements" {
7496
7636
  default = []
7497
7637
  }
7498
7638
 
7639
+ variable "appconfig_application_id" {
7640
+ description = "ID of the shared runtime-config AppConfig application (from \`core/runtime-config/appconfig.application_id\`). When set, the Lambda functions receive \`RUNTIME_CONFIG_APP_ID\` and read access to the application."
7641
+ type = string
7642
+ default = null
7643
+ }
7644
+
7645
+ variable "appconfig_application_arn" {
7646
+ description = "ARN of the shared runtime-config AppConfig application (from \`core/runtime-config/appconfig.application_arn\`). Used to scope the IAM read permission granted to the Lambda functions."
7647
+ type = string
7648
+ default = null
7649
+ }
7650
+
7499
7651
  variable "asset_bucket_name" {
7500
7652
  description = "Name of the shared asset S3 bucket used to stage the Lambda deployment zip. Instantiate the \`core/asset-bucket\` module once per deployment and pass its \`bucket_name\` output here."
7501
7653
  type = string
@@ -7678,7 +7830,9 @@ resource "aws_lambda_function" "api_lambda" {
7678
7830
 
7679
7831
  environment {
7680
7832
  variables = merge({
7681
- }, var.env)
7833
+ }, var.appconfig_application_id != null ? {
7834
+ RUNTIME_CONFIG_APP_ID = var.appconfig_application_id
7835
+ } : {}, var.env)
7682
7836
  }
7683
7837
 
7684
7838
  tags = var.tags
@@ -7727,16 +7881,30 @@ resource "aws_iam_role_policy_attachment" "lambda_vpc_access" {
7727
7881
 
7728
7882
  # Additional IAM policies for Lambda (if provided)
7729
7883
  resource "aws_iam_role_policy" "lambda_additional_policies" {
7730
- count = length(var.additional_iam_policy_statements) > 0 ? 1 : 0
7884
+ count = length(local.lambda_policy_statements) > 0 ? 1 : 0
7731
7885
  name = "TestApiHandler-additional-policies-\${random_string.suffix.result}"
7732
7886
  role = aws_iam_role.lambda_execution_role.id
7733
7887
 
7734
7888
  policy = jsonencode({
7735
7889
  Version = "2012-10-17"
7736
- Statement = var.additional_iam_policy_statements
7890
+ Statement = local.lambda_policy_statements
7737
7891
  })
7738
7892
  }
7739
7893
 
7894
+ locals {
7895
+ # Grant read access to the runtime-config AppConfig application when wired
7896
+ lambda_policy_statements = concat(var.appconfig_application_arn != null ? [
7897
+ {
7898
+ Effect = "Allow"
7899
+ Action = [
7900
+ "appconfig:StartConfigurationSession",
7901
+ "appconfig:GetLatestConfiguration"
7902
+ ]
7903
+ Resource = ["\${var.appconfig_application_arn}/*"]
7904
+ }
7905
+ ] : [], var.additional_iam_policy_statements)
7906
+ }
7907
+
7740
7908
  # CloudWatch Log Group for Lambda
7741
7909
  resource "aws_cloudwatch_log_group" "lambda_logs" {
7742
7910
  #checkov:skip=CKV_AWS_158:Using default CloudWatch log encryption
@@ -38,6 +38,18 @@ variable "additional_iam_policy_statements" {
38
38
  default = []
39
39
  }
40
40
 
41
+ variable "appconfig_application_id" {
42
+ description = "ID of the shared runtime-config AppConfig application (from `core/runtime-config/appconfig.application_id`). When set, the Lambda functions receive `RUNTIME_CONFIG_APP_ID` and read access to the application."
43
+ type = string
44
+ default = null
45
+ }
46
+
47
+ variable "appconfig_application_arn" {
48
+ description = "ARN of the shared runtime-config AppConfig application (from `core/runtime-config/appconfig.application_arn`). Used to scope the IAM read permission granted to the Lambda functions."
49
+ type = string
50
+ default = null
51
+ }
52
+
41
53
  variable "asset_bucket_name" {
42
54
  description = "Name of the shared asset S3 bucket used to stage the Lambda deployment zip. Instantiate the `core/asset-bucket` module once per deployment and pass its `bucket_name` output here."
43
55
  type = string
@@ -231,7 +243,9 @@ resource "aws_lambda_function" "api_lambda" {
231
243
  AWS_LWA_INVOKE_MODE = "buffered"
232
244
  AWS_LAMBDA_EXEC_WRAPPER = "/opt/bootstrap"
233
245
  <%_ } _%>
234
- }, var.env)
246
+ }, var.appconfig_application_id != null ? {
247
+ RUNTIME_CONFIG_APP_ID = var.appconfig_application_id
248
+ } : {}, var.env)
235
249
  }
236
250
 
237
251
  tags = var.tags
@@ -280,16 +294,30 @@ resource "aws_iam_role_policy_attachment" "lambda_vpc_access" {
280
294
 
281
295
  # Additional IAM policies for Lambda (if provided)
282
296
  resource "aws_iam_role_policy" "lambda_additional_policies" {
283
- count = length(var.additional_iam_policy_statements) > 0 ? 1 : 0
297
+ count = length(local.lambda_policy_statements) > 0 ? 1 : 0
284
298
  name = "<%- apiNameClassName %>Handler-additional-policies-${random_string.suffix.result}"
285
299
  role = aws_iam_role.lambda_execution_role.id
286
300
 
287
301
  policy = jsonencode({
288
302
  Version = "2012-10-17"
289
- Statement = var.additional_iam_policy_statements
303
+ Statement = local.lambda_policy_statements
290
304
  })
291
305
  }
292
306
 
307
+ locals {
308
+ # Grant read access to the runtime-config AppConfig application when wired
309
+ lambda_policy_statements = concat(var.appconfig_application_arn != null ? [
310
+ {
311
+ Effect = "Allow"
312
+ Action = [
313
+ "appconfig:StartConfigurationSession",
314
+ "appconfig:GetLatestConfiguration"
315
+ ]
316
+ Resource = ["${var.appconfig_application_arn}/*"]
317
+ }
318
+ ] : [], var.additional_iam_policy_statements)
319
+ }
320
+
293
321
  # CloudWatch Log Group for Lambda
294
322
  resource "aws_cloudwatch_log_group" "lambda_logs" {
295
323
  #checkov:skip=CKV_AWS_158:Using default CloudWatch log encryption
@@ -38,6 +38,18 @@ variable "additional_iam_policy_statements" {
38
38
  default = []
39
39
  }
40
40
 
41
+ variable "appconfig_application_id" {
42
+ description = "ID of the shared runtime-config AppConfig application (from `core/runtime-config/appconfig.application_id`). When set, the Lambda functions receive `RUNTIME_CONFIG_APP_ID` and read access to the application."
43
+ type = string
44
+ default = null
45
+ }
46
+
47
+ variable "appconfig_application_arn" {
48
+ description = "ARN of the shared runtime-config AppConfig application (from `core/runtime-config/appconfig.application_arn`). Used to scope the IAM read permission granted to the Lambda functions."
49
+ type = string
50
+ default = null
51
+ }
52
+
41
53
  variable "asset_bucket_name" {
42
54
  description = "Name of the shared asset S3 bucket used to stage the Lambda deployment zip. Instantiate the `core/asset-bucket` module once per deployment and pass its `bucket_name` output here."
43
55
  type = string
@@ -240,7 +252,9 @@ resource "aws_lambda_function" "api_lambda" {
240
252
  AWS_LWA_INVOKE_MODE = "response_stream"
241
253
  AWS_LAMBDA_EXEC_WRAPPER = "/opt/bootstrap"
242
254
  <%_ } _%>
243
- }, var.env)
255
+ }, var.appconfig_application_id != null ? {
256
+ RUNTIME_CONFIG_APP_ID = var.appconfig_application_id
257
+ } : {}, var.env)
244
258
  }
245
259
 
246
260
  tags = var.tags
@@ -289,16 +303,30 @@ resource "aws_iam_role_policy_attachment" "lambda_vpc_access" {
289
303
 
290
304
  # Additional IAM policies for Lambda (if provided)
291
305
  resource "aws_iam_role_policy" "lambda_additional_policies" {
292
- count = length(var.additional_iam_policy_statements) > 0 ? 1 : 0
306
+ count = length(local.lambda_policy_statements) > 0 ? 1 : 0
293
307
  name = "<%- apiNameClassName %>Handler-additional-policies-${random_string.suffix.result}"
294
308
  role = aws_iam_role.lambda_execution_role.id
295
309
 
296
310
  policy = jsonencode({
297
311
  Version = "2012-10-17"
298
- Statement = var.additional_iam_policy_statements
312
+ Statement = local.lambda_policy_statements
299
313
  })
300
314
  }
301
315
 
316
+ locals {
317
+ # Grant read access to the runtime-config AppConfig application when wired
318
+ lambda_policy_statements = concat(var.appconfig_application_arn != null ? [
319
+ {
320
+ Effect = "Allow"
321
+ Action = [
322
+ "appconfig:StartConfigurationSession",
323
+ "appconfig:GetLatestConfiguration"
324
+ ]
325
+ Resource = ["${var.appconfig_application_arn}/*"]
326
+ }
327
+ ] : [], var.additional_iam_policy_statements)
328
+ }
329
+
302
330
  # CloudWatch Log Group for Lambda
303
331
  resource "aws_cloudwatch_log_group" "lambda_logs" {
304
332
  #checkov:skip=CKV_AWS_158:Using default CloudWatch log encryption