@cdkd/cli 0.334.2 → 0.335.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.
Files changed (37) hide show
  1. package/dist/ambient-client-defaults-B9bnuob2.js +960 -0
  2. package/dist/ambient-client-defaults-B9bnuob2.js.map +1 -0
  3. package/dist/{asg-provider-DTZ_iFWa.js → asg-provider-pl5tnbiA.js} +4 -3
  4. package/dist/asg-provider-pl5tnbiA.js.map +1 -0
  5. package/dist/cli.js +2 -2
  6. package/dist/{db-instance-modify-retry-zm23duXt.js → db-instance-modify-retry-CD7NSyq4.js} +10 -9
  7. package/dist/{db-instance-modify-retry-zm23duXt.js.map → db-instance-modify-retry-CD7NSyq4.js.map} +1 -1
  8. package/dist/{deploy-engine-Dq_RyFZd.js → deploy-engine-iQpILlcZ.js} +13365 -13039
  9. package/dist/deploy-engine-iQpILlcZ.js.map +1 -0
  10. package/dist/{iam-role-provider-DwAhjMfG.js → iam-role-provider-jC3_bsf-.js} +4 -3
  11. package/dist/iam-role-provider-jC3_bsf-.js.map +1 -0
  12. package/dist/index.d.ts +34 -42
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +3 -3
  15. package/dist/{neptune-provider-BFDPuF1_.js → neptune-provider-CNEMvt4t.js} +69 -24
  16. package/dist/neptune-provider-CNEMvt4t.js.map +1 -0
  17. package/dist/{program-Be87SvBg.js → program-DaGdaozO.js} +901 -731
  18. package/dist/program-DaGdaozO.js.map +1 -0
  19. package/dist/{provider-classes-D0isRHVc.js → provider-classes-ZpRORGt2.js} +45 -20
  20. package/dist/provider-classes-ZpRORGt2.js.map +1 -0
  21. package/dist/{rds-provider-CYwGhhxE.js → rds-provider-Ce7ua-ww.js} +289 -31
  22. package/dist/rds-provider-Ce7ua-ww.js.map +1 -0
  23. package/dist/read-replica-BJAUZwWe.js +201 -0
  24. package/dist/read-replica-BJAUZwWe.js.map +1 -0
  25. package/dist/{update-removal-C_x1-FM4.js → update-removal-Dh6W86TO.js} +148 -1097
  26. package/dist/update-removal-Dh6W86TO.js.map +1 -0
  27. package/dist/{version-CagOv0Ke.js → version-BxcTCG5i.js} +2 -2
  28. package/dist/{version-CagOv0Ke.js.map → version-BxcTCG5i.js.map} +1 -1
  29. package/package.json +1 -1
  30. package/dist/asg-provider-DTZ_iFWa.js.map +0 -1
  31. package/dist/deploy-engine-Dq_RyFZd.js.map +0 -1
  32. package/dist/iam-role-provider-DwAhjMfG.js.map +0 -1
  33. package/dist/neptune-provider-BFDPuF1_.js.map +0 -1
  34. package/dist/program-Be87SvBg.js.map +0 -1
  35. package/dist/provider-classes-D0isRHVc.js.map +0 -1
  36. package/dist/rds-provider-CYwGhhxE.js.map +0 -1
  37. package/dist/update-removal-C_x1-FM4.js.map +0 -1
@@ -1,14 +1,15 @@
1
1
  import { $ as safeMsg, n as describeAwsFailure, s as getLogger, y as generatedNameFor } from "./aws-failure-text-CoS1huLy.js";
2
- import { $n as markNonRetryable, B as resolveExplicitPhysicalId, En as ResourceUpdateNotSupportedError, Ft as maskerOrIdentity, Gt as markAuxiliaryFailure, H as assertRegionMatch, I as normalizeAwsTagsToCfn, It as withDerivedNameMasks, J as deleteAfterProtectionFlipWithFinalSnapshot, K as ProtectionFlipRegistry, Kt as markCreatedBeforeFailure, Ln as relayedNameCollision, Q as isTerminalDbWaitStatus, V as RESOURCE_NOT_FOUND, W as markNotGone, Y as deleteWithProtectionCompensation, a as withRemovalDefaults, cr as CdkdError, dt as pasteableAwsCommand, er as markRedactedCause, f as retractCreatedResource, fn as ambientClientDefaults, ft as protectedReplacementAdvice, j as withoutServerErrorRetries, jt as createMaskedLogSinks, nt as protectionFlipKey, pr as ProvisioningError, rt as rdsFamilyProtectionSite, t as clearOnUpdateRemoval, tr as wrapMaskedAwsError, tt as observeThenDisableProtection, u as reportCreatedResource } from "./update-removal-C_x1-FM4.js";
2
+ import { E as relayedNameCollision, H as markNonRetryable, U as markRedactedCause, W as wrapMaskedAwsError, Z as CdkdError, h as ResourceUpdateNotSupportedError, nt as ProvisioningError, t as ambientClientDefaults } from "./ambient-client-defaults-B9bnuob2.js";
3
3
  import { c as ambientRegion } from "./aws-client-defaults-BLXFsfMa.js";
4
- import { Ac as dbInstanceEngineChangeIsInPlace, Gi as stringifyIfAssigned, Ji as planTagDiff, Qi as tagPlanWarning, St as enclosingDeadlineRemainingMs, Wi as definedAttributes, Xi as refuseMalformedDesiredTags, ea as markDeleteStarted, xl as dynamicReferenceTokens, ya as slowCcOperationTimeoutMs } from "./deploy-engine-Dq_RyFZd.js";
5
- import { a as associatedRoleList, c as canonicalAssociatedRoles, i as associatedRoleKey, l as isRoleCallNotAvailableRefusal, n as modifyDbInstanceWhenAvailable, o as associatedRolesNamed, r as associatedRoleArns, s as associatedRolesReadback, t as isModifyNotAvailableRefusal, u as planAssociatedRoleChanges } from "./db-instance-modify-retry-zm23duXt.js";
4
+ import { $i as tagPlanWarning, Gi as definedAttributes, Ki as stringifyIfAssigned, Nt as enclosingDeadlineRemainingMs, Sl as dynamicReferenceTokens, Yi as planTagDiff, Zi as refuseMalformedDesiredTags, ba as slowCcOperationTimeoutMs, jc as dbInstanceEngineChangeIsInPlace, ta as markDeleteStarted } from "./deploy-engine-iQpILlcZ.js";
5
+ import { $ as deleteAfterProtectionFlipWithFinalSnapshot, B as resolveExplicitPhysicalId, H as assertRegionMatch, I as normalizeAwsTagsToCfn, It as maskerOrIdentity, J as observeThenDisableProtection, K as deleteWithProtectionCompensation, Kt as markAuxiliaryFailure, Lt as withDerivedNameMasks, Mt as createMaskedLogSinks, Q as PROTECTION_FLIP_RETRY_WAIT_MS, V as RESOURCE_NOT_FOUND, W as markNotGone, Y as rdsFamilyProtectionSite, a as withRemovalDefaults, f as retractCreatedResource, gt as protectedReplacementAdvice, ht as pasteableAwsCommand, it as ProtectionFlipRegistry, j as withoutServerErrorRetries, nt as isTerminalDbWaitStatus, ot as protectionFlipKey, qt as markCreatedBeforeFailure, t as clearOnUpdateRemoval, u as reportCreatedResource } from "./update-removal-Dh6W86TO.js";
6
+ import { a as associatedRoleList, c as canonicalAssociatedRoles, i as associatedRoleKey, l as isRoleCallNotAvailableRefusal, n as modifyDbInstanceWhenAvailable, o as associatedRolesNamed, r as associatedRoleArns, s as associatedRolesReadback, t as isModifyNotAvailableRefusal, u as planAssociatedRoleChanges } from "./db-instance-modify-retry-CD7NSyq4.js";
7
+ import { a as refuseMalformedReplicaSource, c as replicaModifyAfterCreateInput, d as replicaSourceOf, f as sameReplicaSource, l as replicaNeedsModifyAfterCreate, n as isLiveReadReplica, o as replicaCreateInput, p as withPreviousReplicaSource, r as ownScopeOf, s as replicaEngine, t as describeReplicaSource, u as replicaSourceChange } from "./read-replica-BJAUZwWe.js";
6
8
  import { DescribeSecurityGroupsCommand, EC2Client } from "@aws-sdk/client-ec2";
7
9
  import { isDeepStrictEqual } from "node:util";
8
- import { AddRoleToDBClusterCommand, AddRoleToDBInstanceCommand, AddTagsToResourceCommand, CreateDBClusterCommand, CreateDBInstanceCommand, CreateDBSubnetGroupCommand, DeleteDBClusterCommand, DeleteDBInstanceCommand, DeleteDBSubnetGroupCommand, DescribeDBClustersCommand, DescribeDBInstancesCommand, DescribeDBSubnetGroupsCommand, DescribeGlobalClustersCommand, DisableHttpEndpointCommand, EnableHttpEndpointCommand, ListTagsForResourceCommand, ModifyDBClusterCommand, ModifyDBInstanceCommand, ModifyDBSubnetGroupCommand, RDSClient, RebootDBInstanceCommand, RemoveFromGlobalClusterCommand, RemoveRoleFromDBClusterCommand, RemoveRoleFromDBInstanceCommand, RemoveTagsFromResourceCommand } from "@aws-sdk/client-rds";
10
+ import { AddRoleToDBClusterCommand, AddRoleToDBInstanceCommand, AddTagsToResourceCommand, CreateDBClusterCommand, CreateDBInstanceCommand, CreateDBInstanceReadReplicaCommand, CreateDBSubnetGroupCommand, DeleteDBClusterCommand, DeleteDBInstanceCommand, DeleteDBSubnetGroupCommand, DescribeDBClustersCommand, DescribeDBInstancesCommand, DescribeDBSubnetGroupsCommand, DescribeGlobalClustersCommand, DisableHttpEndpointCommand, EnableHttpEndpointCommand, ListTagsForResourceCommand, ModifyDBClusterCommand, ModifyDBInstanceCommand, ModifyDBSubnetGroupCommand, PromoteReadReplicaCommand, RDSClient, RebootDBInstanceCommand, RemoveFromGlobalClusterCommand, RemoveRoleFromDBClusterCommand, RemoveRoleFromDBInstanceCommand, RemoveTagsFromResourceCommand } from "@aws-sdk/client-rds";
9
11
 
10
12
  // src/provisioning/providers/rds/shared.ts
11
- const PROTECTION_FLIP_RETRY_WAIT_MS = 6e5;
12
13
  const RDS_DELETE_WAIT_MS = Math.max(18e5, slowCcOperationTimeoutMs("AWS::RDS::DBCluster", "DELETE"), slowCcOperationTimeoutMs("AWS::RDS::DBInstance", "DELETE"));
13
14
  function deleteAutomatedBackupsInput(properties) {
14
15
  const value = properties?.["DeleteAutomatedBackups"];
@@ -405,6 +406,68 @@ function clusterModifyBackfillMembers(properties, previousProperties, context) {
405
406
  if (changed("CopyTagsToSnapshot")) members.CopyTagsToSnapshot = properties["CopyTagsToSnapshot"];
406
407
  return members;
407
408
  }
409
+ function clusterSizeValue(value) {
410
+ return retentionPeriodValue(value);
411
+ }
412
+ function malformedInstanceClass(value) {
413
+ return value != null && typeof value !== "string";
414
+ }
415
+ const usableInstanceClass = (value) => typeof value === "string";
416
+ const usableClusterSize = (value) => typeof clusterSizeValue(value) === "number";
417
+ function clusterCreateMultiAzMembers(properties) {
418
+ const members = {};
419
+ const instanceClass = properties["DBClusterInstanceClass"];
420
+ if (typeof instanceClass === "string") members.DBClusterInstanceClass = instanceClass;
421
+ const allocated = clusterSizeValue(properties["AllocatedStorage"]);
422
+ if (typeof allocated === "number") members.AllocatedStorage = allocated;
423
+ const iops = clusterSizeValue(properties["Iops"]);
424
+ if (typeof iops === "number") members.Iops = iops;
425
+ return members;
426
+ }
427
+ function clusterModifyMultiAzMembers(properties, previousProperties, context, onShrinkSkipped = () => {}) {
428
+ const changed = (key) => instanceValueChanged(properties, previousProperties, key, context);
429
+ const members = {};
430
+ const instanceClass = properties["DBClusterInstanceClass"];
431
+ if (typeof instanceClass === "string" && changed("DBClusterInstanceClass")) members.DBClusterInstanceClass = instanceClass;
432
+ const allocated = clusterSizeValue(properties["AllocatedStorage"]);
433
+ const previousAllocated = clusterSizeValue(previousProperties["AllocatedStorage"]);
434
+ const shrinkSkipped = (context?.replayingState === true || context?.desiredFromAwsReadback === true) && changed("AllocatedStorage") && typeof allocated === "number" && typeof previousAllocated === "number" && allocated < previousAllocated;
435
+ if (shrinkSkipped) onShrinkSkipped(allocated, previousAllocated);
436
+ if (changed("AllocatedStorage") && !shrinkSkipped || changed("Iops") || changed("StorageType")) {
437
+ if (shrinkSkipped) members.AllocatedStorage = previousAllocated;
438
+ else if (typeof allocated === "number") members.AllocatedStorage = allocated;
439
+ const iops = clusterSizeValue(properties["Iops"]);
440
+ if (typeof iops === "number") members.Iops = iops;
441
+ }
442
+ return members;
443
+ }
444
+ function multiAzSettledStatuses(fullWait) {
445
+ return new Set(fullWait ? ["available"] : ["available", "storage-optimization"]);
446
+ }
447
+ function multiAzReadState(cluster, sent, fullWait) {
448
+ if (sent.DBClusterInstanceClass === void 0 && sent.AllocatedStorage === void 0 && sent.Iops === void 0) return "applied";
449
+ if (!multiAzSettledStatuses(fullWait).has(cluster.Status ?? "")) return "pending";
450
+ if (sent.DBClusterInstanceClass !== void 0 && cluster.DBClusterInstanceClass !== sent.DBClusterInstanceClass) return "pending";
451
+ if (sent.AllocatedStorage === void 0 && sent.Iops === void 0) return "applied";
452
+ if (sent.AllocatedStorage !== void 0 && cluster.AllocatedStorage !== sent.AllocatedStorage) return "pending";
453
+ const pending = cluster.PendingModifiedValues;
454
+ if (pending?.AllocatedStorage !== void 0 || pending?.Iops !== void 0 || pending?.StorageType !== void 0) return "pending";
455
+ if (sent.Iops === void 0 || cluster.Iops === sent.Iops) return "applied";
456
+ return ["io1", "io2"].includes(cluster.StorageType?.toLowerCase() ?? "") ? "pending" : "iops-unconfirmed";
457
+ }
458
+ const MULTI_AZ_IOPS_CONFIRM_READS = 3;
459
+ function multiAzAppliedProbe(sent, fullWait) {
460
+ let unconfirmedReads = 0;
461
+ return (cluster) => {
462
+ const state = multiAzReadState(cluster, sent, fullWait);
463
+ if (state !== "iops-unconfirmed") {
464
+ unconfirmedReads = 0;
465
+ return state === "applied";
466
+ }
467
+ unconfirmedReads += 1;
468
+ return unconfirmedReads >= 3;
469
+ };
470
+ }
408
471
  const CLUSTER_PERFORMANCE_INSIGHTS_MEMBERS = [
409
472
  ["PerformanceInsightsEnabled", "EnablePerformanceInsights"],
410
473
  ["PerformanceInsightsKmsKeyId", "PerformanceInsightsKMSKeyId"],
@@ -547,6 +610,9 @@ async function createDBCluster(logicalId, resourceType, properties, mask, replay
547
610
  const availabilityZones = rawAvailabilityZones != null && !availabilityZonesSkipped ? rawAvailabilityZones : void 0;
548
611
  const globalClusterSkipped = !readableGlobalClusterId(properties["GlobalClusterIdentifier"]);
549
612
  const globalClusterId = globalClusterSkipped ? void 0 : recordedGlobalClusterIdentifier(properties);
613
+ const classSkipped = malformedInstanceClass(properties["DBClusterInstanceClass"]);
614
+ const allocatedSkipped = clusterSizeValue(properties["AllocatedStorage"]) === "malformed";
615
+ const iopsSkipped = clusterSizeValue(properties["Iops"]) === "malformed";
550
616
  for (const [skipped, key, expected, created] of [
551
617
  [
552
618
  backtrackSkipped,
@@ -566,6 +632,24 @@ async function createDBCluster(logicalId, resourceType, properties, mask, replay
566
632
  "a string",
567
633
  "no global cluster"
568
634
  ],
635
+ [
636
+ classSkipped,
637
+ "DBClusterInstanceClass",
638
+ "a string",
639
+ "no instance class sent"
640
+ ],
641
+ [
642
+ allocatedSkipped,
643
+ "AllocatedStorage",
644
+ "a whole number of GiB",
645
+ "no storage size sent"
646
+ ],
647
+ [
648
+ iopsSkipped,
649
+ "Iops",
650
+ "a whole number",
651
+ "no IOPS sent"
652
+ ],
569
653
  [
570
654
  availabilityZonesSkipped,
571
655
  "AvailabilityZones",
@@ -585,7 +669,10 @@ async function createDBCluster(logicalId, resourceType, properties, mask, replay
585
669
  ...backtrackSkipped ? ["BacktrackWindow"] : [],
586
670
  ...forwardingSkipped ? ["EnableLocalWriteForwarding"] : [],
587
671
  ...availabilityZonesSkipped ? ["AvailabilityZones"] : [],
588
- ...globalClusterSkipped ? ["GlobalClusterIdentifier"] : []
672
+ ...globalClusterSkipped ? ["GlobalClusterIdentifier"] : [],
673
+ ...classSkipped ? ["DBClusterInstanceClass"] : [],
674
+ ...allocatedSkipped ? ["AllocatedStorage"] : [],
675
+ ...iopsSkipped ? ["Iops"] : []
589
676
  ];
590
677
  const effectiveProperties = skippedKeys.length > 0 ? Object.fromEntries(Object.entries(properties).filter(([key]) => !skippedKeys.includes(key))) : void 0;
591
678
  const logExports = desiredLogExports(properties, resourceType, logicalId);
@@ -617,6 +704,7 @@ async function createDBCluster(logicalId, resourceType, properties, mask, replay
617
704
  ...properties["PubliclyAccessible"] !== void 0 && { PubliclyAccessible: properties["PubliclyAccessible"] },
618
705
  ...serverlessV2Config && { ServerlessV2ScalingConfiguration: serverlessV2ScalingToSend(serverlessV2Config) },
619
706
  ...clusterCreateBackfillMembers(properties),
707
+ ...clusterCreateMultiAzMembers(properties),
620
708
  ...logExports !== void 0 && logExports.length > 0 && { EnableCloudwatchLogsExports: logExports },
621
709
  ...clusterCreateScalarMembers(properties),
622
710
  ...httpEndpoint !== void 0 && { EnableHttpEndpoint: httpEndpoint },
@@ -763,17 +851,38 @@ async function updateDBCluster(logicalId, physicalId, resourceType, properties,
763
851
  this.logger.warn(safeMsg`DBCluster ${logicalId}: the replayed AvailabilityZones is not a list of Availability Zone names; the record keeps the previous list`);
764
852
  skippedKeys.push(["AvailabilityZones", usableAvailabilityZones]);
765
853
  }
766
- for (const [malformed, key, expected, usable] of [[
767
- backtrackWindowValue(properties["BacktrackWindow"]) === "malformed",
768
- "BacktrackWindow",
769
- "a whole number of seconds",
770
- usableBacktrackWindow
771
- ], [
772
- localWriteForwardingFlag(properties["EnableLocalWriteForwarding"]) === "malformed",
773
- "EnableLocalWriteForwarding",
774
- "true or false",
775
- usableLocalWriteForwarding
776
- ]]) {
854
+ for (const [malformed, key, expected, usable] of [
855
+ [
856
+ backtrackWindowValue(properties["BacktrackWindow"]) === "malformed",
857
+ "BacktrackWindow",
858
+ "a whole number of seconds",
859
+ usableBacktrackWindow
860
+ ],
861
+ [
862
+ localWriteForwardingFlag(properties["EnableLocalWriteForwarding"]) === "malformed",
863
+ "EnableLocalWriteForwarding",
864
+ "true or false",
865
+ usableLocalWriteForwarding
866
+ ],
867
+ [
868
+ malformedInstanceClass(properties["DBClusterInstanceClass"]),
869
+ "DBClusterInstanceClass",
870
+ "a string",
871
+ usableInstanceClass
872
+ ],
873
+ [
874
+ clusterSizeValue(properties["AllocatedStorage"]) === "malformed",
875
+ "AllocatedStorage",
876
+ "a whole number of GiB",
877
+ usableClusterSize
878
+ ],
879
+ [
880
+ clusterSizeValue(properties["Iops"]) === "malformed",
881
+ "Iops",
882
+ "a whole number",
883
+ usableClusterSize
884
+ ]
885
+ ]) {
777
886
  if (!malformed) continue;
778
887
  if (context?.replayingState !== true && context?.desiredFromAwsReadback !== true) throw markNonRetryable(new ProvisioningError(`${resourceType} ${logicalId}: ${key} must be ${expected}`, resourceType, logicalId, physicalId));
779
888
  this.logger.warn(safeMsg`DBCluster ${logicalId}: the replayed ${key} is not ${expected}; the setting is left as it is`);
@@ -807,6 +916,10 @@ async function updateDBCluster(logicalId, physicalId, resourceType, properties,
807
916
  const portToSend = clusterPortToSend(properties, previousProperties);
808
917
  const engineVersionChanged = clusterEngineVersionChanged(properties, previousProperties, context);
809
918
  const scalarMembers = clusterModifyScalarMembers(properties, previousProperties, context);
919
+ const multiAzMembers = clusterModifyMultiAzMembers(properties, previousProperties, context, (desired, previous) => {
920
+ this.logger.warn(safeMsg`DBCluster ${logicalId}: AllocatedStorage stays at ${String(previous)} GiB rather than going back to ${String(desired)} GiB, because RDS cannot shrink storage`);
921
+ skippedKeys.push(["AllocatedStorage", usableClusterSize]);
922
+ });
810
923
  if (globalClusterPlan.kind === "detach") {
811
924
  if (await this.detachFromGlobalCluster(logicalId, physicalId, globalClusterPlan.globalClusterId, {
812
925
  beforeDelete: false,
@@ -833,6 +946,7 @@ async function updateDBCluster(logicalId, physicalId, resourceType, properties,
833
946
  ...hasServerlessV2 && { ServerlessV2ScalingConfiguration: serverlessV2ScalingToSend(serverlessV2Config) },
834
947
  ...clusterModifyBackfillMembers(properties, previousProperties, context),
835
948
  ...scalarMembers,
949
+ ...multiAzMembers,
836
950
  ...engineLifecycleSupport !== void 0 && { EngineLifecycleSupport: engineLifecycleSupport },
837
951
  ...authenticationType !== void 0 && { MasterUserAuthenticationType: authenticationType },
838
952
  ...logExportConfig !== void 0 && { CloudwatchLogsExportConfiguration: logExportConfig },
@@ -858,6 +972,7 @@ async function updateDBCluster(logicalId, physicalId, resourceType, properties,
858
972
  if (!noWait && forwardingSent !== void 0) await this.waitForClusterState(logicalId, physicalId, (cluster) => localWriteForwardingApplied(cluster, forwardingSent), "local write forwarding setting");
859
973
  const backtrackSent = scalarMembers.BacktrackWindow;
860
974
  if (!noWait && backtrackSent !== void 0) await this.waitForClusterState(logicalId, physicalId, (cluster) => cluster.BacktrackWindow === void 0 || cluster.BacktrackWindow === backtrackSent, "backtrack window");
975
+ if (!noWait && Object.keys(multiAzMembers).length > 0) await this.waitForClusterState(logicalId, physicalId, multiAzAppliedProbe(multiAzMembers, process.env["CDKD_FULL_WAIT"] === "true"), "instance class or storage change", slowCcOperationTimeoutMs("AWS::RDS::DBCluster", "UPDATE"));
861
976
  const described = await this.describeDBCluster(physicalId);
862
977
  if (httpEndpointAction === "enable" || httpEndpointAction === "disable") {
863
978
  const arn = described?.DBClusterArn;
@@ -1183,12 +1298,14 @@ async function createDBInstance(logicalId, resourceType, properties, mask, repla
1183
1298
  const tags = refuseMalformedDesiredTags(properties["Tags"], resourceType, logicalId);
1184
1299
  const roles = this.desiredAssociatedRoles(properties, resourceType, logicalId, void 0, replaying);
1185
1300
  const logExports = desiredLogExports(properties, resourceType, logicalId);
1301
+ refuseMalformedReplicaSource(properties, resourceType, logicalId);
1302
+ const replicaSource = replicaSourceOf(properties);
1186
1303
  const dbInstanceIdentifier = properties["DBInstanceIdentifier"] || generatedNameFor("AWS::RDS::DBInstance", logicalId);
1187
1304
  let instanceCreated = false;
1188
1305
  let createdResourceId;
1189
1306
  try {
1190
1307
  const masterUserSecret = properties["MasterUserSecret"];
1191
- const response = await this.getCreateClient().send(new CreateDBInstanceCommand({
1308
+ const standaloneCreate = () => new CreateDBInstanceCommand({
1192
1309
  DBInstanceIdentifier: dbInstanceIdentifier,
1193
1310
  DBInstanceClass: properties["DBInstanceClass"],
1194
1311
  Engine: properties["Engine"],
@@ -1238,13 +1355,25 @@ async function createDBInstance(logicalId, resourceType, properties, mask, repla
1238
1355
  ...properties["DBName"] != null && { DBName: properties["DBName"] },
1239
1356
  ...properties["AvailabilityZone"] != null && { AvailabilityZone: properties["AvailabilityZone"] },
1240
1357
  ...tags.length > 0 && { Tags: tags }
1241
- }));
1358
+ });
1359
+ const replicaEngineName = replicaSource === void 0 ? void 0 : await replicaEngine.call(this, properties, replicaSource);
1360
+ const response = replicaSource === void 0 ? await this.getCreateClient().send(standaloneCreate()) : await createReadReplicaWhenSourceAvailable.call(this, logicalId, replicaSource, new CreateDBInstanceReadReplicaCommand(replicaCreateInput(properties, {
1361
+ identifier: dbInstanceIdentifier,
1362
+ source: replicaSource,
1363
+ engine: replicaEngineName,
1364
+ currentRegion: await this.getClient().config.region(),
1365
+ tags,
1366
+ logExports
1367
+ })));
1242
1368
  instanceCreated = true;
1243
1369
  createdResourceId = response.DBInstance?.DbiResourceId;
1244
1370
  reportCreatedResource(logicalId, resourceType, dbInstanceIdentifier, createdResourceId);
1245
- if (!response.DBInstance) throw new Error("CreateDBInstance did not return DBInstance");
1371
+ const instance = response.DBInstance;
1372
+ if (!instance) throw new Error(`${replicaSource === void 0 ? "CreateDBInstance" : "CreateDBInstanceReadReplica"} did not return DBInstance`);
1246
1373
  this.logger.debug(`Successfully created DBInstance ${logicalId}: ${dbInstanceIdentifier}`);
1247
- if (process.env["CDKD_NO_WAIT"] !== "true") await this.waitForInstanceAvailable(logicalId, dbInstanceIdentifier);
1374
+ const modifyAfterCreate = replicaSource !== void 0 && replicaNeedsModifyAfterCreate(properties, replicaEngineName, instance.Engine);
1375
+ if (process.env["CDKD_NO_WAIT"] !== "true" || modifyAfterCreate) await this.waitForInstanceAvailable(logicalId, dbInstanceIdentifier);
1376
+ if (modifyAfterCreate) await modifyReplicaAfterCreate.call(this, logicalId, dbInstanceIdentifier, properties, replicaEngineName);
1248
1377
  if (roles !== "skipped") try {
1249
1378
  await this.applyAssociatedRoles("instance", logicalId, dbInstanceIdentifier, roles, [], mask, void 0);
1250
1379
  } catch (roleError) {
@@ -1267,6 +1396,37 @@ async function createDBInstance(logicalId, resourceType, properties, mask, repla
1267
1396
  throw thrown;
1268
1397
  }
1269
1398
  }
1399
+ async function modifyReplicaAfterCreate(logicalId, dbInstanceIdentifier, properties, engine) {
1400
+ await modifyDbInstanceWhenAvailable({
1401
+ send: () => this.getClient().send(new ModifyDBInstanceCommand(replicaModifyAfterCreateInput(properties, dbInstanceIdentifier, engine))),
1402
+ readStatus: async () => (await this.describeDBInstance(dbInstanceIdentifier))?.DBInstanceStatus,
1403
+ sleep: (ms) => this.sleep(ms),
1404
+ logger: this.logger,
1405
+ label: "RDS DBInstance",
1406
+ logicalId,
1407
+ remainingMs: enclosingDeadlineRemainingMs()
1408
+ });
1409
+ const group = properties["DBParameterGroupName"];
1410
+ if (typeof group === "string" && group !== "") await this.rebootForPendingParameterGroup(logicalId, dbInstanceIdentifier, group, false);
1411
+ else if (process.env["CDKD_NO_WAIT"] !== "true") await this.waitForInstanceAvailable(logicalId, dbInstanceIdentifier, void 0, "being modified after its create");
1412
+ }
1413
+ async function createReadReplicaWhenSourceAvailable(logicalId, source, command) {
1414
+ let response = {};
1415
+ await modifyDbInstanceWhenAvailable({
1416
+ send: async () => {
1417
+ response = await this.getCreateClient().send(command);
1418
+ },
1419
+ readStatus: async () => (await describeReplicaSource.call(this, source))?.DBInstanceStatus,
1420
+ sleep: (ms) => this.sleep(ms),
1421
+ logger: this.logger,
1422
+ label: "RDS DBInstance",
1423
+ logicalId,
1424
+ remainingMs: enclosingDeadlineRemainingMs(),
1425
+ action: "create of the read replica",
1426
+ nounText: "source instance"
1427
+ });
1428
+ return response;
1429
+ }
1270
1430
 
1271
1431
  // src/provisioning/providers/rds/instance-update.ts
1272
1432
  async function updateDBInstance(logicalId, physicalId, resourceType, properties, previousProperties, context) {
@@ -1284,7 +1444,36 @@ async function updateDBInstance(logicalId, physicalId, resourceType, properties,
1284
1444
  passwordCompanion = void 0;
1285
1445
  }
1286
1446
  if (passwordCompanion?.kind === "missing") throw markNonRetryable(new ProvisioningError(passwordAuthenticationMissingText(resourceType, logicalId), resourceType, logicalId, physicalId));
1447
+ refuseMalformedReplicaSource(properties, resourceType, logicalId, physicalId);
1448
+ const sourceChange = replicaSourceChange(properties, previousProperties);
1287
1449
  try {
1450
+ const { mask: sourceMask } = withDerivedNameMasks(this.logger, createMaskedLogSinks(this.logger, context?.maskSecrets), [[previousProperties["DBInstanceIdentifier"], physicalId]]);
1451
+ let sourceKept = sourceChange !== "immutable";
1452
+ let liveSourceRead = "read";
1453
+ if (!sourceKept) {
1454
+ const live = await this.describeDBInstance(physicalId).then((instance) => {
1455
+ if (instance === void 0) liveSourceRead = "not-found";
1456
+ return instance;
1457
+ }, (err) => {
1458
+ liveSourceRead = err?.name === "DBInstanceNotFoundFault" ? "not-found" : "unreadable";
1459
+ this.logger.debug(sourceMask(safeMsg`DBInstance ${logicalId}: could not read the live replica source: ${describeAwsFailure(err).summary}`));
1460
+ });
1461
+ const liveSource = live?.ReadReplicaSourceDBInstanceIdentifier;
1462
+ const desiredSource = replicaSourceOf(properties);
1463
+ sourceKept = liveSource !== void 0 && liveSource !== "" && desiredSource !== void 0 && sameReplicaSource(liveSource, desiredSource, ownScopeOf(live?.DBInstanceArn));
1464
+ }
1465
+ const stateBorne = context?.replayingState === true || context?.desiredFromAwsReadback === true;
1466
+ if (!sourceKept && !stateBorne) throw new ResourceUpdateNotSupportedError(resourceType, logicalId, sourceMask(`SourceDBInstanceIdentifier cannot be added or changed on an existing DB instance — an instance becomes a read replica only when it is created, and CloudFormation refuses the same update ("Resource is immutable"). Removing it promotes the replica instead. Nothing was applied to DB instance ${physicalId}. ` + (liveSourceRead === "not-found" ? "RDS reports no such DB instance: it was deleted outside cdkd, so the state record no longer matches AWS. " : liveSourceRead === "unreadable" ? "cdkd could not read the instance's live replica source (an AWS read failed), so it could not tell whether the instance already replicates the declared source; a re-run may succeed. " : "") + "To keep the instance as it is, declare the source the previous deploy declared (or none, if it declared none). To replace it with a new read replica, " + (String(previousProperties["DeletionProtection"]) === "true" ? protectedReplacementAdvice({
1467
+ evidence: "cdkd's properties for this DB instance carry DeletionProtection: true",
1468
+ replaceFlags: "cdkd deploy --replace --force-stateful-recreation",
1469
+ disable: {
1470
+ before: "aws rds modify-db-instance --db-instance-identifier",
1471
+ identifier: physicalId,
1472
+ after: "--no-deletion-protection --apply-immediately",
1473
+ maskSecrets: sourceMask
1474
+ }
1475
+ }) : "note AWS::RDS::DBInstance is a stateful type: re-run with cdkd deploy --replace --force-stateful-recreation (this deletes the instance and its data). The replace flags apply to the WHOLE deploy, so run them with nothing else pending")));
1476
+ if (!sourceKept) this.logger.warn(sourceMask(safeMsg`DBInstance ${logicalId} (${physicalId}): SourceDBInstanceIdentifier cannot be ` + safeMsg`added or changed in place (an instance becomes a read replica only when it is ` + safeMsg`created), so the instance keeps its current replication and cdkd records that.`));
1288
1477
  const { mask: zoneMask } = withDerivedNameMasks(this.logger, createMaskedLogSinks(this.logger, context?.maskSecrets), [[previousProperties["DBInstanceIdentifier"], physicalId]]);
1289
1478
  const desiredZone = properties["AvailabilityZone"];
1290
1479
  let zoneKept = context?.desiredFromAwsReadback === true || context?.replayingState === true && (desiredZone == null || desiredZone === "") || instanceAvailabilityZoneKept(properties, previousProperties);
@@ -1307,7 +1496,24 @@ async function updateDBInstance(logicalId, physicalId, resourceType, properties,
1307
1496
  }
1308
1497
  }) : "note AWS::RDS::DBInstance is a stateful type: re-run with cdkd deploy --replace --force-stateful-recreation to recreate it in the new zone (this deletes the instance and its data)")));
1309
1498
  if (!zoneKept) this.logger.warn(zoneMask(safeMsg`DBInstance ${logicalId} (${physicalId}): AvailabilityZone cannot change in place ` + safeMsg`(ModifyDBInstance has no such member), so the instance keeps its current zone ` + safeMsg`and cdkd records that zone.`));
1310
- const effectiveProperties = zoneKept ? void 0 : withPreviousAvailabilityZone(properties, previousProperties);
1499
+ let promotionSkipped = false;
1500
+ if (sourceChange === "promote") {
1501
+ const live = await this.describeDBInstance(physicalId);
1502
+ if (isLiveReadReplica(live) && context?.replayingState === true) {
1503
+ promotionSkipped = true;
1504
+ this.logger.warn(sourceMask(safeMsg`DBInstance ${logicalId} (${physicalId}): the rollback does not promote the read replica (a promotion cannot be undone, and the instance was a replica before this deploy), so cdkd records its source.`));
1505
+ } else if (isLiveReadReplica(live)) {
1506
+ this.logger.info(safeMsg`Promoting DBInstance ${logicalId} to a standalone instance (SourceDBInstanceIdentifier was removed), as CloudFormation does`);
1507
+ await this.getClient().send(new PromoteReadReplicaCommand({
1508
+ DBInstanceIdentifier: physicalId,
1509
+ ...properties["BackupRetentionPeriod"] != null && { BackupRetentionPeriod: Number(properties["BackupRetentionPeriod"]) },
1510
+ ...properties["PreferredBackupWindow"] != null && { PreferredBackupWindow: properties["PreferredBackupWindow"] }
1511
+ }));
1512
+ await this.waitForInstanceState(logicalId, physicalId, (instance) => instance.DBInstanceStatus === "available" && !isLiveReadReplica(instance), "promotion to a standalone instance");
1513
+ } else this.logger.debug(safeMsg`DBInstance ${logicalId} is no longer a read replica; nothing to promote`);
1514
+ }
1515
+ const zoneEffective = zoneKept ? void 0 : withPreviousAvailabilityZone(properties, previousProperties);
1516
+ const effectiveProperties = sourceKept && !promotionSkipped ? zoneEffective : withPreviousReplicaSource(zoneEffective ?? properties, previousProperties);
1311
1517
  const masterUserSecret = properties["MasterUserSecret"];
1312
1518
  const sendCredentialSettings = masterCredentialSettingsChanged(properties, previousProperties, context);
1313
1519
  const sendManagedPasswordSetting = managedPasswordSettingRides(sendCredentialSettings, authenticationType);
@@ -1440,7 +1646,16 @@ async function deleteDBInstanceOnce(logicalId, physicalId, resourceType, propert
1440
1646
  } catch (disableError) {
1441
1647
  if (!this.isNotFoundError(disableError, "DBInstanceNotFoundFault")) this.logger.debug(maskerOrIdentity(context?.maskSecrets)(`Could not disable deletion protection for DBInstance ${logicalId}: ${describeAwsFailure(disableError).detail}`));
1442
1648
  }
1443
- const finalSnapshotId = properties?.["DBClusterIdentifier"] === void 0 ? context?.finalSnapshotIdentifier : void 0;
1649
+ let finalSnapshotId = properties?.["DBClusterIdentifier"] === void 0 ? context?.finalSnapshotIdentifier : void 0;
1650
+ if (finalSnapshotId && replicaSourceOf(properties) !== void 0) {
1651
+ const live = await this.describeDBInstance(physicalId).catch((err) => {
1652
+ this.logger.debug(maskerOrIdentity(context?.maskSecrets)(safeMsg`Could not read whether DBInstance ${logicalId} is a read replica: ${describeAwsFailure(err).detail}`));
1653
+ });
1654
+ if (isLiveReadReplica(live)) {
1655
+ finalSnapshotId = void 0;
1656
+ this.logger.info(safeMsg`Deleting DBInstance ${logicalId} without a final snapshot: it is a read replica, whose DeletionPolicy CloudFormation ignores`);
1657
+ }
1658
+ }
1444
1659
  const sendDelete = () => this.getClient().send(new DeleteDBInstanceCommand({
1445
1660
  DBInstanceIdentifier: physicalId,
1446
1661
  ...finalSnapshotId ? {
@@ -1681,9 +1896,9 @@ async function waitForSecurityGroupsApplied(dbClusterIdentifier, logicalId, expe
1681
1896
  }
1682
1897
  throw new Error(`Timed out waiting for DBCluster ${logicalId} to apply its new VPC security groups`);
1683
1898
  }
1684
- async function waitForClusterState(logicalId, dbClusterIdentifier, done, change) {
1899
+ async function waitForClusterState(logicalId, dbClusterIdentifier, done, change, unboundedMaxWaitMs = 18e5) {
1685
1900
  const remaining = enclosingDeadlineRemainingMs();
1686
- const maxWaitMs = Number.isFinite(remaining) ? remaining : 18e5;
1901
+ const maxWaitMs = Number.isFinite(remaining) ? remaining : unboundedMaxWaitMs;
1687
1902
  const startTime = Date.now();
1688
1903
  let delay = 5e3;
1689
1904
  while (Date.now() - startTime < maxWaitMs) {
@@ -1881,7 +2096,12 @@ function canonicalizeDriftProperties(resourceType, properties) {
1881
2096
  const value = properties[key];
1882
2097
  if (value === "true" || value === "false") set(key, value === "true");
1883
2098
  }
1884
- for (const key of ["PerformanceInsightsRetentionPeriod", "BacktrackWindow"]) {
2099
+ for (const key of [
2100
+ "PerformanceInsightsRetentionPeriod",
2101
+ "BacktrackWindow",
2102
+ "AllocatedStorage",
2103
+ "Iops"
2104
+ ]) {
1885
2105
  const value = properties[key];
1886
2106
  if (typeof value === "string") {
1887
2107
  const parsed = retentionPeriodValue(value);
@@ -1890,6 +2110,25 @@ function canonicalizeDriftProperties(resourceType, properties) {
1890
2110
  }
1891
2111
  return out ?? properties;
1892
2112
  }
2113
+ async function canonicalizeDriftPair(resourceType, baseline, aws) {
2114
+ const recorded = baseline["SourceDBInstanceIdentifier"];
2115
+ const live = aws["SourceDBInstanceIdentifier"];
2116
+ if (resourceType !== "AWS::RDS::DBInstance" || typeof recorded !== "string" || typeof live !== "string" || recorded === live) return {
2117
+ baseline,
2118
+ aws
2119
+ };
2120
+ const region = await this.getClient().config.region();
2121
+ return sameReplicaSource(recorded, live, { region }) ? {
2122
+ baseline,
2123
+ aws: {
2124
+ ...aws,
2125
+ SourceDBInstanceIdentifier: recorded
2126
+ }
2127
+ } : {
2128
+ baseline,
2129
+ aws
2130
+ };
2131
+ }
1893
2132
  function canonicalizeUnsettledProperties(resourceType, properties) {
1894
2133
  return this.canonicalizeDriftProperties(resourceType, properties);
1895
2134
  }
@@ -2021,6 +2260,11 @@ async function readCurrentStateDBInstance(physicalId) {
2021
2260
  if (inst.DBName !== void 0) result["DBName"] = inst.DBName;
2022
2261
  if (inst.AvailabilityZone !== void 0 && inst.MultiAZ !== true) result["AvailabilityZone"] = inst.AvailabilityZone;
2023
2262
  if (inst.EngineLifecycleSupport !== void 0 && inst.DBClusterIdentifier === void 0) result["EngineLifecycleSupport"] = inst.EngineLifecycleSupport;
2263
+ const liveSource = inst.ReadReplicaSourceDBInstanceIdentifier;
2264
+ if (liveSource !== void 0 && liveSource !== "") {
2265
+ const ownArn = inst.DBInstanceArn;
2266
+ result["SourceDBInstanceIdentifier"] = liveSource.startsWith("arn:") || ownArn === void 0 || !ownArn.startsWith("arn:") ? liveSource : `${ownArn.slice(0, ownArn.lastIndexOf(":") + 1)}${liveSource}`;
2267
+ }
2024
2268
  result["AssociatedRoles"] = associatedRolesReadback(inst.AssociatedRoles);
2025
2269
  if (inst.DBInstanceArn) await this.attachTags(result, inst.DBInstanceArn);
2026
2270
  return result;
@@ -2066,6 +2310,13 @@ async function readCurrentStateDBCluster(physicalId) {
2066
2310
  if (cluster.CopyTagsToSnapshot !== void 0) result["CopyTagsToSnapshot"] = cluster.CopyTagsToSnapshot;
2067
2311
  const storageType = cluster.PendingModifiedValues?.StorageType ?? cluster.StorageType ?? (cluster.Engine?.toLowerCase().startsWith("aurora") ? "aurora" : void 0);
2068
2312
  if (storageType !== void 0) result["StorageType"] = storageType;
2313
+ if (!cluster.Engine?.toLowerCase().startsWith("aurora")) {
2314
+ if (cluster.DBClusterInstanceClass !== void 0) result["DBClusterInstanceClass"] = cluster.DBClusterInstanceClass;
2315
+ const allocatedStorage = cluster.PendingModifiedValues?.AllocatedStorage ?? cluster.AllocatedStorage;
2316
+ if (allocatedStorage !== void 0) result["AllocatedStorage"] = allocatedStorage;
2317
+ const iops = cluster.PendingModifiedValues?.Iops ?? cluster.Iops;
2318
+ if (iops !== void 0) result["Iops"] = iops;
2319
+ }
2069
2320
  const clusterLogs = liveLogExports(cluster.EnabledCloudwatchLogsExports, cluster.PendingModifiedValues?.PendingCloudwatchLogsExports);
2070
2321
  if (clusterLogs.length > 0) result["EnableCloudwatchLogsExports"] = clusterLogs;
2071
2322
  if (cluster.AutoMinorVersionUpgrade !== void 0) result["AutoMinorVersionUpgrade"] = cluster.AutoMinorVersionUpgrade;
@@ -2180,7 +2431,10 @@ var RDSProvider = class {
2180
2431
  "AssociatedRoles",
2181
2432
  "EngineMode",
2182
2433
  "AvailabilityZones",
2183
- "GlobalClusterIdentifier"
2434
+ "GlobalClusterIdentifier",
2435
+ "DBClusterInstanceClass",
2436
+ "AllocatedStorage",
2437
+ "Iops"
2184
2438
  ])],
2185
2439
  ["AWS::RDS::DBInstance", /* @__PURE__ */ new Set([
2186
2440
  "DBInstanceIdentifier",
@@ -2232,7 +2486,8 @@ var RDSProvider = class {
2232
2486
  "AvailabilityZone",
2233
2487
  "EngineLifecycleSupport",
2234
2488
  "MasterUserAuthenticationType",
2235
- "AssociatedRoles"
2489
+ "AssociatedRoles",
2490
+ "SourceDBInstanceIdentifier"
2236
2491
  ])]
2237
2492
  ]);
2238
2493
  unhandledByDesign = /* @__PURE__ */ new Map([["AWS::RDS::DBCluster", /* @__PURE__ */ new Map([
@@ -2359,8 +2614,8 @@ var RDSProvider = class {
2359
2614
  waitForSecurityGroupsApplied(dbClusterIdentifier, logicalId, expected, maxWaitMs = 18e5) {
2360
2615
  return waitForSecurityGroupsApplied.call(this, dbClusterIdentifier, logicalId, expected, maxWaitMs);
2361
2616
  }
2362
- waitForClusterState(logicalId, dbClusterIdentifier, done, change) {
2363
- return waitForClusterState.call(this, logicalId, dbClusterIdentifier, done, change);
2617
+ waitForClusterState(logicalId, dbClusterIdentifier, done, change, unboundedMaxWaitMs = 18e5) {
2618
+ return waitForClusterState.call(this, logicalId, dbClusterIdentifier, done, change, unboundedMaxWaitMs);
2364
2619
  }
2365
2620
  sendHttpEndpointChange(logicalId, physicalId, arn, enable) {
2366
2621
  return sendHttpEndpointChange.call(this, logicalId, physicalId, arn, enable);
@@ -2410,6 +2665,9 @@ var RDSProvider = class {
2410
2665
  canonicalizeDriftProperties(resourceType, properties) {
2411
2666
  return canonicalizeDriftProperties.call(this, resourceType, properties);
2412
2667
  }
2668
+ canonicalizeDriftPair(resourceType, baseline, aws) {
2669
+ return canonicalizeDriftPair.call(this, resourceType, baseline, aws);
2670
+ }
2413
2671
  canonicalizeUnsettledProperties(resourceType, properties) {
2414
2672
  return canonicalizeUnsettledProperties.call(this, resourceType, properties);
2415
2673
  }
@@ -2452,4 +2710,4 @@ var RDSProvider = class {
2452
2710
  };
2453
2711
 
2454
2712
  export { RDSProvider };
2455
- //# sourceMappingURL=rds-provider-CYwGhhxE.js.map
2713
+ //# sourceMappingURL=rds-provider-Ce7ua-ww.js.map