@aws/nx-plugin 1.0.0-rc.76 → 1.0.0-rc.78

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/migrations.json +16 -1
  2. package/package.json +1 -1
  3. package/src/migrations/latest/dynamodb-configurable-encryption/__snapshots__/migration.spec.ts.snap +429 -0
  4. package/src/migrations/latest/dynamodb-configurable-encryption/metadata.json +3 -0
  5. package/src/migrations/latest/dynamodb-configurable-encryption/migration.d.ts +6 -0
  6. package/src/migrations/latest/dynamodb-configurable-encryption/migration.js +325 -0
  7. package/src/migrations/latest/dynamodb-configurable-encryption/migration.js.map +1 -0
  8. package/src/migrations/latest/static-website-configurable-waf-encryption/metadata.json +3 -0
  9. package/src/migrations/latest/static-website-configurable-waf-encryption/migration.d.ts +6 -0
  10. package/src/migrations/latest/static-website-configurable-waf-encryption/migration.js +418 -0
  11. package/src/migrations/latest/static-website-configurable-waf-encryption/migration.js.map +1 -0
  12. package/src/migrations/latest/user-identity-configurable-mfa/metadata.json +3 -0
  13. package/src/migrations/latest/user-identity-configurable-mfa/migration.d.ts +6 -0
  14. package/src/migrations/latest/user-identity-configurable-mfa/migration.js +362 -0
  15. package/src/migrations/latest/user-identity-configurable-mfa/migration.js.map +1 -0
  16. package/src/py/dynamodb/__snapshots__/generator.spec.ts.snap +90 -9
  17. package/src/ts/dynamodb/__snapshots__/generator.spec.ts.snap +90 -9
  18. package/src/ts/react-website/app/__snapshots__/generator.spec.ts.snap +259 -48
  19. package/src/ts/react-website/cognito-auth/__snapshots__/generator.spec.ts.snap +37 -7
  20. package/src/ts/react-website/cognito-auth/__snapshots__/generator.terraform.spec.ts.snap +26 -0
  21. package/src/utils/dynamodb-constructs/files/cdk/core/dynamodb.ts.template +23 -3
  22. package/src/utils/dynamodb-constructs/files/terraform/app/dynamodb/__nameKebabCase__/__nameKebabCase__.tf.template +27 -1
  23. package/src/utils/dynamodb-constructs/files/terraform/core/dynamodb/dynamodb.tf.template +39 -5
  24. package/src/utils/identity-constructs/files/cdk/core/user-identity.ts.template +41 -7
  25. package/src/utils/identity-constructs/files/terraform/core/user-identity/identity/identity.tf.template +48 -13
  26. package/src/utils/identity-constructs/files/terraform/core/user-identity/main.tf.template +26 -0
  27. package/src/utils/website-constructs/files/cdk/app/static-websites/__websiteNameKebabCase__.ts.template +11 -2
  28. package/src/utils/website-constructs/files/cdk/core/static-website.ts.template +47 -10
  29. package/src/utils/website-constructs/files/terraform/app/static-websites/__websiteNameKebabCase__/__websiteNameKebabCase__.tf.template +55 -0
  30. package/src/utils/website-constructs/files/terraform/core/static-website/static-website.tf.template +57 -15
@@ -63,8 +63,31 @@ variable "deletion_protection_enabled" {
63
63
  default = true
64
64
  }
65
65
 
66
+ variable "encryption" {
67
+ description = "Server-side encryption for the table. One of CUSTOMER_MANAGED, AWS_MANAGED or DEFAULT (the AWS owned key, at no cost and with no key to manage). Changing this on an already-deployed table away from CUSTOMER_MANAGED requires a manual step first - see the ts#dynamodb generator's docs."
68
+ type = string
69
+ default = "CUSTOMER_MANAGED"
70
+
71
+ validation {
72
+ condition = contains(["CUSTOMER_MANAGED", "AWS_MANAGED", "DEFAULT"], var.encryption)
73
+ error_message = "encryption must be one of CUSTOMER_MANAGED, AWS_MANAGED or DEFAULT."
74
+ }
75
+ }
76
+
77
+ variable "kms_key_arn" {
78
+ description = "ARN of an existing KMS key used to encrypt the table when encryption is CUSTOMER_MANAGED. When not provided and create_kms_key is true, a new key is created. Note that a customer-supplied key must already grant the DynamoDB service the necessary permissions in its own key policy."
79
+ type = string
80
+ default = null
81
+ }
82
+
83
+ variable "create_kms_key" {
84
+ description = "Whether to create a KMS key for the table. Only applies when encryption is CUSTOMER_MANAGED. Set to false when supplying kms_key_arn."
85
+ type = bool
86
+ default = true
87
+ }
88
+
66
89
  variable "enable_key_rotation" {
67
- description = "Whether to enable automatic key rotation on the KMS key used to encrypt the table."
90
+ description = "Whether to enable automatic key rotation on the KMS key used to encrypt the table. Only applies when encryption is CUSTOMER_MANAGED and create_kms_key is true."
68
91
  type = bool
69
92
  default = true
70
93
  }
@@ -84,12 +107,22 @@ locals {
84
107
  gsi_attribute_names = distinct(flatten([
85
108
  for gsi in var.global_secondary_indexes : [gsi.hash_key, gsi.range_key]
86
109
  ]))
110
+
111
+ create_table_key = var.encryption == "CUSTOMER_MANAGED" && var.create_kms_key
112
+ table_kms_key_arn = (
113
+ var.encryption == "CUSTOMER_MANAGED" ? (local.create_table_key ? aws_kms_key.table[0].arn : var.kms_key_arn) :
114
+ var.encryption == "AWS_MANAGED" ? "arn:\${data.aws_partition.current.partition}:kms:\${data.aws_region.current.region}:\${data.aws_caller_identity.current.account_id}:alias/aws/dynamodb" :
115
+ null
116
+ )
87
117
  }
88
118
 
89
119
  data "aws_caller_identity" "current" {}
90
120
  data "aws_partition" "current" {}
121
+ data "aws_region" "current" {}
91
122
 
92
123
  resource "aws_kms_key" "table" {
124
+ count = local.create_table_key ? 1 : 0
125
+
93
126
  description = "KMS key for DynamoDB table \${var.name}"
94
127
  enable_key_rotation = var.enable_key_rotation
95
128
 
@@ -126,6 +159,7 @@ resource "aws_kms_key" "table" {
126
159
  }
127
160
 
128
161
  resource "aws_dynamodb_table" "table" {
162
+ #checkov:skip=CKV_AWS_119:Encryption is configurable via var.encryption; checkov cannot resolve the conditional server_side_encryption.enabled expression
129
163
  name = var.name
130
164
  billing_mode = var.billing_mode
131
165
  hash_key = "pk"
@@ -165,8 +199,8 @@ resource "aws_dynamodb_table" "table" {
165
199
  }
166
200
 
167
201
  server_side_encryption {
168
- enabled = true
169
- kms_key_arn = aws_kms_key.table.arn
202
+ enabled = var.encryption != "DEFAULT"
203
+ kms_key_arn = local.table_kms_key_arn
170
204
  }
171
205
  }
172
206
 
@@ -181,8 +215,8 @@ output "table_arn" {
181
215
  }
182
216
 
183
217
  output "kms_key_arn" {
184
- description = "ARN of the KMS key used to encrypt the DynamoDB table."
185
- value = aws_kms_key.table.arn
218
+ description = "ARN of the KMS key used to encrypt the DynamoDB table, or null when using the AWS owned key (encryption = DEFAULT)."
219
+ value = local.table_kms_key_arn
186
220
  }
187
221
  "
188
222
  `;
@@ -219,8 +253,31 @@ variable "deletion_protection_enabled" {
219
253
  default = true
220
254
  }
221
255
 
256
+ variable "encryption" {
257
+ description = "Server-side encryption for the table. One of CUSTOMER_MANAGED, AWS_MANAGED or DEFAULT (the AWS owned key, at no cost and with no key to manage). Changing this on an already-deployed table away from CUSTOMER_MANAGED requires a manual step first - see the ts#dynamodb generator's docs."
258
+ type = string
259
+ default = "CUSTOMER_MANAGED"
260
+
261
+ validation {
262
+ condition = contains(["CUSTOMER_MANAGED", "AWS_MANAGED", "DEFAULT"], var.encryption)
263
+ error_message = "encryption must be one of CUSTOMER_MANAGED, AWS_MANAGED or DEFAULT."
264
+ }
265
+ }
266
+
267
+ variable "kms_key_arn" {
268
+ description = "ARN of an existing KMS key used to encrypt the table when encryption is CUSTOMER_MANAGED. When not provided and create_kms_key is true, a new key is created. Note that a customer-supplied key must already grant the DynamoDB service the necessary permissions in its own key policy."
269
+ type = string
270
+ default = null
271
+ }
272
+
273
+ variable "create_kms_key" {
274
+ description = "Whether to create a KMS key for the table. Only applies when encryption is CUSTOMER_MANAGED. Set to false when supplying kms_key_arn."
275
+ type = bool
276
+ default = true
277
+ }
278
+
222
279
  variable "enable_key_rotation" {
223
- description = "Whether to enable automatic key rotation on the KMS key used to encrypt the table."
280
+ description = "Whether to enable automatic key rotation on the KMS key used to encrypt the table. Only applies when encryption is CUSTOMER_MANAGED and create_kms_key is true."
224
281
  type = bool
225
282
  default = true
226
283
  }
@@ -247,6 +304,9 @@ module "dynamodb_table" {
247
304
  billing_mode = var.billing_mode
248
305
  point_in_time_recovery_enabled = var.point_in_time_recovery_enabled
249
306
  deletion_protection_enabled = var.deletion_protection_enabled
307
+ encryption = var.encryption
308
+ kms_key_arn = var.kms_key_arn
309
+ create_kms_key = var.create_kms_key
250
310
  enable_key_rotation = var.enable_key_rotation
251
311
  global_secondary_indexes = local.global_secondary_indexes
252
312
  }
@@ -747,7 +807,7 @@ import {
747
807
  } from 'aws-cdk-lib/aws-dynamodb';
748
808
  import { RemovalPolicy } from 'aws-cdk-lib';
749
809
  import { Grant, IGrantable } from 'aws-cdk-lib/aws-iam';
750
- import { Key } from 'aws-cdk-lib/aws-kms';
810
+ import { IKey, Key } from 'aws-cdk-lib/aws-kms';
751
811
  import { RuntimeConfig } from './runtime-config.js';
752
812
 
753
813
  type _DynamoDBTableProps = Omit<
@@ -767,8 +827,23 @@ export interface DynamoDBTableProps extends _DynamoDBTableProps {
767
827
  */
768
828
  readonly runtimeConfigKey: string;
769
829
 
830
+ /**
831
+ * Server-side encryption for the table.
832
+ *
833
+ * @default TableEncryption.CUSTOMER_MANAGED
834
+ */
835
+ readonly encryption?: TableEncryption;
836
+
837
+ /**
838
+ * KMS key used to encrypt the table. Only used when \`encryption\` is
839
+ * \`TableEncryption.CUSTOMER_MANAGED\`. When not provided, a new key is created.
840
+ */
841
+ readonly encryptionKey?: IKey;
842
+
770
843
  /**
771
844
  * Whether to enable automatic key rotation on the KMS key used to encrypt the table.
845
+ * Only applies when \`encryption\` is \`TableEncryption.CUSTOMER_MANAGED\` and no
846
+ * \`encryptionKey\` is supplied.
772
847
  *
773
848
  * @default true
774
849
  */
@@ -788,13 +863,19 @@ export abstract class DynamoDBTable extends Construct {
788
863
  pointInTimeRecoverySpecification = { pointInTimeRecoveryEnabled: true },
789
864
  deletionProtection = true,
790
865
  removalPolicy = RemovalPolicy.RETAIN,
866
+ encryption = TableEncryption.CUSTOMER_MANAGED,
867
+ encryptionKey,
791
868
  enableKeyRotation = true,
792
869
  ...rest
793
870
  }: DynamoDBTableProps,
794
871
  ) {
795
872
  super(scope, id);
796
873
 
797
- const key = new Key(this, 'EncryptionKey', { enableKeyRotation });
874
+ const key: IKey | undefined =
875
+ encryption === TableEncryption.CUSTOMER_MANAGED
876
+ ? (encryptionKey ??
877
+ new Key(this, 'EncryptionKey', { enableKeyRotation }))
878
+ : undefined;
798
879
 
799
880
  this.table = new Table(this, runtimeConfigKey, {
800
881
  ...rest,
@@ -805,7 +886,7 @@ export abstract class DynamoDBTable extends Construct {
805
886
  pointInTimeRecoverySpecification,
806
887
  deletionProtection,
807
888
  encryptionKey: key,
808
- encryption: TableEncryption.CUSTOMER_MANAGED,
889
+ encryption,
809
890
  removalPolicy,
810
891
  });
811
892