@cdkd/cli 0.338.0 → 0.340.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{ambient-client-defaults-Bz2AYX3k.js → ambient-client-defaults-D2df_dIB.js} +22 -3
- package/dist/{ambient-client-defaults-Bz2AYX3k.js.map → ambient-client-defaults-D2df_dIB.js.map} +1 -1
- package/dist/{asg-provider-CWmAKpgF.js → asg-provider-DrQNWTtu.js} +4 -4
- package/dist/{asg-provider-CWmAKpgF.js.map → asg-provider-DrQNWTtu.js.map} +1 -1
- package/dist/{aws-clients-ez_oXu6x.js → aws-clients-D3Z_tFc1.js} +4 -25
- package/dist/aws-clients-D3Z_tFc1.js.map +1 -0
- package/dist/cli.js +2 -2
- package/dist/{db-instance-modify-retry-Dks4BxMq.js → db-instance-modify-retry-BJSwxkSE.js} +3 -3
- package/dist/{db-instance-modify-retry-Dks4BxMq.js.map → db-instance-modify-retry-BJSwxkSE.js.map} +1 -1
- package/dist/{deploy-engine-BnsHKIjc.js → deploy-engine-Bn_aBFb7.js} +281 -46
- package/dist/deploy-engine-Bn_aBFb7.js.map +1 -0
- package/dist/{ecr-uri-Bekubfie.js → ecr-uri-B5zqA138.js} +3 -3
- package/dist/{ecr-uri-Bekubfie.js.map → ecr-uri-B5zqA138.js.map} +1 -1
- package/dist/{iam-role-provider-c85y_vuT.js → iam-role-provider-CRHaUz5M.js} +5 -5
- package/dist/{iam-role-provider-c85y_vuT.js.map → iam-role-provider-CRHaUz5M.js.map} +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/{neptune-provider-CLuvQucV.js → neptune-provider-BL93NXUx.js} +5 -5
- package/dist/{neptune-provider-CLuvQucV.js.map → neptune-provider-BL93NXUx.js.map} +1 -1
- package/dist/{program-CF2fN6wd.js → program-CuJKRAac.js} +50 -80
- package/dist/program-CuJKRAac.js.map +1 -0
- package/dist/{provider-classes-Ch72oCC3.js → provider-classes-CRZ8a4sy.js} +13 -13
- package/dist/provider-classes-CRZ8a4sy.js.map +1 -0
- package/dist/{rds-provider-DDK78o9z.js → rds-provider-B-LP69hz.js} +624 -171
- package/dist/rds-provider-B-LP69hz.js.map +1 -0
- package/dist/{read-replica-C7nFHyNr.js → read-replica-DblnJp2B.js} +5 -19
- package/dist/read-replica-DblnJp2B.js.map +1 -0
- package/dist/rolldown-runtime-CNh9ExCG.js +17 -0
- package/dist/{update-removal--qeWEXhm.js → update-removal-DTvJXMeM.js} +2 -2
- package/dist/{update-removal--qeWEXhm.js.map → update-removal-DTvJXMeM.js.map} +1 -1
- package/dist/{version-bUHr9iDr.js → version-Y2LIzQUU.js} +2 -2
- package/dist/{version-bUHr9iDr.js.map → version-Y2LIzQUU.js.map} +1 -1
- package/package.json +11 -11
- package/dist/aws-clients-ez_oXu6x.js.map +0 -1
- package/dist/deploy-engine-BnsHKIjc.js.map +0 -1
- package/dist/program-CF2fN6wd.js.map +0 -1
- package/dist/provider-classes-Ch72oCC3.js.map +0 -1
- package/dist/rds-provider-DDK78o9z.js.map +0 -1
- package/dist/read-replica-C7nFHyNr.js.map +0 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { $ as safeMsg, n as describeAwsFailure, s as getLogger, y as generatedNameFor } from "./aws-failure-text-FKztQiaJ.js";
|
|
2
|
-
import {
|
|
2
|
+
import { D as relayedNameCollision, G as wrapMaskedAwsError, Q as CdkdError, U as markNonRetryable, W as markRedactedCause, g as ResourceUpdateNotSupportedError, rt as ProvisioningError, t as ambientClientDefaults } from "./ambient-client-defaults-D2df_dIB.js";
|
|
3
|
+
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-DTvJXMeM.js";
|
|
3
4
|
import { c as ambientRegion } from "./aws-client-defaults-BLXFsfMa.js";
|
|
4
|
-
import { $i as
|
|
5
|
-
import {
|
|
6
|
-
import { a as
|
|
7
|
-
import { a as refuseMalformedReplicaSource, c as replicaEngine, d as replicaSourceChange, f as replicaSourceOf, l as replicaModifyAfterCreateInput, m as withPreviousReplicaSource, n as isLiveReadReplica, o as refuseUnknownSourceRegion, p as sameReplicaSource, r as ownScopeOf, s as replicaCreateInput, t as describeReplicaSource, u as replicaNeedsModifyAfterCreate } from "./read-replica-C7nFHyNr.js";
|
|
5
|
+
import { $i as definedAttributes, Al as dynamicReferenceTokens, Ft as enclosingDeadlineRemainingMs, Oa as slowCcOperationTimeoutMs, aa as refuseMalformedDesiredTags, ea as stringifyIfAssigned, la as markDeleteStarted, mi as refuseRestoreFromItself, ra as planTagDiff, sa as tagPlanWarning, ts as coerceCfnBoolean, zc as dbInstanceEngineChangeIsInPlace } from "./deploy-engine-Bn_aBFb7.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-BJSwxkSE.js";
|
|
7
|
+
import { a as refuseMalformedReplicaSource, c as replicaEngine, d as replicaSourceChange, f as replicaSourceOf, l as replicaModifyAfterCreateInput, m as withPreviousReplicaSource, n as isLiveReadReplica, o as refuseUnknownSourceRegion, p as sameReplicaSource, r as ownScopeOf, s as replicaCreateInput, t as describeReplicaSource, u as replicaNeedsModifyAfterCreate } from "./read-replica-DblnJp2B.js";
|
|
8
8
|
import { DescribeSecurityGroupsCommand, EC2Client } from "@aws-sdk/client-ec2";
|
|
9
9
|
import { isDeepStrictEqual } from "node:util";
|
|
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";
|
|
10
|
+
import { AddRoleToDBClusterCommand, AddRoleToDBInstanceCommand, AddTagsToResourceCommand, CreateDBClusterCommand, CreateDBInstanceCommand, CreateDBInstanceReadReplicaCommand, CreateDBSubnetGroupCommand, DeleteDBClusterCommand, DeleteDBInstanceCommand, DeleteDBSubnetGroupCommand, DescribeDBClustersCommand, DescribeDBInstanceAutomatedBackupsCommand, DescribeDBInstancesCommand, DescribeDBSubnetGroupsCommand, DescribeGlobalClustersCommand, DisableHttpEndpointCommand, EnableHttpEndpointCommand, ListTagsForResourceCommand, ModifyDBClusterCommand, ModifyDBInstanceCommand, ModifyDBSubnetGroupCommand, PromoteReadReplicaCommand, RDSClient, RebootDBInstanceCommand, RemoveFromGlobalClusterCommand, RemoveRoleFromDBClusterCommand, RemoveRoleFromDBInstanceCommand, RemoveTagsFromResourceCommand, RestoreDBClusterToPointInTimeCommand, StartDBInstanceAutomatedBackupsReplicationCommand, StopDBInstanceAutomatedBackupsReplicationCommand } from "@aws-sdk/client-rds";
|
|
11
11
|
|
|
12
12
|
// src/provisioning/providers/rds/shared.ts
|
|
13
13
|
const RDS_DELETE_WAIT_MS = Math.max(18e5, slowCcOperationTimeoutMs("AWS::RDS::DBCluster", "DELETE"), slowCcOperationTimeoutMs("AWS::RDS::DBInstance", "DELETE"));
|
|
@@ -450,6 +450,83 @@ function engineLifecycleSupportRefusalText(resourceType, logicalId, physicalId,
|
|
|
450
450
|
const cli = kind === "DB cluster" ? "aws rds modify-db-cluster" : "aws rds modify-db-instance";
|
|
451
451
|
return `${resourceType} ${logicalId}: EngineLifecycleSupport cannot change on an existing ${kind}. CloudFormation refuses the same update ("EngineLifecycleSupport cannot be modified."), whether the value changes, is added or is removed. Nothing was applied to ${kind} ${physicalId}. ` + (liveRead === "unreadable" ? `cdkd could not read the live setting (an AWS read failed), so it could not tell whether the ${kind} already holds the declared value; a re-run may succeed. ` : liveRead === "not-found" ? `RDS reports no such ${kind}: it was deleted outside cdkd, so the state record no longer matches AWS. ` : "") + `Declare the value the previous deploy declared (or none, if it declared none). To change the live setting, run ${cli} with --engine-lifecycle-support and --apply-immediately, then declare that value: a declared value the ${kind} already holds is no change.`;
|
|
452
452
|
}
|
|
453
|
+
const BACKUP_REPLICATION_KEYS = [
|
|
454
|
+
"AutomaticBackupReplicationRegion",
|
|
455
|
+
"AutomaticBackupReplicationKmsKeyId",
|
|
456
|
+
"AutomaticBackupReplicationRetentionPeriod"
|
|
457
|
+
];
|
|
458
|
+
const MALFORMED = Symbol("malformed");
|
|
459
|
+
function optionalString(value) {
|
|
460
|
+
if (value == null || value === "") return void 0;
|
|
461
|
+
return typeof value === "string" ? value : MALFORMED;
|
|
462
|
+
}
|
|
463
|
+
function optionalWholeNumber(value) {
|
|
464
|
+
if (value == null || value === "") return void 0;
|
|
465
|
+
const parsed = typeof value === "number" ? value : typeof value === "string" ? Number(value) : NaN;
|
|
466
|
+
return Number.isInteger(parsed) ? parsed : MALFORMED;
|
|
467
|
+
}
|
|
468
|
+
function backupReplicationOf(bag) {
|
|
469
|
+
const region = optionalString(bag["AutomaticBackupReplicationRegion"]);
|
|
470
|
+
const kmsKeyId = optionalString(bag["AutomaticBackupReplicationKmsKeyId"]);
|
|
471
|
+
const retention = optionalWholeNumber(bag["AutomaticBackupReplicationRetentionPeriod"]);
|
|
472
|
+
if (region === MALFORMED || kmsKeyId === MALFORMED || retention === MALFORMED) return "malformed";
|
|
473
|
+
return {
|
|
474
|
+
region,
|
|
475
|
+
kmsKeyId,
|
|
476
|
+
retention
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
function backupRetentionPeriodOf(bag) {
|
|
480
|
+
const value = optionalWholeNumber(bag["BackupRetentionPeriod"]);
|
|
481
|
+
return value === MALFORMED ? void 0 : value;
|
|
482
|
+
}
|
|
483
|
+
function backupReplicationPlan(properties, previousProperties, resourceType, logicalId, physicalId, stateBorne, warn) {
|
|
484
|
+
const none = {
|
|
485
|
+
stop: false,
|
|
486
|
+
start: void 0
|
|
487
|
+
};
|
|
488
|
+
const keys = [...BACKUP_REPLICATION_KEYS, "BackupRetentionPeriod"];
|
|
489
|
+
const desired = backupReplicationOf(properties);
|
|
490
|
+
const previous = backupReplicationOf(previousProperties);
|
|
491
|
+
if (desired === "malformed") {
|
|
492
|
+
if (keys.every((key) => isDeepStrictEqual(properties[key], previousProperties[key]))) return none;
|
|
493
|
+
throw markNonRetryable(new ProvisioningError(`${resourceType} ${logicalId}: AutomaticBackupReplicationRegion and AutomaticBackupReplicationKmsKeyId must be strings, and AutomaticBackupReplicationRetentionPeriod a whole number`, resourceType, logicalId, physicalId));
|
|
494
|
+
}
|
|
495
|
+
const misuse = desired.region === void 0 ? desired.kmsKeyId !== void 0 ? "You must specify the AutomaticBackupReplicationRegion parameter when setting the AutomaticBackupReplicationKmsKeyId parameter" : desired.retention !== void 0 ? "You must specify the AutomaticBackupReplicationRegion parameter when setting the AutomaticBackupReplicationRetentionPeriod parameter" : void 0 : backupRetentionPeriodOf(properties) === 0 ? "AutomaticBackupReplicationRegion cannot be specified when BackupRetentionPeriod is 0" : void 0;
|
|
496
|
+
if (misuse !== void 0) {
|
|
497
|
+
const message = `${resourceType} ${logicalId}: ${misuse} (as CloudFormation refuses it)`;
|
|
498
|
+
if (!stateBorne) throw markNonRetryable(new ProvisioningError(message, resourceType, logicalId, physicalId));
|
|
499
|
+
warn(`${message}; the restored properties declare it, so it is applied as declared`);
|
|
500
|
+
}
|
|
501
|
+
const start = desired.region === void 0 ? void 0 : {
|
|
502
|
+
...desired,
|
|
503
|
+
region: desired.region
|
|
504
|
+
};
|
|
505
|
+
if (previous === "malformed") return {
|
|
506
|
+
stop: true,
|
|
507
|
+
start
|
|
508
|
+
};
|
|
509
|
+
if (previous.region === void 0) return {
|
|
510
|
+
stop: false,
|
|
511
|
+
start
|
|
512
|
+
};
|
|
513
|
+
if (desired.region === void 0) return {
|
|
514
|
+
stop: true,
|
|
515
|
+
start: void 0
|
|
516
|
+
};
|
|
517
|
+
return desired.retention === void 0 && backupRetentionPeriodOf(properties) !== void 0 && backupRetentionPeriodOf(properties) !== backupRetentionPeriodOf(previousProperties) || desired.region !== previous.region || desired.kmsKeyId !== previous.kmsKeyId || desired.retention !== previous.retention ? {
|
|
518
|
+
stop: true,
|
|
519
|
+
start
|
|
520
|
+
} : none;
|
|
521
|
+
}
|
|
522
|
+
function liveBackupReplicationRegions(instance) {
|
|
523
|
+
const regions = [];
|
|
524
|
+
for (const replication of instance.DBInstanceAutomatedBackupsReplications ?? []) {
|
|
525
|
+
const region = replication.DBInstanceAutomatedBackupsArn?.split(":")[3];
|
|
526
|
+
if (region !== void 0 && region !== "" && !regions.includes(region)) regions.push(region);
|
|
527
|
+
}
|
|
528
|
+
return regions;
|
|
529
|
+
}
|
|
453
530
|
|
|
454
531
|
// src/provisioning/providers/rds/cluster-members.ts
|
|
455
532
|
const CLUSTER_REMOVED_PORT = /* @__PURE__ */ new Map([
|
|
@@ -757,6 +834,227 @@ async function deleteExpressWriter(logicalId, physicalId, cluster, recordedWrite
|
|
|
757
834
|
return true;
|
|
758
835
|
}
|
|
759
836
|
|
|
837
|
+
// src/provisioning/providers/rds/cluster-restore.ts
|
|
838
|
+
const ZONED_DATE_TIME = /^(\d{4})-(\d{2})-(\d{2})[Tt](\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,9}))?)?(?:[Zz]|([+-])(\d{2})(?::(\d{2})(?::(\d{2}))?)?)(?:\[[^\]]+\])?$/;
|
|
839
|
+
function parseZonedTimestamp(text) {
|
|
840
|
+
const match = ZONED_DATE_TIME.exec(text);
|
|
841
|
+
if (match === null) return void 0;
|
|
842
|
+
const n = (i) => match[i] === void 0 ? 0 : Number(match[i]);
|
|
843
|
+
const [year, month, day, hour, minute, second] = [
|
|
844
|
+
n(1),
|
|
845
|
+
n(2),
|
|
846
|
+
n(3),
|
|
847
|
+
n(4),
|
|
848
|
+
n(5),
|
|
849
|
+
n(6)
|
|
850
|
+
];
|
|
851
|
+
const [offsetHours, offsetMinutes, offsetSeconds] = [
|
|
852
|
+
n(9),
|
|
853
|
+
n(10),
|
|
854
|
+
n(11)
|
|
855
|
+
];
|
|
856
|
+
if (month < 1 || month > 12 || hour > 23 || minute > 59 || second > 59) return void 0;
|
|
857
|
+
if (offsetMinutes > 59 || offsetSeconds > 59) return void 0;
|
|
858
|
+
if (offsetHours * 3600 + offsetMinutes * 60 + offsetSeconds > 64800) return void 0;
|
|
859
|
+
if (day < 1 || new Date(Date.UTC(year, month - 1, day)).getUTCDate() !== day) return void 0;
|
|
860
|
+
const millis = Number((match[7] ?? "").padEnd(3, "0").slice(0, 3));
|
|
861
|
+
const offsetMs = (match[8] === "-" ? -1 : 1) * (offsetHours * 3600 + offsetMinutes * 60 + offsetSeconds) * 1e3;
|
|
862
|
+
const date = new Date(Date.UTC(year, month - 1, day, hour, minute, second, millis) - offsetMs);
|
|
863
|
+
return Number.isNaN(date.getTime()) ? void 0 : date;
|
|
864
|
+
}
|
|
865
|
+
function readClusterRestore(properties, resourceType, logicalId) {
|
|
866
|
+
const refuse = (reason) => {
|
|
867
|
+
throw markNonRetryable(new ProvisioningError(safeMsg`${resourceType} ${logicalId}: ${reason}, as CloudFormation requires; nothing was changed.`, resourceType, logicalId));
|
|
868
|
+
};
|
|
869
|
+
const declaredTime = properties["RestoreToTime"];
|
|
870
|
+
let restoreToTime;
|
|
871
|
+
if (declaredTime != null && !(typeof declaredTime === "string" && declaredTime.trim() === "")) {
|
|
872
|
+
restoreToTime = typeof declaredTime === "string" ? parseZonedTimestamp(declaredTime) : void 0;
|
|
873
|
+
if (restoreToTime === void 0) return refuse("RestoreToTime must be an ISO 8601 timestamp with a time zone, such as 2026-01-01T00:00:00Z");
|
|
874
|
+
}
|
|
875
|
+
const declaredLatest = properties["UseLatestRestorableTime"];
|
|
876
|
+
const useLatestRestorableTime = declaredLatest == null ? void 0 : coerceCfnBoolean(declaredLatest);
|
|
877
|
+
if (declaredLatest != null && useLatestRestorableTime === void 0) return refuse("UseLatestRestorableTime must be true or false");
|
|
878
|
+
const restoreType = properties["RestoreType"];
|
|
879
|
+
if (restoreType != null && typeof restoreType !== "string") return refuse("RestoreType must be a string");
|
|
880
|
+
const source = properties["SourceDBClusterIdentifier"];
|
|
881
|
+
if (source == null) return void 0;
|
|
882
|
+
if (typeof source !== "string") return refuse("SourceDBClusterIdentifier must be a string");
|
|
883
|
+
if (source === "") return void 0;
|
|
884
|
+
return {
|
|
885
|
+
sourceDBClusterIdentifier: source,
|
|
886
|
+
restoreToTime: useLatestRestorableTime === true ? void 0 : restoreToTime,
|
|
887
|
+
useLatestRestorableTime,
|
|
888
|
+
restoreType: restoreType === "" ? void 0 : restoreType
|
|
889
|
+
};
|
|
890
|
+
}
|
|
891
|
+
function isRestoredRecord(properties) {
|
|
892
|
+
const source = properties?.["SourceDBClusterIdentifier"];
|
|
893
|
+
return typeof source === "string" && source !== "";
|
|
894
|
+
}
|
|
895
|
+
function unusedRestoreKeys(properties, restore) {
|
|
896
|
+
return (restore === void 0 ? [
|
|
897
|
+
"RestoreType",
|
|
898
|
+
"RestoreToTime",
|
|
899
|
+
"UseLatestRestorableTime"
|
|
900
|
+
] : [
|
|
901
|
+
"AvailabilityZones",
|
|
902
|
+
"GlobalClusterIdentifier",
|
|
903
|
+
"WithExpressConfiguration",
|
|
904
|
+
"ClusterScalabilityType",
|
|
905
|
+
"MasterUserAuthenticationType",
|
|
906
|
+
...restore.useLatestRestorableTime === true ? ["RestoreToTime"] : []
|
|
907
|
+
]).filter((key) => {
|
|
908
|
+
const value = properties[key];
|
|
909
|
+
if (value == null || value === "" || value === false || value === "false") return false;
|
|
910
|
+
return !(Array.isArray(value) && value.length === 0);
|
|
911
|
+
});
|
|
912
|
+
}
|
|
913
|
+
function restoredDifferences(properties, cluster) {
|
|
914
|
+
return [
|
|
915
|
+
["Engine", cluster.Engine],
|
|
916
|
+
["EngineVersion", cluster.EngineVersion],
|
|
917
|
+
["EngineMode", cluster.EngineMode],
|
|
918
|
+
["MasterUsername", cluster.MasterUsername],
|
|
919
|
+
["DatabaseName", cluster.DatabaseName]
|
|
920
|
+
].filter(([key, live]) => properties[key] != null && properties[key] !== "" && live !== void 0 && String(properties[key]) !== live).map(([key]) => key);
|
|
921
|
+
}
|
|
922
|
+
const ARN_IDENTIFIER_REFUSALS = /* @__PURE__ */ new Set(["InvalidParameterValue", "InvalidParameterCombination"]);
|
|
923
|
+
async function readRestoreSource(source, resourceType, logicalId, mask) {
|
|
924
|
+
const wrapSourceReadError = (error) => this.wrapCaughtError(mask, error, (text) => new ProvisioningError(`Failed to create DBCluster ${logicalId}: reading the restore source failed, so nothing was changed: ${text}`, resourceType, logicalId, void 0, error instanceof Error ? error : void 0));
|
|
925
|
+
let found;
|
|
926
|
+
try {
|
|
927
|
+
found = (await this.getClient().send(new DescribeDBClustersCommand({ DBClusterIdentifier: source }))).DBClusters?.[0];
|
|
928
|
+
} catch (error) {
|
|
929
|
+
if (!(source.startsWith("arn:") && error instanceof Error && ARN_IDENTIFIER_REFUSALS.has(error.name)) && !this.isNotFoundError(error, "DBClusterNotFoundFault")) throw wrapSourceReadError(error);
|
|
930
|
+
}
|
|
931
|
+
if (found === void 0 && source.startsWith("arn:")) try {
|
|
932
|
+
let marker;
|
|
933
|
+
do {
|
|
934
|
+
const page = await this.getClient().send(new DescribeDBClustersCommand({
|
|
935
|
+
IncludeShared: true,
|
|
936
|
+
Marker: marker
|
|
937
|
+
}));
|
|
938
|
+
found = page.DBClusters?.find((cluster) => (cluster.DBClusterArn ?? "").toLowerCase() === source.toLowerCase());
|
|
939
|
+
marker = page.Marker;
|
|
940
|
+
} while (found === void 0 && marker !== void 0 && marker !== "");
|
|
941
|
+
} catch (error) {
|
|
942
|
+
throw wrapSourceReadError(error);
|
|
943
|
+
}
|
|
944
|
+
if (found !== void 0) return found;
|
|
945
|
+
throw markNonRetryable(new ProvisioningError(safeMsg`${resourceType} ${logicalId}: SourceDBClusterIdentifier ${source} does not name a DB cluster this account can read, so there is nothing to restore; nothing was changed.`, resourceType, logicalId));
|
|
946
|
+
}
|
|
947
|
+
function refuseRestoreEncryption(properties, source, resourceType, logicalId) {
|
|
948
|
+
const desired = coerceCfnBoolean(properties["StorageEncrypted"]);
|
|
949
|
+
const kmsKeyId = properties["KmsKeyId"];
|
|
950
|
+
const hasKey = typeof kmsKeyId === "string" ? kmsKeyId !== "" : kmsKeyId != null;
|
|
951
|
+
const refuse = (reason) => {
|
|
952
|
+
throw markNonRetryable(new ProvisioningError(`${resourceType} ${logicalId}: ${reason} Nothing was changed.`, resourceType, logicalId));
|
|
953
|
+
};
|
|
954
|
+
if (source.StorageEncrypted === false && desired === true && !hasKey) refuse("StorageEncrypted is true but the restore source is not encrypted and no KmsKeyId is set: you can't create an encrypted DB cluster from an unencrypted source without a KMS key. Set KmsKeyId (alias/aws/rds is the default key), as CloudFormation requires.");
|
|
955
|
+
if (source.StorageEncrypted === true && desired === false) refuse("StorageEncrypted is false but the restore source is encrypted: a restore of an encrypted source is encrypted. Set StorageEncrypted to true or remove it, as CloudFormation requires.");
|
|
956
|
+
if (desired === false && hasKey) refuse("a KmsKeyId is set while StorageEncrypted is false: a restore encrypts with the key. Set StorageEncrypted to true or remove the KmsKeyId, as CloudFormation requires.");
|
|
957
|
+
}
|
|
958
|
+
function isLimitlessSource(source) {
|
|
959
|
+
return source.ClusterScalabilityType === "limitless";
|
|
960
|
+
}
|
|
961
|
+
function pointInTimeRestoreInput(properties, restore, dbClusterIdentifier, tags, logExports, limitless) {
|
|
962
|
+
const string = (key) => properties[key] != null ? properties[key] : void 0;
|
|
963
|
+
const scaling = properties["ServerlessV2ScalingConfiguration"];
|
|
964
|
+
const multiAz = clusterCreateMultiAzMembers(properties);
|
|
965
|
+
const backfill = clusterCreateBackfillMembers(properties);
|
|
966
|
+
const scalars = clusterCreateScalarMembers(properties);
|
|
967
|
+
const engineLifecycleSupport = engineLifecycleSupportOf(properties);
|
|
968
|
+
return {
|
|
969
|
+
DBClusterIdentifier: dbClusterIdentifier,
|
|
970
|
+
SourceDBClusterIdentifier: restore.sourceDBClusterIdentifier,
|
|
971
|
+
...restore.restoreType !== void 0 && { RestoreType: restore.restoreType },
|
|
972
|
+
...restore.useLatestRestorableTime !== void 0 && { UseLatestRestorableTime: restore.useLatestRestorableTime },
|
|
973
|
+
...restore.restoreToTime !== void 0 && { RestoreToTime: restore.restoreToTime },
|
|
974
|
+
...backfill.CopyTagsToSnapshot !== void 0 && { CopyTagsToSnapshot: backfill.CopyTagsToSnapshot },
|
|
975
|
+
...multiAz.DBClusterInstanceClass !== void 0 && { DBClusterInstanceClass: multiAz.DBClusterInstanceClass },
|
|
976
|
+
...multiAz.Iops !== void 0 && { Iops: multiAz.Iops },
|
|
977
|
+
...string("DBSubnetGroupName") !== void 0 && { DBSubnetGroupName: string("DBSubnetGroupName") },
|
|
978
|
+
...logExports !== void 0 && logExports.length > 0 && { EnableCloudwatchLogsExports: logExports },
|
|
979
|
+
...string("KmsKeyId") !== void 0 && { KmsKeyId: string("KmsKeyId") },
|
|
980
|
+
...string("NetworkType") !== void 0 && { NetworkType: string("NetworkType") },
|
|
981
|
+
...properties["Port"] != null && { Port: Number(properties["Port"]) },
|
|
982
|
+
...properties["PubliclyAccessible"] != null && { PubliclyAccessible: properties["PubliclyAccessible"] },
|
|
983
|
+
...scaling != null && { ServerlessV2ScalingConfiguration: serverlessV2ScalingToSend(scaling) },
|
|
984
|
+
...backfill.StorageType !== void 0 && { StorageType: backfill.StorageType },
|
|
985
|
+
...properties["VpcSecurityGroupIds"] != null && { VpcSecurityGroupIds: properties["VpcSecurityGroupIds"] },
|
|
986
|
+
...engineLifecycleSupport !== void 0 && { EngineLifecycleSupport: engineLifecycleSupport },
|
|
987
|
+
...tags.length > 0 && { Tags: tags },
|
|
988
|
+
...limitless && {
|
|
989
|
+
...string("MonitoringRoleArn") !== void 0 && { MonitoringRoleArn: string("MonitoringRoleArn") },
|
|
990
|
+
...properties["MonitoringInterval"] != null && { MonitoringInterval: Number(properties["MonitoringInterval"]) },
|
|
991
|
+
...scalars.EnablePerformanceInsights !== void 0 && { EnablePerformanceInsights: scalars.EnablePerformanceInsights },
|
|
992
|
+
...scalars.PerformanceInsightsRetentionPeriod !== void 0 && { PerformanceInsightsRetentionPeriod: scalars.PerformanceInsightsRetentionPeriod },
|
|
993
|
+
...scalars.PerformanceInsightsKMSKeyId !== void 0 && { PerformanceInsightsKMSKeyId: scalars.PerformanceInsightsKMSKeyId }
|
|
994
|
+
}
|
|
995
|
+
};
|
|
996
|
+
}
|
|
997
|
+
const DEFAULT_BACKUP_RETENTION_PERIOD = 1;
|
|
998
|
+
function pointInTimeRestoreFollowUp(properties, logExports, limitless) {
|
|
999
|
+
const multiAz = clusterCreateMultiAzMembers(properties);
|
|
1000
|
+
const backfill = clusterCreateBackfillMembers(properties);
|
|
1001
|
+
const { EngineLifecycleSupport: _lifecycle, MasterUserAuthenticationType: _authentication, BacktrackWindow: backtrackWindow, ...scalars } = clusterCreateScalarMembers(properties);
|
|
1002
|
+
const serverlessV1 = properties["EngineMode"] === "serverless";
|
|
1003
|
+
const managed = coerceCfnBoolean(properties["ManageMasterUserPassword"]) === true;
|
|
1004
|
+
const masterUserSecret = properties["MasterUserSecret"];
|
|
1005
|
+
const allocatedStorage = clusterSizeValue(properties["AllocatedStorage"]);
|
|
1006
|
+
const members = {
|
|
1007
|
+
...scalars,
|
|
1008
|
+
BackupRetentionPeriod: properties["BackupRetentionPeriod"] != null ? Number(properties["BackupRetentionPeriod"]) : DEFAULT_BACKUP_RETENTION_PERIOD,
|
|
1009
|
+
...logExports !== void 0 && logExports.length > 0 && { CloudwatchLogsExportConfiguration: { EnableLogTypes: logExports } },
|
|
1010
|
+
...backfill,
|
|
1011
|
+
...multiAz.DBClusterInstanceClass !== void 0 && { DBClusterInstanceClass: multiAz.DBClusterInstanceClass },
|
|
1012
|
+
...multiAz.Iops !== void 0 && { Iops: multiAz.Iops },
|
|
1013
|
+
...properties["DeletionProtection"] != null && { DeletionProtection: properties["DeletionProtection"] },
|
|
1014
|
+
...properties["MasterUserPassword"] != null && { MasterUserPassword: properties["MasterUserPassword"] },
|
|
1015
|
+
...properties["MonitoringInterval"] != null && { MonitoringInterval: Number(properties["MonitoringInterval"]) },
|
|
1016
|
+
...properties["MonitoringRoleArn"] != null && { MonitoringRoleArn: properties["MonitoringRoleArn"] },
|
|
1017
|
+
...serverlessV1 ? properties["EnableHttpEndpoint"] != null && { EnableHttpEndpoint: coerceCfnBoolean(properties["EnableHttpEndpoint"]) } : {
|
|
1018
|
+
...typeof allocatedStorage === "number" && { AllocatedStorage: allocatedStorage },
|
|
1019
|
+
...backtrackWindow !== void 0 && { BacktrackWindow: backtrackWindow },
|
|
1020
|
+
...properties["EnableIAMDatabaseAuthentication"] != null && { EnableIAMDatabaseAuthentication: properties["EnableIAMDatabaseAuthentication"] }
|
|
1021
|
+
},
|
|
1022
|
+
...managed && {
|
|
1023
|
+
ManageMasterUserPassword: true,
|
|
1024
|
+
...masterUserSecret?.KmsKeyId !== void 0 && { MasterUserSecretKmsKeyId: masterUserSecret.KmsKeyId }
|
|
1025
|
+
}
|
|
1026
|
+
};
|
|
1027
|
+
if (serverlessV1) delete members.PreferredBackupWindow;
|
|
1028
|
+
if (limitless) {
|
|
1029
|
+
delete members.StorageType;
|
|
1030
|
+
delete members.EnablePerformanceInsights;
|
|
1031
|
+
delete members.PerformanceInsightsKMSKeyId;
|
|
1032
|
+
delete members.CloudwatchLogsExportConfiguration;
|
|
1033
|
+
}
|
|
1034
|
+
return members;
|
|
1035
|
+
}
|
|
1036
|
+
function restoreWaitMs() {
|
|
1037
|
+
const remaining = enclosingDeadlineRemainingMs() - 3e4;
|
|
1038
|
+
return Number.isFinite(remaining) ? Math.max(18e5, remaining) : 18e5;
|
|
1039
|
+
}
|
|
1040
|
+
async function sendRestoreFollowUp(logicalId, physicalId, members) {
|
|
1041
|
+
await modifyDbInstanceWhenAvailable({
|
|
1042
|
+
send: () => this.getClient().send(new ModifyDBClusterCommand({
|
|
1043
|
+
DBClusterIdentifier: physicalId,
|
|
1044
|
+
...members,
|
|
1045
|
+
ApplyImmediately: true
|
|
1046
|
+
})),
|
|
1047
|
+
readStatus: async () => (await this.describeDBCluster(physicalId))?.Status,
|
|
1048
|
+
sleep: (ms) => this.sleep(ms),
|
|
1049
|
+
logger: this.logger,
|
|
1050
|
+
label: "DBCluster",
|
|
1051
|
+
subject: "cluster",
|
|
1052
|
+
action: "create",
|
|
1053
|
+
logicalId,
|
|
1054
|
+
remainingMs: enclosingDeadlineRemainingMs()
|
|
1055
|
+
});
|
|
1056
|
+
}
|
|
1057
|
+
|
|
760
1058
|
// src/provisioning/providers/rds/cluster-create.ts
|
|
761
1059
|
async function createDBCluster(logicalId, resourceType, properties, mask, replaying = false) {
|
|
762
1060
|
this.logger.debug(`Creating DBCluster ${logicalId}`);
|
|
@@ -781,7 +1079,10 @@ async function createDBCluster(logicalId, resourceType, properties, mask, replay
|
|
|
781
1079
|
const globalClusterId = globalClusterSkipped ? void 0 : recordedGlobalClusterIdentifier(properties);
|
|
782
1080
|
const expressFlag = expressConfigurationFlag(properties["WithExpressConfiguration"]);
|
|
783
1081
|
const expressSkipped = expressFlag === "malformed";
|
|
784
|
-
const
|
|
1082
|
+
const restore = readClusterRestore(properties, resourceType, logicalId);
|
|
1083
|
+
const express = expressFlag === true && restore === void 0;
|
|
1084
|
+
const unused = unusedRestoreKeys(properties, restore);
|
|
1085
|
+
if (unused.length > 0) this.logger.warn(safeMsg`DBCluster ${logicalId}: this ${restore === void 0 ? "create" : "point-in-time restore"} does not apply ${unused.join(", ")}, as in CloudFormation.`);
|
|
785
1086
|
const classSkipped = malformedInstanceClass(properties["DBClusterInstanceClass"]);
|
|
786
1087
|
const allocatedSkipped = clusterSizeValue(properties["AllocatedStorage"]) === "malformed";
|
|
787
1088
|
const iopsSkipped = clusterSizeValue(properties["Iops"]) === "malformed";
|
|
@@ -864,12 +1165,19 @@ async function createDBCluster(logicalId, resourceType, properties, mask, replay
|
|
|
864
1165
|
const effectiveProperties = skippedKeys.length > 0 ? Object.fromEntries(Object.entries(properties).filter(([key]) => !skippedKeys.includes(key))) : void 0;
|
|
865
1166
|
const logExports = desiredLogExports(properties, resourceType, logicalId);
|
|
866
1167
|
const dbClusterIdentifier = properties["DBClusterIdentifier"] || generatedNameFor("AWS::RDS::DBCluster", logicalId, { properties });
|
|
1168
|
+
if (restore !== void 0 && !/^arn:/i.test(restore.sourceDBClusterIdentifier)) refuseRestoreFromItself(resourceType, properties, dbClusterIdentifier, logicalId, {});
|
|
1169
|
+
let limitless = false;
|
|
1170
|
+
if (restore !== void 0) {
|
|
1171
|
+
const source = await readRestoreSource.call(this, restore.sourceDBClusterIdentifier, resourceType, logicalId, mask);
|
|
1172
|
+
refuseRestoreEncryption(properties, source, resourceType, logicalId);
|
|
1173
|
+
limitless = isLimitlessSource(source);
|
|
1174
|
+
}
|
|
867
1175
|
let clusterLeftBehind = false;
|
|
868
1176
|
let createdResourceId;
|
|
869
1177
|
try {
|
|
870
1178
|
const serverlessV2Config = properties["ServerlessV2ScalingConfiguration"];
|
|
871
1179
|
const masterUserSecret = properties["MasterUserSecret"];
|
|
872
|
-
const response = await this.getCreateClient().send(new CreateDBClusterCommand({
|
|
1180
|
+
const response = await (restore !== void 0 ? this.getCreateClient().send(new RestoreDBClusterToPointInTimeCommand(pointInTimeRestoreInput(properties, restore, dbClusterIdentifier, tags, logExports, limitless))) : this.getCreateClient().send(new CreateDBClusterCommand({
|
|
873
1181
|
DBClusterIdentifier: dbClusterIdentifier,
|
|
874
1182
|
Engine: properties["Engine"],
|
|
875
1183
|
EngineVersion: properties["EngineVersion"],
|
|
@@ -901,16 +1209,31 @@ async function createDBCluster(logicalId, resourceType, properties, mask, replay
|
|
|
901
1209
|
...globalClusterId !== void 0 && { GlobalClusterIdentifier: globalClusterId },
|
|
902
1210
|
...expressFlag !== void 0 && !expressSkipped && { WithExpressConfiguration: express },
|
|
903
1211
|
...tags.length > 0 && { Tags: tags }
|
|
904
|
-
}));
|
|
1212
|
+
})));
|
|
905
1213
|
clusterLeftBehind = true;
|
|
906
1214
|
createdResourceId = response.DBCluster?.DbClusterResourceId;
|
|
907
1215
|
reportCreatedResource(logicalId, resourceType, dbClusterIdentifier, createdResourceId);
|
|
908
|
-
|
|
1216
|
+
const cluster = response.DBCluster;
|
|
1217
|
+
if (!cluster) throw new Error(`${restore === void 0 ? "CreateDBCluster" : "RestoreDBClusterToPointInTime"} did not return DBCluster`);
|
|
1218
|
+
if (restore !== void 0) {
|
|
1219
|
+
const differs = restoredDifferences(properties, cluster);
|
|
1220
|
+
if (differs.length > 0) this.logger.warn(safeMsg`DBCluster ${logicalId}: the restored cluster keeps its source's ${differs.join(", ")}, not the template's, as in CloudFormation: a restore does not set ${differs.length === 1 ? "it" : "them"}.`);
|
|
1221
|
+
}
|
|
909
1222
|
this.logger.debug(`Successfully created DBCluster ${logicalId}: ${dbClusterIdentifier}`);
|
|
910
1223
|
const wantsDeletionProtection = properties["DeletionProtection"] === true;
|
|
911
1224
|
try {
|
|
1225
|
+
if (restore !== void 0) {
|
|
1226
|
+
await this.waitForClusterAvailable(logicalId, dbClusterIdentifier, restoreWaitMs(), "being restored");
|
|
1227
|
+
await sendRestoreFollowUp.call(this, logicalId, dbClusterIdentifier, pointInTimeRestoreFollowUp(properties, logExports, limitless));
|
|
1228
|
+
if (httpEndpoint === true && properties["EngineMode"] !== "serverless") {
|
|
1229
|
+
const arn = cluster.DBClusterArn ?? (await this.describeDBCluster(dbClusterIdentifier))?.DBClusterArn;
|
|
1230
|
+
if (arn === void 0) throw new Error("The restored DBCluster has no ARN to enable the Data API on");
|
|
1231
|
+
await this.sendHttpEndpointChange(logicalId, dbClusterIdentifier, arn, true);
|
|
1232
|
+
if (process.env["CDKD_NO_WAIT"] !== "true") await this.waitForClusterState(logicalId, dbClusterIdentifier, (live) => live.HttpEndpointEnabled === true, "HTTP endpoint (Data API) setting");
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
912
1235
|
if (process.env["CDKD_NO_WAIT"] !== "true") {
|
|
913
|
-
await this.waitForClusterAvailable(logicalId, dbClusterIdentifier);
|
|
1236
|
+
await this.waitForClusterAvailable(logicalId, dbClusterIdentifier, restore === void 0 ? void 0 : restoreWaitMs(), restore === void 0 ? void 0 : "applying the restored cluster settings");
|
|
914
1237
|
if (localWriteForwardingFlag(properties["EnableLocalWriteForwarding"]) === true) await this.waitForClusterState(logicalId, dbClusterIdentifier, (cluster) => localWriteForwardingApplied(cluster, true), "local write forwarding setting");
|
|
915
1238
|
if (express) await this.waitForInstanceAvailable(logicalId, expressWriterIdentifier(dbClusterIdentifier));
|
|
916
1239
|
}
|
|
@@ -1129,7 +1452,7 @@ async function updateDBCluster(logicalId, physicalId, resourceType, properties,
|
|
|
1129
1452
|
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`);
|
|
1130
1453
|
skippedKeys.push(["AllocatedStorage", usableClusterSize]);
|
|
1131
1454
|
});
|
|
1132
|
-
if (globalClusterPlan.kind === "detach") {
|
|
1455
|
+
if (globalClusterPlan.kind === "detach" && !await restoredOutsideGlobalCluster.call(this, previousProperties, physicalId, globalClusterPlan.globalClusterId)) {
|
|
1133
1456
|
if (await this.detachFromGlobalCluster(logicalId, physicalId, globalClusterPlan.globalClusterId, {
|
|
1134
1457
|
beforeDelete: false,
|
|
1135
1458
|
removeProtection: false
|
|
@@ -1233,6 +1556,7 @@ async function planGlobalClusterUpdate(physicalId, properties, previousPropertie
|
|
|
1233
1556
|
if (!stateBorne || desiredId === void 0) return { kind: "none" };
|
|
1234
1557
|
const live = await liveGlobalClusterMembership.call(this, physicalId, desiredId);
|
|
1235
1558
|
if (live.kind !== "answered" || live.member) return { kind: "none" };
|
|
1559
|
+
if (isRestoredRecord(previousProperties)) return { kind: "none" };
|
|
1236
1560
|
this.logger.warn(mask(safeMsg`${logicalId} (${resourceType}): the cluster is no longer a member of global cluster ${desiredId}, so the record drops GlobalClusterIdentifier.`));
|
|
1237
1561
|
return { kind: "drop" };
|
|
1238
1562
|
}
|
|
@@ -1273,9 +1597,10 @@ async function liveGlobalClusterMembership(physicalId, desiredId) {
|
|
|
1273
1597
|
}
|
|
1274
1598
|
marker = page.Marker;
|
|
1275
1599
|
} while (marker);
|
|
1600
|
+
const idOf = (id) => id === void 0 ? void 0 : (id.split(":").pop() ?? id).toLowerCase();
|
|
1276
1601
|
return {
|
|
1277
1602
|
kind: "answered",
|
|
1278
|
-
member: liveId === desiredId
|
|
1603
|
+
member: idOf(liveId) === idOf(desiredId)
|
|
1279
1604
|
};
|
|
1280
1605
|
} catch (error) {
|
|
1281
1606
|
const failure = describeAwsFailure(error);
|
|
@@ -1286,6 +1611,11 @@ async function liveGlobalClusterMembership(physicalId, desiredId) {
|
|
|
1286
1611
|
};
|
|
1287
1612
|
}
|
|
1288
1613
|
}
|
|
1614
|
+
async function restoredOutsideGlobalCluster(properties, physicalId, globalClusterId) {
|
|
1615
|
+
if (!isRestoredRecord(properties)) return false;
|
|
1616
|
+
const live = await liveGlobalClusterMembership.call(this, physicalId, globalClusterId);
|
|
1617
|
+
return live.kind === "answered" && !live.member;
|
|
1618
|
+
}
|
|
1289
1619
|
|
|
1290
1620
|
// src/provisioning/providers/rds/cluster-delete.ts
|
|
1291
1621
|
async function deleteDBCluster(logicalId, physicalId, resourceType, properties, context) {
|
|
@@ -1365,13 +1695,15 @@ async function deleteDBClusterOnce(logicalId, physicalId, resourceType, properti
|
|
|
1365
1695
|
} catch (disableError) {
|
|
1366
1696
|
if (!this.isNotFoundError(disableError, "DBClusterNotFoundFault")) this.logger.debug(maskerOrIdentity(context?.maskSecrets)(`Could not disable deletion protection for DBCluster ${logicalId}: ${describeAwsFailure(disableError).detail}`));
|
|
1367
1697
|
}
|
|
1698
|
+
const restored = isRestoredRecord(properties);
|
|
1368
1699
|
const globalClusterId = recordedGlobalClusterIdentifier(properties);
|
|
1369
|
-
if (globalClusterId !== void 0) detachedFrom = await this.detachFromGlobalCluster(logicalId, physicalId, globalClusterId, {
|
|
1700
|
+
if (globalClusterId !== void 0 && !await restoredOutsideGlobalCluster.call(this, properties, physicalId, globalClusterId)) detachedFrom = await this.detachFromGlobalCluster(logicalId, physicalId, globalClusterId, {
|
|
1370
1701
|
beforeDelete: true,
|
|
1371
1702
|
removeProtection: context?.removeProtection === true
|
|
1372
1703
|
}, progress, maskerOrIdentity(context?.maskSecrets)) ? globalClusterId : void 0;
|
|
1373
|
-
|
|
1374
|
-
|
|
1704
|
+
const recordedWriterId = recordedExpressWriterId(context?.recordedAttributes);
|
|
1705
|
+
if (!(restored && recordedWriterId === void 0) && expressConfigurationFlag(properties?.["WithExpressConfiguration"]) === true) {
|
|
1706
|
+
if (await deleteExpressWriter.call(this, logicalId, physicalId, await this.describeDBCluster(physicalId), recordedWriterId, flip.flippedOffByThisRun, maskerOrIdentity(context?.maskSecrets))) progress.stripped = true;
|
|
1375
1707
|
}
|
|
1376
1708
|
const finalSnapshotId = context?.finalSnapshotIdentifier;
|
|
1377
1709
|
const sendDelete = () => this.getClient().send(new DeleteDBClusterCommand({
|
|
@@ -1510,6 +1842,232 @@ async function deleteAfterProtectionFlip(logicalId, physicalId, send) {
|
|
|
1510
1842
|
});
|
|
1511
1843
|
}
|
|
1512
1844
|
|
|
1845
|
+
// src/provisioning/providers/rds/calls.ts
|
|
1846
|
+
async function applyTagDiff(arn, resourceType, logicalId, oldTagsRaw, newTagsRaw) {
|
|
1847
|
+
const plan = planTagDiff(oldTagsRaw, newTagsRaw);
|
|
1848
|
+
const tagWarning = tagPlanWarning(plan, resourceType, logicalId);
|
|
1849
|
+
if (tagWarning !== void 0) this.logger.warn(tagWarning);
|
|
1850
|
+
const tagsToAdd = [...plan.set].map(([Key, Value]) => ({
|
|
1851
|
+
Key,
|
|
1852
|
+
Value
|
|
1853
|
+
}));
|
|
1854
|
+
const tagsToRemove = plan.remove;
|
|
1855
|
+
if (tagsToRemove.length > 0) {
|
|
1856
|
+
await this.getClient().send(new RemoveTagsFromResourceCommand({
|
|
1857
|
+
ResourceName: arn,
|
|
1858
|
+
TagKeys: tagsToRemove
|
|
1859
|
+
}));
|
|
1860
|
+
this.logger.debug(`Removed ${tagsToRemove.length} tag(s) from RDS resource ${arn}`);
|
|
1861
|
+
}
|
|
1862
|
+
if (tagsToAdd.length > 0) {
|
|
1863
|
+
await this.getClient().send(new AddTagsToResourceCommand({
|
|
1864
|
+
ResourceName: arn,
|
|
1865
|
+
Tags: tagsToAdd
|
|
1866
|
+
}));
|
|
1867
|
+
this.logger.debug(`Added/updated ${tagsToAdd.length} tag(s) on RDS resource ${arn}`);
|
|
1868
|
+
}
|
|
1869
|
+
}
|
|
1870
|
+
function isNotFoundError(error, faultName) {
|
|
1871
|
+
if (!(error instanceof Error)) return false;
|
|
1872
|
+
const name = error.name ?? "";
|
|
1873
|
+
const message = error.message.toLowerCase();
|
|
1874
|
+
return name === faultName || message.includes("not found") || message.includes("does not exist");
|
|
1875
|
+
}
|
|
1876
|
+
function wrapCaughtError(mask, error, build) {
|
|
1877
|
+
const m = maskerOrIdentity(mask);
|
|
1878
|
+
const failure = describeAwsFailure(error);
|
|
1879
|
+
if (!failure.redacted) return wrapMaskedAwsError(m, error, build);
|
|
1880
|
+
this.logger.debug(m(build(m(failure.detail)).message));
|
|
1881
|
+
const wrapped = build(`${m(failure.summary)}${relayedNameCollision(failure.detail)}`);
|
|
1882
|
+
return error instanceof Error ? markRedactedCause(wrapped) : wrapped;
|
|
1883
|
+
}
|
|
1884
|
+
function wrapDeleteError(mask, error, build) {
|
|
1885
|
+
const thrown = this.wrapCaughtError(mask, error, build);
|
|
1886
|
+
return error instanceof Error && error.name.includes("NotFound") ? markNotGone(thrown) : thrown;
|
|
1887
|
+
}
|
|
1888
|
+
async function engineLifecycleSupportToSend(kind, logicalId, physicalId, resourceType, properties, previousProperties, context) {
|
|
1889
|
+
const action = engineLifecycleSupportAction(properties, previousProperties, context);
|
|
1890
|
+
if (action === "unchanged") return void 0;
|
|
1891
|
+
const desired = engineLifecycleSupportOf(properties);
|
|
1892
|
+
if (action === "send") return desired;
|
|
1893
|
+
const idKey = kind === "DB cluster" ? "DBClusterIdentifier" : "DBInstanceIdentifier";
|
|
1894
|
+
const { mask } = withDerivedNameMasks(this.logger, createMaskedLogSinks(this.logger, context?.maskSecrets), [[previousProperties[idKey], physicalId]]);
|
|
1895
|
+
let liveRead = "read";
|
|
1896
|
+
if (action === "check-live") try {
|
|
1897
|
+
const resource = kind === "DB cluster" ? await this.describeDBCluster(physicalId) : await this.describeDBInstance(physicalId);
|
|
1898
|
+
if (resource === void 0) liveRead = "not-found";
|
|
1899
|
+
else if (resource.EngineLifecycleSupport === desired) liveRead = void 0;
|
|
1900
|
+
} catch (err) {
|
|
1901
|
+
if (err instanceof CdkdError) throw err;
|
|
1902
|
+
const faultName = err?.name;
|
|
1903
|
+
if (faultName === "DBClusterNotFoundFault" || faultName === "DBInstanceNotFoundFault") liveRead = "not-found";
|
|
1904
|
+
else throw this.wrapCaughtError(mask, err, (text) => new ProvisioningError(`${mask(engineLifecycleSupportRefusalText(resourceType, logicalId, physicalId, kind, "unreadable"))} The read failed: ${text}`, resourceType, logicalId, physicalId, err instanceof Error ? err : void 0));
|
|
1905
|
+
}
|
|
1906
|
+
if (liveRead === void 0) return void 0;
|
|
1907
|
+
throw markNonRetryable(new ProvisioningError(mask(engineLifecycleSupportRefusalText(resourceType, logicalId, physicalId, kind, liveRead)), resourceType, logicalId, physicalId));
|
|
1908
|
+
}
|
|
1909
|
+
async function describeDBCluster(dbClusterIdentifier) {
|
|
1910
|
+
return (await this.getClient().send(new DescribeDBClustersCommand({ DBClusterIdentifier: dbClusterIdentifier }))).DBClusters?.[0];
|
|
1911
|
+
}
|
|
1912
|
+
async function securityGroupsToSend(target, logicalId, physicalId, resourceType, properties, previousProperties, context) {
|
|
1913
|
+
const key = target === "DBCluster" ? "VpcSecurityGroupIds" : "VPCSecurityGroups";
|
|
1914
|
+
const noun = target === "DBCluster" ? "cluster" : "instance";
|
|
1915
|
+
const desired = properties[key];
|
|
1916
|
+
if (desired !== void 0) return desired.length > 0 ? desired : void 0;
|
|
1917
|
+
const previous = previousProperties[key];
|
|
1918
|
+
if (context?.desiredFromAwsReadback === true) return void 0;
|
|
1919
|
+
if (!Array.isArray(previous) || previous.length === 0) return void 0;
|
|
1920
|
+
let groupId;
|
|
1921
|
+
let missing;
|
|
1922
|
+
let awsError;
|
|
1923
|
+
try {
|
|
1924
|
+
let subnetGroupName;
|
|
1925
|
+
let vpcId;
|
|
1926
|
+
if (target === "DBInstance") {
|
|
1927
|
+
const subnetGroup = (await this.describeDBInstance(physicalId))?.DBSubnetGroup;
|
|
1928
|
+
subnetGroupName = subnetGroup?.DBSubnetGroupName;
|
|
1929
|
+
vpcId = subnetGroupName ? subnetGroup?.VpcId : void 0;
|
|
1930
|
+
} else {
|
|
1931
|
+
subnetGroupName = (await this.describeDBCluster(physicalId))?.DBSubnetGroup;
|
|
1932
|
+
vpcId = subnetGroupName ? (await this.getClient().send(new DescribeDBSubnetGroupsCommand({ DBSubnetGroupName: subnetGroupName }))).DBSubnetGroups?.[0]?.VpcId : void 0;
|
|
1933
|
+
}
|
|
1934
|
+
if (!subnetGroupName) missing = `the ${noun} reports no DB subnet group`;
|
|
1935
|
+
else if (!vpcId) missing = `DB subnet group ${subnetGroupName} reports no VPC`;
|
|
1936
|
+
else {
|
|
1937
|
+
groupId = (await this.getEc2Client().send(new DescribeSecurityGroupsCommand({ Filters: [{
|
|
1938
|
+
Name: "vpc-id",
|
|
1939
|
+
Values: [vpcId]
|
|
1940
|
+
}, {
|
|
1941
|
+
Name: "group-name",
|
|
1942
|
+
Values: ["default"]
|
|
1943
|
+
}] }))).SecurityGroups?.[0]?.GroupId;
|
|
1944
|
+
if (!groupId) missing = `VPC ${vpcId} has no security group named default`;
|
|
1945
|
+
}
|
|
1946
|
+
} catch (error) {
|
|
1947
|
+
awsError = error;
|
|
1948
|
+
}
|
|
1949
|
+
if (groupId === void 0) {
|
|
1950
|
+
const mask = context?.maskSecrets ?? ((text) => text);
|
|
1951
|
+
const failure = missing === void 0 ? describeAwsFailure(awsError) : void 0;
|
|
1952
|
+
if (failure?.redacted === true) this.logger.debug(safeMsg`${logicalId}: the VPC default security group lookup failed: ${mask(failure.detail)}`);
|
|
1953
|
+
const shown = mask(failure?.summary ?? "");
|
|
1954
|
+
const refusal = new ProvisioningError(`Failed to update ${target} ${logicalId}: ${key} was removed from the template, so the ${noun} moves to its VPC's default security group (as CloudFormation does), but cdkd could not find that group: ${missing ?? shown}. Declare ${key} in the template to choose the ${noun}'s security groups.`, resourceType, logicalId, physicalId, awsError instanceof Error ? awsError : void 0);
|
|
1955
|
+
if (missing !== void 0) throw markNonRetryable(refusal);
|
|
1956
|
+
throw awsError instanceof Error && (failure?.redacted === true || shown !== (failure?.summary ?? "")) ? markRedactedCause(refusal) : refusal;
|
|
1957
|
+
}
|
|
1958
|
+
this.logger.warn(safeMsg`${logicalId}: ${key} was removed from the template; attaching the VPC's default security group ${groupId}, as CloudFormation does.`);
|
|
1959
|
+
return [groupId];
|
|
1960
|
+
}
|
|
1961
|
+
async function describeDBInstance(dbInstanceIdentifier) {
|
|
1962
|
+
return (await this.getClient().send(new DescribeDBInstancesCommand({ DBInstanceIdentifier: dbInstanceIdentifier }))).DBInstances?.[0];
|
|
1963
|
+
}
|
|
1964
|
+
async function sendHttpEndpointChange(logicalId, physicalId, arn, enable) {
|
|
1965
|
+
let delay = 5e3;
|
|
1966
|
+
for (let attempt = 1;; attempt += 1) {
|
|
1967
|
+
await this.waitForClusterState(logicalId, physicalId, (cluster) => cluster.Status === "available", "pending changes to settle before the Data API call");
|
|
1968
|
+
try {
|
|
1969
|
+
await this.getClient().send(enable ? new EnableHttpEndpointCommand({ ResourceArn: arn }) : new DisableHttpEndpointCommand({ ResourceArn: arn }));
|
|
1970
|
+
return;
|
|
1971
|
+
} catch (error) {
|
|
1972
|
+
const name = awsErrorName(error);
|
|
1973
|
+
if (!HTTP_ENDPOINT_BUSY_FAULTS.has(name) || attempt >= 8) throw error;
|
|
1974
|
+
this.logger.debug(safeMsg`DBCluster ${logicalId}: the Data API call was refused as busy (${name}); retrying`);
|
|
1975
|
+
await this.sleep(delay);
|
|
1976
|
+
delay = Math.min(delay * 2, 1e4);
|
|
1977
|
+
}
|
|
1978
|
+
}
|
|
1979
|
+
}
|
|
1980
|
+
async function attachTags(result, arn) {
|
|
1981
|
+
try {
|
|
1982
|
+
const tagsResp = await this.getClient().send(new ListTagsForResourceCommand({ ResourceName: arn }));
|
|
1983
|
+
result["Tags"] = normalizeAwsTagsToCfn(tagsResp.TagList);
|
|
1984
|
+
} catch (err) {
|
|
1985
|
+
this.logger.debug(`RDS ListTagsForResource(${arn}) failed: ${describeAwsFailure(err).detail}`);
|
|
1986
|
+
}
|
|
1987
|
+
}
|
|
1988
|
+
async function sendInRegion(region, call) {
|
|
1989
|
+
const client = new RDSClient({
|
|
1990
|
+
...ambientClientDefaults(),
|
|
1991
|
+
region
|
|
1992
|
+
});
|
|
1993
|
+
try {
|
|
1994
|
+
return await call(client);
|
|
1995
|
+
} finally {
|
|
1996
|
+
client.destroy();
|
|
1997
|
+
}
|
|
1998
|
+
}
|
|
1999
|
+
const REPLICATION_KMS_KEY_ERROR = "Encrypted instances require a valid KMS key ID";
|
|
2000
|
+
const REPLICATION_BUSY_FAULTS = /* @__PURE__ */ new Set([
|
|
2001
|
+
"InvalidDBInstanceStateFault",
|
|
2002
|
+
"InvalidDBInstanceState",
|
|
2003
|
+
"InvalidDBInstanceAutomatedBackupStateFault",
|
|
2004
|
+
"InvalidDBInstanceAutomatedBackupState"
|
|
2005
|
+
]);
|
|
2006
|
+
const REPLICATION_MAX_ATTEMPTS = 10;
|
|
2007
|
+
async function sendReplicationCall(logicalId, physicalId, region, call) {
|
|
2008
|
+
for (let attempt = 1;; attempt++) try {
|
|
2009
|
+
return await sendInRegion(region, call);
|
|
2010
|
+
} catch (error) {
|
|
2011
|
+
if (!REPLICATION_BUSY_FAULTS.has(awsErrorName(error)) || attempt >= REPLICATION_MAX_ATTEMPTS) throw error;
|
|
2012
|
+
this.logger.debug(safeMsg`${logicalId}: automated backup replication call refused as busy (${awsErrorName(error)}); waiting to resend`);
|
|
2013
|
+
await this.sleep(15e3);
|
|
2014
|
+
const budgetMs = Math.min(18e5, enclosingDeadlineRemainingMs() - 3e4);
|
|
2015
|
+
if (budgetMs <= 0) throw error;
|
|
2016
|
+
await this.waitForInstanceAvailable(logicalId, physicalId, budgetMs, "changing its automated backup replication");
|
|
2017
|
+
}
|
|
2018
|
+
}
|
|
2019
|
+
async function applyBackupReplication(logicalId, physicalId, plan, fromReadback = false) {
|
|
2020
|
+
if (!plan.stop && plan.start === void 0) return;
|
|
2021
|
+
const waitBudgetMs = Math.min(18e5, enclosingDeadlineRemainingMs() - 3e4);
|
|
2022
|
+
if (waitBudgetMs <= 0) throw new Error("the resource timeout leaves no more time to change the automated backup replication of the instance; re-run the deploy, or with a longer --resource-timeout");
|
|
2023
|
+
if (fromReadback && plan.start !== void 0 && plan.start.kmsKeyId === void 0) {
|
|
2024
|
+
if ((await this.describeDBInstance(physicalId))?.StorageEncrypted === true) throw markNonRetryable(/* @__PURE__ */ new Error(`cdkd drift --revert cannot restart the automated backup replication of storage-encrypted DB instance ${logicalId}: RDS needs a KMS key in ${plan.start.region} for it, and AutomaticBackupReplicationKmsKeyId is write-only, so the revert has none to send. Nothing was stopped or started. Restore it with aws rds start-db-instance-automated-backups-replication --region ${plan.start.region} --source-db-instance-arn <the instance ARN> --kms-key-id <a key in that region>, or change the template's replication properties and run cdkd deploy`));
|
|
2025
|
+
}
|
|
2026
|
+
await this.waitForInstanceAvailable(logicalId, physicalId, waitBudgetMs, "changing its automated backup replication");
|
|
2027
|
+
const instance = await this.describeDBInstance(physicalId);
|
|
2028
|
+
const arn = instance?.DBInstanceArn;
|
|
2029
|
+
if (instance === void 0 || arn === void 0) throw new Error("DescribeDBInstances returned no instance ARN while changing its automated backup replication; nothing was started or stopped");
|
|
2030
|
+
const wait = process.env["CDKD_NO_WAIT"] !== "true";
|
|
2031
|
+
const live = liveBackupReplicationRegions(instance);
|
|
2032
|
+
for (const region of live) {
|
|
2033
|
+
this.logger.debug(safeMsg`Stopping automated backup replication of ${logicalId} to ${region}`);
|
|
2034
|
+
await sendReplicationCall.call(this, logicalId, physicalId, region, (client) => client.send(new StopDBInstanceAutomatedBackupsReplicationCommand({ SourceDBInstanceArn: arn })));
|
|
2035
|
+
}
|
|
2036
|
+
if (live.length > 0 && (wait || plan.start !== void 0)) await this.waitForInstanceState(logicalId, physicalId, (current) => current.DBInstanceStatus === "available" && liveBackupReplicationRegions(current).length === 0, "automated backup replication stop");
|
|
2037
|
+
const start = plan.start;
|
|
2038
|
+
if (start === void 0) return;
|
|
2039
|
+
this.logger.debug(safeMsg`Starting automated backup replication of ${logicalId} to ${start.region}`);
|
|
2040
|
+
try {
|
|
2041
|
+
await sendReplicationCall.call(this, logicalId, physicalId, start.region, (client) => client.send(new StartDBInstanceAutomatedBackupsReplicationCommand({
|
|
2042
|
+
SourceDBInstanceArn: arn,
|
|
2043
|
+
...start.retention !== void 0 && { BackupRetentionPeriod: start.retention },
|
|
2044
|
+
...start.kmsKeyId !== void 0 && { KmsKeyId: start.kmsKeyId }
|
|
2045
|
+
})));
|
|
2046
|
+
} catch (error) {
|
|
2047
|
+
if (error instanceof Error && error.message.includes(REPLICATION_KMS_KEY_ERROR)) error.message = `${error.message} Provide a valid value for the AutomaticBackupReplicationKmsKeyId property.`;
|
|
2048
|
+
throw error;
|
|
2049
|
+
}
|
|
2050
|
+
if (wait) await this.waitForInstanceState(logicalId, physicalId, (current) => current.DBInstanceStatus === "available" && liveBackupReplicationRegions(current).includes(start.region), "automated backup replication start");
|
|
2051
|
+
}
|
|
2052
|
+
const RETENTION_READ_SOFT_FAULTS = /* @__PURE__ */ new Set([
|
|
2053
|
+
"DBInstanceAutomatedBackupNotFoundFault",
|
|
2054
|
+
"DBInstanceAutomatedBackupNotFound",
|
|
2055
|
+
"AccessDenied",
|
|
2056
|
+
"AccessDeniedException"
|
|
2057
|
+
]);
|
|
2058
|
+
async function replicatedBackupRetention(automatedBackupsArn) {
|
|
2059
|
+
const region = automatedBackupsArn.split(":")[3];
|
|
2060
|
+
if (region === void 0 || region === "") return void 0;
|
|
2061
|
+
try {
|
|
2062
|
+
return (await sendInRegion(region, (client) => client.send(new DescribeDBInstanceAutomatedBackupsCommand({ DBInstanceAutomatedBackupsArn: automatedBackupsArn })))).DBInstanceAutomatedBackups?.[0]?.BackupRetentionPeriod;
|
|
2063
|
+
} catch (error) {
|
|
2064
|
+
const name = awsErrorName(error);
|
|
2065
|
+
if (!RETENTION_READ_SOFT_FAULTS.has(name)) throw error;
|
|
2066
|
+
if (name.startsWith("AccessDenied")) this.logger.warn(safeMsg`Could not read the replicated automated backup's retention in ${region} (${name}): AutomaticBackupReplicationRetentionPeriod reads as unset`);
|
|
2067
|
+
return;
|
|
2068
|
+
}
|
|
2069
|
+
}
|
|
2070
|
+
|
|
1513
2071
|
// src/provisioning/providers/rds/instance-create.ts
|
|
1514
2072
|
async function createDBInstance(logicalId, resourceType, properties, mask, replaying = false) {
|
|
1515
2073
|
this.logger.debug(`Creating DBInstance ${logicalId}`);
|
|
@@ -1517,6 +2075,7 @@ async function createDBInstance(logicalId, resourceType, properties, mask, repla
|
|
|
1517
2075
|
const roles = this.desiredAssociatedRoles(properties, resourceType, logicalId, void 0, replaying);
|
|
1518
2076
|
const logExports = desiredLogExports(properties, resourceType, logicalId);
|
|
1519
2077
|
const processor = desiredProcessorFeatures(properties, resourceType, logicalId);
|
|
2078
|
+
const replication = backupReplicationPlan(properties, {}, resourceType, logicalId, void 0, replaying, (message) => this.logger.warn(message));
|
|
1520
2079
|
refuseMalformedReplicaSource(properties, resourceType, logicalId);
|
|
1521
2080
|
refuseUnknownSourceRegion(properties, resourceType, logicalId, replaying, (message) => this.logger.warn(message));
|
|
1522
2081
|
const replicaSource = replicaSourceOf(properties);
|
|
@@ -1574,6 +2133,9 @@ async function createDBInstance(logicalId, resourceType, properties, mask, repla
|
|
|
1574
2133
|
...logExports !== void 0 && logExports.length > 0 && { EnableCloudwatchLogsExports: logExports },
|
|
1575
2134
|
...properties["DBName"] != null && { DBName: properties["DBName"] },
|
|
1576
2135
|
...properties["AvailabilityZone"] != null && { AvailabilityZone: properties["AvailabilityZone"] },
|
|
2136
|
+
...properties["CharacterSetName"] != null && { CharacterSetName: properties["CharacterSetName"] },
|
|
2137
|
+
...properties["NcharCharacterSetName"] != null && { NcharCharacterSetName: properties["NcharCharacterSetName"] },
|
|
2138
|
+
...properties["Timezone"] != null && { Timezone: properties["Timezone"] },
|
|
1577
2139
|
...processor.features !== void 0 && { ProcessorFeatures: processor.features },
|
|
1578
2140
|
...tags.length > 0 && { Tags: tags }
|
|
1579
2141
|
});
|
|
@@ -1599,11 +2161,12 @@ async function createDBInstance(logicalId, resourceType, properties, mask, repla
|
|
|
1599
2161
|
const modifyAfterCreate = replicaSource !== void 0 && replicaNeedsModifyAfterCreate(properties, replicaEngineName, instance.Engine);
|
|
1600
2162
|
if (process.env["CDKD_NO_WAIT"] !== "true" || modifyAfterCreate) await this.waitForInstanceAvailable(logicalId, dbInstanceIdentifier);
|
|
1601
2163
|
if (modifyAfterCreate) await modifyReplicaAfterCreate.call(this, logicalId, dbInstanceIdentifier, properties, replicaEngineName);
|
|
1602
|
-
|
|
1603
|
-
await this.applyAssociatedRoles("instance", logicalId, dbInstanceIdentifier, roles, [], mask, void 0);
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
2164
|
+
try {
|
|
2165
|
+
if (roles !== "skipped") await this.applyAssociatedRoles("instance", logicalId, dbInstanceIdentifier, roles, [], mask, void 0);
|
|
2166
|
+
await applyBackupReplication.call(this, logicalId, dbInstanceIdentifier, replication);
|
|
2167
|
+
} catch (auxiliaryError) {
|
|
2168
|
+
markAuxiliaryFailure(auxiliaryError, logicalId);
|
|
2169
|
+
throw auxiliaryError;
|
|
1607
2170
|
}
|
|
1608
2171
|
const described = await this.describeDBInstance(dbInstanceIdentifier);
|
|
1609
2172
|
return {
|
|
@@ -1660,6 +2223,7 @@ async function updateDBInstance(logicalId, physicalId, resourceType, properties,
|
|
|
1660
2223
|
const roles = this.desiredAssociatedRoles(properties, resourceType, logicalId, physicalId, false);
|
|
1661
2224
|
const logExportConfig = logExportsDelta(desiredLogExports(properties, resourceType, logicalId, physicalId), previousProperties["EnableCloudwatchLogsExports"]);
|
|
1662
2225
|
const processorMembers = instanceProcessorFeatureMembers(properties, previousProperties, resourceType, logicalId, physicalId);
|
|
2226
|
+
const replication = backupReplicationPlan(properties, previousProperties, resourceType, logicalId, physicalId, context?.replayingState === true || context?.desiredFromAwsReadback === true, (message) => this.logger.warn(message));
|
|
1663
2227
|
const vpcSgIds = await this.securityGroupsToSend("DBInstance", logicalId, physicalId, resourceType, properties, previousProperties, context);
|
|
1664
2228
|
const engineLifecycleSupport = await this.engineLifecycleSupportToSend("DB instance", logicalId, physicalId, resourceType, properties, previousProperties, context);
|
|
1665
2229
|
let authenticationType = masterUserAuthenticationTypeToSend(properties, previousProperties, context);
|
|
@@ -1789,6 +2353,7 @@ async function updateDBInstance(logicalId, physicalId, resourceType, properties,
|
|
|
1789
2353
|
const sentGroup = backfillMembers.DBParameterGroupName;
|
|
1790
2354
|
if (sentGroup !== void 0 || instanceParameterGroupPendingReboot(described) || instanceParameterGroupApplying(described)) described = await this.rebootForPendingParameterGroup(logicalId, physicalId, sentGroup, String(properties["CertificateRotationRestart"]) === "true");
|
|
1791
2355
|
await this.applyAssociatedRoles("instance", logicalId, physicalId, roles, associatedRoleList(previousProperties["AssociatedRoles"], { featureNameRequired: true }) ?? [], context?.maskSecrets, context);
|
|
2356
|
+
await applyBackupReplication.call(this, logicalId, physicalId, replication, context?.desiredFromAwsReadback === true);
|
|
1792
2357
|
if (described?.DBInstanceArn) await this.applyTagDiff(described.DBInstanceArn, resourceType, logicalId, previousProperties["Tags"], properties["Tags"]);
|
|
1793
2358
|
return {
|
|
1794
2359
|
physicalId,
|
|
@@ -1935,150 +2500,6 @@ async function deleteInstanceAfterProtectionFlip(logicalId, physicalId, send) {
|
|
|
1935
2500
|
});
|
|
1936
2501
|
}
|
|
1937
2502
|
|
|
1938
|
-
// src/provisioning/providers/rds/calls.ts
|
|
1939
|
-
async function applyTagDiff(arn, resourceType, logicalId, oldTagsRaw, newTagsRaw) {
|
|
1940
|
-
const plan = planTagDiff(oldTagsRaw, newTagsRaw);
|
|
1941
|
-
const tagWarning = tagPlanWarning(plan, resourceType, logicalId);
|
|
1942
|
-
if (tagWarning !== void 0) this.logger.warn(tagWarning);
|
|
1943
|
-
const tagsToAdd = [...plan.set].map(([Key, Value]) => ({
|
|
1944
|
-
Key,
|
|
1945
|
-
Value
|
|
1946
|
-
}));
|
|
1947
|
-
const tagsToRemove = plan.remove;
|
|
1948
|
-
if (tagsToRemove.length > 0) {
|
|
1949
|
-
await this.getClient().send(new RemoveTagsFromResourceCommand({
|
|
1950
|
-
ResourceName: arn,
|
|
1951
|
-
TagKeys: tagsToRemove
|
|
1952
|
-
}));
|
|
1953
|
-
this.logger.debug(`Removed ${tagsToRemove.length} tag(s) from RDS resource ${arn}`);
|
|
1954
|
-
}
|
|
1955
|
-
if (tagsToAdd.length > 0) {
|
|
1956
|
-
await this.getClient().send(new AddTagsToResourceCommand({
|
|
1957
|
-
ResourceName: arn,
|
|
1958
|
-
Tags: tagsToAdd
|
|
1959
|
-
}));
|
|
1960
|
-
this.logger.debug(`Added/updated ${tagsToAdd.length} tag(s) on RDS resource ${arn}`);
|
|
1961
|
-
}
|
|
1962
|
-
}
|
|
1963
|
-
function isNotFoundError(error, faultName) {
|
|
1964
|
-
if (!(error instanceof Error)) return false;
|
|
1965
|
-
const name = error.name ?? "";
|
|
1966
|
-
const message = error.message.toLowerCase();
|
|
1967
|
-
return name === faultName || message.includes("not found") || message.includes("does not exist");
|
|
1968
|
-
}
|
|
1969
|
-
function wrapCaughtError(mask, error, build) {
|
|
1970
|
-
const m = maskerOrIdentity(mask);
|
|
1971
|
-
const failure = describeAwsFailure(error);
|
|
1972
|
-
if (!failure.redacted) return wrapMaskedAwsError(m, error, build);
|
|
1973
|
-
this.logger.debug(m(build(m(failure.detail)).message));
|
|
1974
|
-
const wrapped = build(`${m(failure.summary)}${relayedNameCollision(failure.detail)}`);
|
|
1975
|
-
return error instanceof Error ? markRedactedCause(wrapped) : wrapped;
|
|
1976
|
-
}
|
|
1977
|
-
function wrapDeleteError(mask, error, build) {
|
|
1978
|
-
const thrown = this.wrapCaughtError(mask, error, build);
|
|
1979
|
-
return error instanceof Error && error.name.includes("NotFound") ? markNotGone(thrown) : thrown;
|
|
1980
|
-
}
|
|
1981
|
-
async function engineLifecycleSupportToSend(kind, logicalId, physicalId, resourceType, properties, previousProperties, context) {
|
|
1982
|
-
const action = engineLifecycleSupportAction(properties, previousProperties, context);
|
|
1983
|
-
if (action === "unchanged") return void 0;
|
|
1984
|
-
const desired = engineLifecycleSupportOf(properties);
|
|
1985
|
-
if (action === "send") return desired;
|
|
1986
|
-
const idKey = kind === "DB cluster" ? "DBClusterIdentifier" : "DBInstanceIdentifier";
|
|
1987
|
-
const { mask } = withDerivedNameMasks(this.logger, createMaskedLogSinks(this.logger, context?.maskSecrets), [[previousProperties[idKey], physicalId]]);
|
|
1988
|
-
let liveRead = "read";
|
|
1989
|
-
if (action === "check-live") try {
|
|
1990
|
-
const resource = kind === "DB cluster" ? await this.describeDBCluster(physicalId) : await this.describeDBInstance(physicalId);
|
|
1991
|
-
if (resource === void 0) liveRead = "not-found";
|
|
1992
|
-
else if (resource.EngineLifecycleSupport === desired) liveRead = void 0;
|
|
1993
|
-
} catch (err) {
|
|
1994
|
-
if (err instanceof CdkdError) throw err;
|
|
1995
|
-
const faultName = err?.name;
|
|
1996
|
-
if (faultName === "DBClusterNotFoundFault" || faultName === "DBInstanceNotFoundFault") liveRead = "not-found";
|
|
1997
|
-
else throw this.wrapCaughtError(mask, err, (text) => new ProvisioningError(`${mask(engineLifecycleSupportRefusalText(resourceType, logicalId, physicalId, kind, "unreadable"))} The read failed: ${text}`, resourceType, logicalId, physicalId, err instanceof Error ? err : void 0));
|
|
1998
|
-
}
|
|
1999
|
-
if (liveRead === void 0) return void 0;
|
|
2000
|
-
throw markNonRetryable(new ProvisioningError(mask(engineLifecycleSupportRefusalText(resourceType, logicalId, physicalId, kind, liveRead)), resourceType, logicalId, physicalId));
|
|
2001
|
-
}
|
|
2002
|
-
async function describeDBCluster(dbClusterIdentifier) {
|
|
2003
|
-
return (await this.getClient().send(new DescribeDBClustersCommand({ DBClusterIdentifier: dbClusterIdentifier }))).DBClusters?.[0];
|
|
2004
|
-
}
|
|
2005
|
-
async function securityGroupsToSend(target, logicalId, physicalId, resourceType, properties, previousProperties, context) {
|
|
2006
|
-
const key = target === "DBCluster" ? "VpcSecurityGroupIds" : "VPCSecurityGroups";
|
|
2007
|
-
const noun = target === "DBCluster" ? "cluster" : "instance";
|
|
2008
|
-
const desired = properties[key];
|
|
2009
|
-
if (desired !== void 0) return desired.length > 0 ? desired : void 0;
|
|
2010
|
-
const previous = previousProperties[key];
|
|
2011
|
-
if (context?.desiredFromAwsReadback === true) return void 0;
|
|
2012
|
-
if (!Array.isArray(previous) || previous.length === 0) return void 0;
|
|
2013
|
-
let groupId;
|
|
2014
|
-
let missing;
|
|
2015
|
-
let awsError;
|
|
2016
|
-
try {
|
|
2017
|
-
let subnetGroupName;
|
|
2018
|
-
let vpcId;
|
|
2019
|
-
if (target === "DBInstance") {
|
|
2020
|
-
const subnetGroup = (await this.describeDBInstance(physicalId))?.DBSubnetGroup;
|
|
2021
|
-
subnetGroupName = subnetGroup?.DBSubnetGroupName;
|
|
2022
|
-
vpcId = subnetGroupName ? subnetGroup?.VpcId : void 0;
|
|
2023
|
-
} else {
|
|
2024
|
-
subnetGroupName = (await this.describeDBCluster(physicalId))?.DBSubnetGroup;
|
|
2025
|
-
vpcId = subnetGroupName ? (await this.getClient().send(new DescribeDBSubnetGroupsCommand({ DBSubnetGroupName: subnetGroupName }))).DBSubnetGroups?.[0]?.VpcId : void 0;
|
|
2026
|
-
}
|
|
2027
|
-
if (!subnetGroupName) missing = `the ${noun} reports no DB subnet group`;
|
|
2028
|
-
else if (!vpcId) missing = `DB subnet group ${subnetGroupName} reports no VPC`;
|
|
2029
|
-
else {
|
|
2030
|
-
groupId = (await this.getEc2Client().send(new DescribeSecurityGroupsCommand({ Filters: [{
|
|
2031
|
-
Name: "vpc-id",
|
|
2032
|
-
Values: [vpcId]
|
|
2033
|
-
}, {
|
|
2034
|
-
Name: "group-name",
|
|
2035
|
-
Values: ["default"]
|
|
2036
|
-
}] }))).SecurityGroups?.[0]?.GroupId;
|
|
2037
|
-
if (!groupId) missing = `VPC ${vpcId} has no security group named default`;
|
|
2038
|
-
}
|
|
2039
|
-
} catch (error) {
|
|
2040
|
-
awsError = error;
|
|
2041
|
-
}
|
|
2042
|
-
if (groupId === void 0) {
|
|
2043
|
-
const mask = context?.maskSecrets ?? ((text) => text);
|
|
2044
|
-
const failure = missing === void 0 ? describeAwsFailure(awsError) : void 0;
|
|
2045
|
-
if (failure?.redacted === true) this.logger.debug(safeMsg`${logicalId}: the VPC default security group lookup failed: ${mask(failure.detail)}`);
|
|
2046
|
-
const shown = mask(failure?.summary ?? "");
|
|
2047
|
-
const refusal = new ProvisioningError(`Failed to update ${target} ${logicalId}: ${key} was removed from the template, so the ${noun} moves to its VPC's default security group (as CloudFormation does), but cdkd could not find that group: ${missing ?? shown}. Declare ${key} in the template to choose the ${noun}'s security groups.`, resourceType, logicalId, physicalId, awsError instanceof Error ? awsError : void 0);
|
|
2048
|
-
if (missing !== void 0) throw markNonRetryable(refusal);
|
|
2049
|
-
throw awsError instanceof Error && (failure?.redacted === true || shown !== (failure?.summary ?? "")) ? markRedactedCause(refusal) : refusal;
|
|
2050
|
-
}
|
|
2051
|
-
this.logger.warn(safeMsg`${logicalId}: ${key} was removed from the template; attaching the VPC's default security group ${groupId}, as CloudFormation does.`);
|
|
2052
|
-
return [groupId];
|
|
2053
|
-
}
|
|
2054
|
-
async function describeDBInstance(dbInstanceIdentifier) {
|
|
2055
|
-
return (await this.getClient().send(new DescribeDBInstancesCommand({ DBInstanceIdentifier: dbInstanceIdentifier }))).DBInstances?.[0];
|
|
2056
|
-
}
|
|
2057
|
-
async function sendHttpEndpointChange(logicalId, physicalId, arn, enable) {
|
|
2058
|
-
let delay = 5e3;
|
|
2059
|
-
for (let attempt = 1;; attempt += 1) {
|
|
2060
|
-
await this.waitForClusterState(logicalId, physicalId, (cluster) => cluster.Status === "available", "pending changes to settle before the Data API call");
|
|
2061
|
-
try {
|
|
2062
|
-
await this.getClient().send(enable ? new EnableHttpEndpointCommand({ ResourceArn: arn }) : new DisableHttpEndpointCommand({ ResourceArn: arn }));
|
|
2063
|
-
return;
|
|
2064
|
-
} catch (error) {
|
|
2065
|
-
const name = awsErrorName(error);
|
|
2066
|
-
if (!HTTP_ENDPOINT_BUSY_FAULTS.has(name) || attempt >= 8) throw error;
|
|
2067
|
-
this.logger.debug(safeMsg`DBCluster ${logicalId}: the Data API call was refused as busy (${name}); retrying`);
|
|
2068
|
-
await this.sleep(delay);
|
|
2069
|
-
delay = Math.min(delay * 2, 1e4);
|
|
2070
|
-
}
|
|
2071
|
-
}
|
|
2072
|
-
}
|
|
2073
|
-
async function attachTags(result, arn) {
|
|
2074
|
-
try {
|
|
2075
|
-
const tagsResp = await this.getClient().send(new ListTagsForResourceCommand({ ResourceName: arn }));
|
|
2076
|
-
result["Tags"] = normalizeAwsTagsToCfn(tagsResp.TagList);
|
|
2077
|
-
} catch (err) {
|
|
2078
|
-
this.logger.debug(`RDS ListTagsForResource(${arn}) failed: ${describeAwsFailure(err).detail}`);
|
|
2079
|
-
}
|
|
2080
|
-
}
|
|
2081
|
-
|
|
2082
2503
|
// src/provisioning/providers/rds/waits.ts
|
|
2083
2504
|
async function waitForMemberAfterClusterChange(dbInstanceIdentifier, clusterLogicalId, transitional, change, maxWaitMs = 18e5) {
|
|
2084
2505
|
const startTime = Date.now();
|
|
@@ -2314,10 +2735,16 @@ function getDriftUnknownPaths(resourceType, properties) {
|
|
|
2314
2735
|
"AllowMajorVersionUpgrade",
|
|
2315
2736
|
"CertificateRotationRestart",
|
|
2316
2737
|
"SourceRegion",
|
|
2317
|
-
"UseDefaultProcessorFeatures"
|
|
2738
|
+
"UseDefaultProcessorFeatures",
|
|
2739
|
+
"AutomaticBackupReplicationKmsKeyId"
|
|
2318
2740
|
];
|
|
2741
|
+
const retention = properties?.["AutomaticBackupReplicationRetentionPeriod"];
|
|
2319
2742
|
const declared = properties?.["ProcessorFeatures"];
|
|
2320
|
-
return
|
|
2743
|
+
return [
|
|
2744
|
+
...instanceUnknown,
|
|
2745
|
+
...declared == null || Array.isArray(declared) && declared.length === 0 ? ["ProcessorFeatures"] : [],
|
|
2746
|
+
...retention == null || retention === "" ? ["AutomaticBackupReplicationRetentionPeriod"] : []
|
|
2747
|
+
];
|
|
2321
2748
|
}
|
|
2322
2749
|
if (resourceType !== "AWS::RDS::DBCluster") return [];
|
|
2323
2750
|
const neverRead = [
|
|
@@ -2327,7 +2754,11 @@ function getDriftUnknownPaths(resourceType, properties) {
|
|
|
2327
2754
|
"MasterUserAuthenticationType",
|
|
2328
2755
|
"GlobalClusterIdentifier",
|
|
2329
2756
|
"DBInstanceParameterGroupName",
|
|
2330
|
-
"WithExpressConfiguration"
|
|
2757
|
+
"WithExpressConfiguration",
|
|
2758
|
+
"SourceDBClusterIdentifier",
|
|
2759
|
+
"RestoreToTime",
|
|
2760
|
+
"RestoreType",
|
|
2761
|
+
"UseLatestRestorableTime"
|
|
2331
2762
|
];
|
|
2332
2763
|
if (properties === void 0 || Object.keys(properties).length === 0) return neverRead;
|
|
2333
2764
|
return (properties?.["ServerlessV2ScalingConfiguration"])?.SecondsUntilAutoPause === void 0 ? [...neverRead, "ServerlessV2ScalingConfiguration.SecondsUntilAutoPause"] : neverRead;
|
|
@@ -2527,8 +2958,20 @@ async function readCurrentStateDBInstance(physicalId) {
|
|
|
2527
2958
|
Name: feature.Name,
|
|
2528
2959
|
Value: feature.Value
|
|
2529
2960
|
}));
|
|
2961
|
+
const replicationArn = inst.DBInstanceAutomatedBackupsReplications?.[0]?.DBInstanceAutomatedBackupsArn;
|
|
2962
|
+
const replicationRegion = replicationArn?.split(":")[3];
|
|
2963
|
+
if (replicationArn !== void 0 && replicationRegion !== void 0 && replicationRegion !== "") {
|
|
2964
|
+
result["AutomaticBackupReplicationRegion"] = replicationRegion;
|
|
2965
|
+
const retention = await replicatedBackupRetention.call(this, replicationArn);
|
|
2966
|
+
if (retention !== void 0) result["AutomaticBackupReplicationRetentionPeriod"] = retention;
|
|
2967
|
+
}
|
|
2530
2968
|
if (inst.DBName !== void 0) result["DBName"] = inst.DBName;
|
|
2531
2969
|
if (inst.AvailabilityZone !== void 0 && inst.MultiAZ !== true) result["AvailabilityZone"] = inst.AvailabilityZone;
|
|
2970
|
+
for (const key of [
|
|
2971
|
+
"CharacterSetName",
|
|
2972
|
+
"NcharCharacterSetName",
|
|
2973
|
+
"Timezone"
|
|
2974
|
+
]) if (inst[key] !== void 0) result[key] = inst[key];
|
|
2532
2975
|
if (inst.EngineLifecycleSupport !== void 0 && inst.DBClusterIdentifier === void 0) result["EngineLifecycleSupport"] = inst.EngineLifecycleSupport;
|
|
2533
2976
|
const liveSource = inst.ReadReplicaSourceDBInstanceIdentifier;
|
|
2534
2977
|
if (liveSource !== void 0 && liveSource !== "") {
|
|
@@ -2706,7 +3149,11 @@ var RDSProvider = class {
|
|
|
2706
3149
|
"AllocatedStorage",
|
|
2707
3150
|
"Iops",
|
|
2708
3151
|
"DBInstanceParameterGroupName",
|
|
2709
|
-
"WithExpressConfiguration"
|
|
3152
|
+
"WithExpressConfiguration",
|
|
3153
|
+
"SourceDBClusterIdentifier",
|
|
3154
|
+
"RestoreToTime",
|
|
3155
|
+
"RestoreType",
|
|
3156
|
+
"UseLatestRestorableTime"
|
|
2710
3157
|
])],
|
|
2711
3158
|
["AWS::RDS::DBInstance", /* @__PURE__ */ new Set([
|
|
2712
3159
|
"DBInstanceIdentifier",
|
|
@@ -2762,7 +3209,13 @@ var RDSProvider = class {
|
|
|
2762
3209
|
"SourceDBInstanceIdentifier",
|
|
2763
3210
|
"SourceRegion",
|
|
2764
3211
|
"ProcessorFeatures",
|
|
2765
|
-
"UseDefaultProcessorFeatures"
|
|
3212
|
+
"UseDefaultProcessorFeatures",
|
|
3213
|
+
"AutomaticBackupReplicationRegion",
|
|
3214
|
+
"AutomaticBackupReplicationKmsKeyId",
|
|
3215
|
+
"AutomaticBackupReplicationRetentionPeriod",
|
|
3216
|
+
"CharacterSetName",
|
|
3217
|
+
"NcharCharacterSetName",
|
|
3218
|
+
"Timezone"
|
|
2766
3219
|
])]
|
|
2767
3220
|
]);
|
|
2768
3221
|
unhandledByDesign = /* @__PURE__ */ new Map([["AWS::RDS::DBCluster", /* @__PURE__ */ new Map([
|
|
@@ -2984,4 +3437,4 @@ var RDSProvider = class {
|
|
|
2984
3437
|
};
|
|
2985
3438
|
|
|
2986
3439
|
export { RDSProvider };
|
|
2987
|
-
//# sourceMappingURL=rds-provider-
|
|
3440
|
+
//# sourceMappingURL=rds-provider-B-LP69hz.js.map
|