@cdkd/cli 0.331.0 → 0.332.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/{asg-provider-CX1vIS2U.js → asg-provider-CwwgTp0h.js} +2 -2
- package/dist/{asg-provider-CX1vIS2U.js.map → asg-provider-CwwgTp0h.js.map} +1 -1
- package/dist/cli.js +2 -2
- package/dist/{db-associated-roles-C6OzmodG.js → db-instance-modify-retry-B1PdmL5X.js} +42 -42
- package/dist/db-instance-modify-retry-B1PdmL5X.js.map +1 -0
- package/dist/{deploy-engine-CV-uC4wn.js → deploy-engine-5GASWIYI.js} +1447 -1216
- package/dist/deploy-engine-5GASWIYI.js.map +1 -0
- package/dist/{iam-role-provider-qO-1ttiR.js → iam-role-provider-Cp9ASoIg.js} +2 -2
- package/dist/{iam-role-provider-qO-1ttiR.js.map → iam-role-provider-Cp9ASoIg.js.map} +1 -1
- package/dist/index.js +2 -2
- package/dist/{neptune-provider-CrnOI25j.js → neptune-provider-C9IhSshh.js} +3 -3
- package/dist/{neptune-provider-CrnOI25j.js.map → neptune-provider-C9IhSshh.js.map} +1 -1
- package/dist/{program-C9XGOVAc.js → program-CaHG8EBB.js} +22355 -22202
- package/dist/program-CaHG8EBB.js.map +1 -0
- package/dist/{provider-classes-zd-4wuDn.js → provider-classes-DdGvWb5T.js} +4358 -3717
- package/dist/provider-classes-DdGvWb5T.js.map +1 -0
- package/dist/rds-provider-BI5PcgWT.js +2439 -0
- package/dist/rds-provider-BI5PcgWT.js.map +1 -0
- package/dist/{version-CP8YzFQk.js → version-DXx2w7jk.js} +2 -2
- package/dist/{version-CP8YzFQk.js.map → version-DXx2w7jk.js.map} +1 -1
- package/package.json +1 -1
- package/dist/db-associated-roles-C6OzmodG.js.map +0 -1
- package/dist/deploy-engine-CV-uC4wn.js.map +0 -1
- package/dist/program-C9XGOVAc.js.map +0 -1
- package/dist/provider-classes-zd-4wuDn.js.map +0 -1
- package/dist/rds-provider-uCvjWdCy.js +0 -2117
- package/dist/rds-provider-uCvjWdCy.js.map +0 -1
|
@@ -1,2117 +0,0 @@
|
|
|
1
|
-
import { $ as safeMsg, E as generatedNameFor, n as describeAwsFailure, s as getLogger } from "./aws-failure-text-DiHodi76.js";
|
|
2
|
-
import { B as normalizeAwsTagsToCfn, F as assertRegionMatch, Fn as ResourceUpdateNotSupportedError, Ft as maskerOrIdentity, Gt as markAuxiliaryFailure, It as withDerivedNameMasks, J as deleteAfterProtectionFlipWithFinalSnapshot, K as ProtectionFlipRegistry, Kt as markCreatedBeforeFailure, M as RESOURCE_NOT_FOUND, Mr as markRedactedCause, Nn as ProvisioningError, Nr as wrapMaskedAwsError, P as markNotGone, Q as isTerminalDbWaitStatus, W as resolveExplicitPhysicalId, Y as deleteWithProtectionCompensation, b as withRemovalDefaults, dt as pasteableAwsCommand, fn as ambientClientDefaults, ft as protectedReplacementAdvice, g as clearOnUpdateRemoval, hr as relayedNameCollision, i as reportCreatedResource, j as withoutServerErrorRetries, jr as markNonRetryable, jt as createMaskedLogSinks, nt as protectionFlipKey, o as retractCreatedResource, rt as rdsFamilyProtectionSite, tt as observeThenDisableProtection, vn as CdkdError } from "./created-resource-sink-DBYrPwKg.js";
|
|
3
|
-
import { c as ambientRegion } from "./aws-client-defaults-BLXFsfMa.js";
|
|
4
|
-
import { $i as stringifyIfAssigned, Dt as enclosingDeadlineRemainingMs, Qi as definedAttributes, Tc as dbInstanceEngineChangeIsInPlace, Wi as markDeleteStarted, Yi as refuseMalformedDesiredTags, Zi as tagPlanWarning, gl as dynamicReferenceTokens, ha as slowCcOperationTimeoutMs, qi as planTagDiff } from "./deploy-engine-CV-uC4wn.js";
|
|
5
|
-
import { a as associatedRolesReadback, c as planAssociatedRoleChanges, i as associatedRolesNamed, l as isModifyNotAvailableRefusal, n as associatedRoleKey, o as canonicalAssociatedRoles, r as associatedRoleList, s as isRoleCallNotAvailableRefusal, t as associatedRoleArns, u as modifyDbInstanceWhenAvailable } from "./db-associated-roles-C6OzmodG.js";
|
|
6
|
-
import { DescribeSecurityGroupsCommand, EC2Client } from "@aws-sdk/client-ec2";
|
|
7
|
-
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";
|
|
9
|
-
|
|
10
|
-
// src/provisioning/providers/rds-provider.ts
|
|
11
|
-
function propertyChangedForUpdate(key, desired, recorded, context) {
|
|
12
|
-
const changedProperties = context?.changedProperties;
|
|
13
|
-
if (changedProperties !== void 0) return changedProperties.has(key);
|
|
14
|
-
return holdsRecordedStandIn(recorded) || !isDeepStrictEqual(desired, recorded);
|
|
15
|
-
}
|
|
16
|
-
function holdsRecordedStandIn(value) {
|
|
17
|
-
if (typeof value === "string") return value === "***" || dynamicReferenceTokens(value).length > 0;
|
|
18
|
-
if (Array.isArray(value)) return value.some(holdsRecordedStandIn);
|
|
19
|
-
if (value !== null && typeof value === "object") return Object.values(value).some(holdsRecordedStandIn);
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
function masterUserPasswordToSend(properties, previousProperties, context) {
|
|
23
|
-
const desired = properties["MasterUserPassword"];
|
|
24
|
-
if (desired === void 0 || desired === null) return void 0;
|
|
25
|
-
return propertyChangedForUpdate("MasterUserPassword", desired, previousProperties["MasterUserPassword"], context) ? desired : void 0;
|
|
26
|
-
}
|
|
27
|
-
function masterCredentialSettingsChanged(properties, previousProperties, context) {
|
|
28
|
-
return propertyChangedForUpdate("MasterUserPassword", properties["MasterUserPassword"], previousProperties["MasterUserPassword"], context) || propertyChangedForUpdate("ManageMasterUserPassword", properties["ManageMasterUserPassword"], previousProperties["ManageMasterUserPassword"], context) || propertyChangedForUpdate("MasterUserSecret", properties["MasterUserSecret"], previousProperties["MasterUserSecret"], context);
|
|
29
|
-
}
|
|
30
|
-
function managedPasswordSettingRides(credentialSettingsChanged, authenticationType) {
|
|
31
|
-
return credentialSettingsChanged || authenticationType !== void 0;
|
|
32
|
-
}
|
|
33
|
-
function passwordAuthenticationCompanion(properties, previousProperties, authenticationType) {
|
|
34
|
-
if (authenticationType !== "password") return void 0;
|
|
35
|
-
if (String(properties["ManageMasterUserPassword"]) === "true") {
|
|
36
|
-
const previous = previousProperties["MasterUserAuthenticationType"];
|
|
37
|
-
return previous != null && previous !== "" && previous !== "password" ? { kind: "managed" } : void 0;
|
|
38
|
-
}
|
|
39
|
-
const password = properties["MasterUserPassword"];
|
|
40
|
-
return typeof password === "string" && password !== "" ? {
|
|
41
|
-
kind: "password",
|
|
42
|
-
password
|
|
43
|
-
} : { kind: "missing" };
|
|
44
|
-
}
|
|
45
|
-
function passwordAuthenticationMissingText(resourceType, logicalId) {
|
|
46
|
-
return `${resourceType} ${logicalId}: MasterUserAuthenticationType changes to password, which RDS accepts only beside a master password or the managed one in the same call, and the template declares neither MasterUserPassword nor ManageMasterUserPassword: true. Nothing was applied. Declare one of them.`;
|
|
47
|
-
}
|
|
48
|
-
function masterUserAuthenticationTypeToSend(properties, previousProperties, context) {
|
|
49
|
-
return instanceValueChanged(properties, previousProperties, "MasterUserAuthenticationType", context) ? properties["MasterUserAuthenticationType"] : void 0;
|
|
50
|
-
}
|
|
51
|
-
function managedPasswordOnRemoval(properties, previousProperties) {
|
|
52
|
-
const previous = previousProperties["ManageMasterUserPassword"];
|
|
53
|
-
return properties["ManageMasterUserPassword"] === void 0 && (previous === true || previous === "true");
|
|
54
|
-
}
|
|
55
|
-
const CLUSTER_REMOVED_PORT = /* @__PURE__ */ new Map([
|
|
56
|
-
["aurora-postgresql", 5432],
|
|
57
|
-
["aurora-mysql", 3306],
|
|
58
|
-
["mysql", 3306],
|
|
59
|
-
["postgres", 3306]
|
|
60
|
-
]);
|
|
61
|
-
function numberOrUndefined(value) {
|
|
62
|
-
return value == null ? void 0 : Number(value);
|
|
63
|
-
}
|
|
64
|
-
const STORAGE_MEMBERS = /* @__PURE__ */ new Set([
|
|
65
|
-
"AllocatedStorage",
|
|
66
|
-
"Iops",
|
|
67
|
-
"StorageType",
|
|
68
|
-
"StorageThroughput"
|
|
69
|
-
]);
|
|
70
|
-
function instanceValueChanged(properties, previousProperties, key, context) {
|
|
71
|
-
const desired = properties[key];
|
|
72
|
-
if (desired == null) return false;
|
|
73
|
-
const previous = previousProperties[key];
|
|
74
|
-
if (previous == null) return true;
|
|
75
|
-
const differs = typeof desired === "object" || typeof previous === "object" ? !isDeepStrictEqual(desired, previous) : String(desired) !== String(previous);
|
|
76
|
-
if (STORAGE_MEMBERS.has(key) && !differs) return false;
|
|
77
|
-
if (context?.changedProperties !== void 0) return context.changedProperties.has(key);
|
|
78
|
-
return differs;
|
|
79
|
-
}
|
|
80
|
-
function sizeOrZero(value) {
|
|
81
|
-
const size = Number(value);
|
|
82
|
-
return value != null && Number.isFinite(size) ? size : 0;
|
|
83
|
-
}
|
|
84
|
-
function isProvisionedIoStorage(properties) {
|
|
85
|
-
const storageType = properties["StorageType"];
|
|
86
|
-
if (typeof storageType === "string" && storageType !== "") return [
|
|
87
|
-
"io1",
|
|
88
|
-
"io2",
|
|
89
|
-
"gp3"
|
|
90
|
-
].includes(storageType.toLowerCase());
|
|
91
|
-
return properties["Iops"] != null;
|
|
92
|
-
}
|
|
93
|
-
async function instanceModifyBackfillMembers(properties, previousProperties, liveAllocatedStorage, logicalId, context) {
|
|
94
|
-
const changed = (key) => instanceValueChanged(properties, previousProperties, key, context);
|
|
95
|
-
const desiredAllocated = numberOrUndefined(properties["AllocatedStorage"]);
|
|
96
|
-
const members = {};
|
|
97
|
-
if (changed("BackupRetentionPeriod")) members.BackupRetentionPeriod = Number(properties["BackupRetentionPeriod"]);
|
|
98
|
-
for (const key of [
|
|
99
|
-
"PreferredBackupWindow",
|
|
100
|
-
"PreferredMaintenanceWindow",
|
|
101
|
-
"StorageType",
|
|
102
|
-
"OptionGroupName",
|
|
103
|
-
"CACertificateIdentifier"
|
|
104
|
-
]) if (changed(key)) members[key] = properties[key];
|
|
105
|
-
for (const key of ["NetworkType", "LicenseModel"]) if (changed(key)) members[key] = properties[key];
|
|
106
|
-
if (changed("DatabaseInsightsMode")) members.DatabaseInsightsMode = properties["DatabaseInsightsMode"];
|
|
107
|
-
for (const key of [
|
|
108
|
-
"MultiAZ",
|
|
109
|
-
"AutoMinorVersionUpgrade",
|
|
110
|
-
"CopyTagsToSnapshot",
|
|
111
|
-
"DedicatedLogVolume"
|
|
112
|
-
]) if (changed(key)) members[key] = properties[key];
|
|
113
|
-
if (changed("StorageThroughput")) members.StorageThroughput = Number(properties["StorageThroughput"]);
|
|
114
|
-
if (changed("PromotionTier")) members.PromotionTier = Number(properties["PromotionTier"]);
|
|
115
|
-
if (changed("CACertificateIdentifier") && properties["CertificateRotationRestart"] != null) members.CertificateRotationRestart = properties["CertificateRotationRestart"];
|
|
116
|
-
if (changed("MaxAllocatedStorage")) members.MaxAllocatedStorage = Number(properties["MaxAllocatedStorage"]);
|
|
117
|
-
else if (properties["MaxAllocatedStorage"] == null && previousProperties["MaxAllocatedStorage"] != null) {
|
|
118
|
-
const live = await liveAllocatedStorage();
|
|
119
|
-
if (live === void 0) throw new Error(safeMsg`DBInstance ${logicalId}: MaxAllocatedStorage was removed from the template, which turns storage autoscaling off by setting it to the allocated storage, but DescribeDBInstances did not report the allocated storage`);
|
|
120
|
-
members.MaxAllocatedStorage = Math.max(live, sizeOrZero(desiredAllocated));
|
|
121
|
-
}
|
|
122
|
-
const rollback = context?.replayingState === true;
|
|
123
|
-
if (changed("EngineVersion") && !rollback) members.EngineVersion = String(properties["EngineVersion"]);
|
|
124
|
-
if (changed("DBParameterGroupName") && !(rollback && changed("EngineVersion"))) members.DBParameterGroupName = properties["DBParameterGroupName"];
|
|
125
|
-
if (changed("AllowMajorVersionUpgrade") || members.EngineVersion !== void 0 && properties["AllowMajorVersionUpgrade"] != null) members.AllowMajorVersionUpgrade = properties["AllowMajorVersionUpgrade"];
|
|
126
|
-
if (changed("AllocatedStorage") && !rollback) members.AllocatedStorage = desiredAllocated;
|
|
127
|
-
if (isProvisionedIoStorage(properties)) {
|
|
128
|
-
if (changed("AllocatedStorage") || changed("Iops") || changed("StorageThroughput") || changed("StorageType")) {
|
|
129
|
-
if (members.AllocatedStorage === void 0) {
|
|
130
|
-
const live = await liveAllocatedStorage();
|
|
131
|
-
const larger = Math.max(sizeOrZero(live), sizeOrZero(desiredAllocated), rollback ? sizeOrZero(previousProperties["AllocatedStorage"]) : 0);
|
|
132
|
-
if (larger > 0) members.AllocatedStorage = larger;
|
|
133
|
-
}
|
|
134
|
-
if (properties["Iops"] != null) members.Iops = Number(properties["Iops"]);
|
|
135
|
-
}
|
|
136
|
-
} else if (changed("Iops") && !rollback) members.Iops = Number(properties["Iops"]);
|
|
137
|
-
const enableChanged = changed("EnablePerformanceInsights");
|
|
138
|
-
const keyChanged = changed("PerformanceInsightsKMSKeyId");
|
|
139
|
-
const enableDesired = properties["EnablePerformanceInsights"];
|
|
140
|
-
const keyDesired = properties["PerformanceInsightsKMSKeyId"];
|
|
141
|
-
if (enableChanged || keyChanged) {
|
|
142
|
-
members.EnablePerformanceInsights = enableDesired;
|
|
143
|
-
if (keyChanged || String(enableDesired) === "true") members.PerformanceInsightsKMSKeyId = keyDesired;
|
|
144
|
-
}
|
|
145
|
-
if (changed("PerformanceInsightsRetentionPeriod")) {
|
|
146
|
-
members.PerformanceInsightsRetentionPeriod = Number(properties["PerformanceInsightsRetentionPeriod"]);
|
|
147
|
-
members.EnablePerformanceInsights = enableDesired;
|
|
148
|
-
members.PerformanceInsightsKMSKeyId = keyDesired;
|
|
149
|
-
}
|
|
150
|
-
return Object.fromEntries(Object.entries(members).filter(([, value]) => value !== void 0));
|
|
151
|
-
}
|
|
152
|
-
function instanceParameterGroupPendingReboot(instance) {
|
|
153
|
-
return (instance?.DBParameterGroups ?? []).some((group) => group.ParameterApplyStatus === "pending-reboot");
|
|
154
|
-
}
|
|
155
|
-
function instanceParameterGroupApplying(instance) {
|
|
156
|
-
return (instance?.DBParameterGroups ?? []).some((group) => group.ParameterApplyStatus === "applying");
|
|
157
|
-
}
|
|
158
|
-
function instanceHasPendingChanges(instance, caRotationRestarts) {
|
|
159
|
-
const pending = instance.PendingModifiedValues;
|
|
160
|
-
if (pending === void 0) return false;
|
|
161
|
-
return pending.DBInstanceClass !== void 0 || pending.AllocatedStorage !== void 0 || pending.AutomationMode !== void 0 || pending.BackupRetentionPeriod !== void 0 || pending.DBInstanceIdentifier !== void 0 || pending.DBSubnetGroupName !== void 0 || pending.Engine !== void 0 || pending.EngineVersion !== void 0 || pending.IAMDatabaseAuthenticationEnabled !== void 0 || pending.Iops !== void 0 || pending.LicenseModel !== void 0 || pending.MasterUserPassword !== void 0 || pending.MultiAZ !== void 0 || pending.PendingCloudwatchLogsExports !== void 0 || pending.Port !== void 0 || (pending.ProcessorFeatures ?? []).length > 0 || pending.ResumeFullAutomationModeTime !== void 0 || pending.StorageThroughput !== void 0 || pending.StorageType !== void 0 || caRotationRestarts && pending.CACertificateIdentifier !== void 0;
|
|
162
|
-
}
|
|
163
|
-
function instanceParameterGroupSettled(instance, sentGroup, caRotationRestarts) {
|
|
164
|
-
if (instance.DBInstanceStatus !== "available") return false;
|
|
165
|
-
if (instanceHasPendingChanges(instance, caRotationRestarts)) return false;
|
|
166
|
-
const groups = instance.DBParameterGroups ?? [];
|
|
167
|
-
if (groups.some((group) => group.ParameterApplyStatus === "applying")) return false;
|
|
168
|
-
if (sentGroup === void 0 || groups.length === 0) return true;
|
|
169
|
-
return groups.some((group) => group.DBParameterGroupName?.toLowerCase() === sentGroup.toLowerCase());
|
|
170
|
-
}
|
|
171
|
-
function instanceRebootApplied(instance) {
|
|
172
|
-
return instance.DBInstanceStatus === "available" && (instance.DBParameterGroups ?? []).every((group) => group.ParameterApplyStatus === "in-sync") && (instance.OptionGroupMemberships ?? []).every((group) => group.Status === "in-sync");
|
|
173
|
-
}
|
|
174
|
-
function logExportsList(value) {
|
|
175
|
-
if (value == null) return void 0;
|
|
176
|
-
if (!Array.isArray(value) || !value.every((type) => typeof type === "string")) return "malformed";
|
|
177
|
-
return [...new Set(value)];
|
|
178
|
-
}
|
|
179
|
-
function desiredLogExports(properties, resourceType, logicalId, physicalId) {
|
|
180
|
-
const desired = logExportsList(properties["EnableCloudwatchLogsExports"]);
|
|
181
|
-
if (desired !== "malformed") return desired;
|
|
182
|
-
throw markNonRetryable(new ProvisioningError(`${resourceType} ${logicalId}: EnableCloudwatchLogsExports must be a list of log type names`, resourceType, logicalId, physicalId));
|
|
183
|
-
}
|
|
184
|
-
function logExportsDelta(desired, previousValue) {
|
|
185
|
-
const previous = logExportsList(previousValue);
|
|
186
|
-
const had = previous === void 0 || previous === "malformed" ? [] : previous;
|
|
187
|
-
const want = desired ?? [];
|
|
188
|
-
const enable = want.filter((type) => !had.includes(type));
|
|
189
|
-
const disable = had.filter((type) => !want.includes(type));
|
|
190
|
-
if (enable.length === 0 && disable.length === 0) return void 0;
|
|
191
|
-
return {
|
|
192
|
-
...enable.length > 0 && { EnableLogTypes: enable },
|
|
193
|
-
...disable.length > 0 && { DisableLogTypes: disable }
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
function liveLogExports(enabled, pending) {
|
|
197
|
-
const disabled = pending?.LogTypesToDisable ?? [];
|
|
198
|
-
const out = (enabled ?? []).filter((type) => !disabled.includes(type));
|
|
199
|
-
for (const type of pending?.LogTypesToEnable ?? []) if (!out.includes(type)) out.push(type);
|
|
200
|
-
return out;
|
|
201
|
-
}
|
|
202
|
-
function logExportsApplied(config, enabled, pending) {
|
|
203
|
-
if ((pending?.LogTypesToEnable?.length ?? 0) > 0) return false;
|
|
204
|
-
if ((pending?.LogTypesToDisable?.length ?? 0) > 0) return false;
|
|
205
|
-
const live = enabled ?? [];
|
|
206
|
-
return (config.EnableLogTypes ?? []).every((type) => live.includes(type)) && !(config.DisableLogTypes ?? []).some((type) => live.includes(type));
|
|
207
|
-
}
|
|
208
|
-
function instanceAvailabilityZoneKept(properties, previousProperties) {
|
|
209
|
-
const desired = properties["AvailabilityZone"];
|
|
210
|
-
if (desired === previousProperties["AvailabilityZone"]) return true;
|
|
211
|
-
return (desired == null || desired === "") && String(properties["MultiAZ"]) === "true";
|
|
212
|
-
}
|
|
213
|
-
function withPreviousAvailabilityZone(properties, previousProperties) {
|
|
214
|
-
const { AvailabilityZone: _desired, ...rest } = properties;
|
|
215
|
-
const previous = previousProperties["AvailabilityZone"];
|
|
216
|
-
return previous === void 0 ? rest : {
|
|
217
|
-
...rest,
|
|
218
|
-
AvailabilityZone: previous
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
function engineLifecycleSupportOf(bag) {
|
|
222
|
-
const value = bag["EngineLifecycleSupport"];
|
|
223
|
-
return value == null || value === "" ? void 0 : String(value);
|
|
224
|
-
}
|
|
225
|
-
function engineLifecycleSupportAction(properties, previousProperties, context) {
|
|
226
|
-
const desired = engineLifecycleSupportOf(properties);
|
|
227
|
-
if (desired === engineLifecycleSupportOf(previousProperties)) return "unchanged";
|
|
228
|
-
if (context?.replayingState === true) return "unchanged";
|
|
229
|
-
if (context?.desiredFromAwsReadback === true) return desired === void 0 ? "unchanged" : "send";
|
|
230
|
-
return desired === void 0 ? "refuse" : "check-live";
|
|
231
|
-
}
|
|
232
|
-
function engineLifecycleSupportRefusalText(resourceType, logicalId, physicalId, kind, liveRead) {
|
|
233
|
-
const cli = kind === "DB cluster" ? "aws rds modify-db-cluster" : "aws rds modify-db-instance";
|
|
234
|
-
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.`;
|
|
235
|
-
}
|
|
236
|
-
const PROTECTION_FLIP_RETRY_WAIT_MS = 6e5;
|
|
237
|
-
function isClusterBusyRefusal(error) {
|
|
238
|
-
if (isModifyNotAvailableRefusal(error)) return true;
|
|
239
|
-
return error instanceof Error && error.name === "InvalidDBClusterStateFault" && /could not be modified\. Please try again/i.test(error.message);
|
|
240
|
-
}
|
|
241
|
-
function serverlessV2ScalingToSend(config) {
|
|
242
|
-
const seconds = numberOrUndefined(config.SecondsUntilAutoPause);
|
|
243
|
-
return {
|
|
244
|
-
MinCapacity: config.MinCapacity,
|
|
245
|
-
MaxCapacity: config.MaxCapacity,
|
|
246
|
-
...seconds !== void 0 && { SecondsUntilAutoPause: seconds }
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
const CLUSTER_BACKFILL_STRING_MEMBERS = [
|
|
250
|
-
"DBClusterParameterGroupName",
|
|
251
|
-
"PreferredBackupWindow",
|
|
252
|
-
"PreferredMaintenanceWindow",
|
|
253
|
-
"StorageType"
|
|
254
|
-
];
|
|
255
|
-
function clusterCreateBackfillMembers(properties) {
|
|
256
|
-
const members = {};
|
|
257
|
-
for (const key of CLUSTER_BACKFILL_STRING_MEMBERS) if (properties[key] != null) members[key] = properties[key];
|
|
258
|
-
if (properties["CopyTagsToSnapshot"] != null) members.CopyTagsToSnapshot = properties["CopyTagsToSnapshot"];
|
|
259
|
-
return members;
|
|
260
|
-
}
|
|
261
|
-
function clusterModifyBackfillMembers(properties, previousProperties, context) {
|
|
262
|
-
const changed = (key) => instanceValueChanged(properties, previousProperties, key, context);
|
|
263
|
-
const members = {};
|
|
264
|
-
for (const key of CLUSTER_BACKFILL_STRING_MEMBERS) if (changed(key)) members[key] = properties[key];
|
|
265
|
-
if (changed("CopyTagsToSnapshot")) members.CopyTagsToSnapshot = properties["CopyTagsToSnapshot"];
|
|
266
|
-
return members;
|
|
267
|
-
}
|
|
268
|
-
const CLUSTER_PERFORMANCE_INSIGHTS_MEMBERS = [
|
|
269
|
-
["PerformanceInsightsEnabled", "EnablePerformanceInsights"],
|
|
270
|
-
["PerformanceInsightsKmsKeyId", "PerformanceInsightsKMSKeyId"],
|
|
271
|
-
["PerformanceInsightsRetentionPeriod", "PerformanceInsightsRetentionPeriod"]
|
|
272
|
-
];
|
|
273
|
-
function clusterPerformanceInsightsMembers(properties) {
|
|
274
|
-
const members = {};
|
|
275
|
-
if (properties["PerformanceInsightsEnabled"] != null) members.EnablePerformanceInsights = properties["PerformanceInsightsEnabled"];
|
|
276
|
-
if (properties["PerformanceInsightsKmsKeyId"] != null) members.PerformanceInsightsKMSKeyId = properties["PerformanceInsightsKmsKeyId"];
|
|
277
|
-
const retention = retentionPeriodValue(properties["PerformanceInsightsRetentionPeriod"]);
|
|
278
|
-
if (typeof retention === "number") members.PerformanceInsightsRetentionPeriod = retention;
|
|
279
|
-
return members;
|
|
280
|
-
}
|
|
281
|
-
function clusterCreateScalarMembers(properties) {
|
|
282
|
-
return {
|
|
283
|
-
...properties["AutoMinorVersionUpgrade"] != null && { AutoMinorVersionUpgrade: properties["AutoMinorVersionUpgrade"] },
|
|
284
|
-
...properties["NetworkType"] != null && { NetworkType: properties["NetworkType"] },
|
|
285
|
-
...clusterPerformanceInsightsMembers(properties),
|
|
286
|
-
...properties["DatabaseInsightsMode"] != null && { DatabaseInsightsMode: properties["DatabaseInsightsMode"] },
|
|
287
|
-
...engineLifecycleSupportOf(properties) !== void 0 && { EngineLifecycleSupport: engineLifecycleSupportOf(properties) },
|
|
288
|
-
...properties["MasterUserAuthenticationType"] != null && { MasterUserAuthenticationType: properties["MasterUserAuthenticationType"] },
|
|
289
|
-
...typeof backtrackWindowValue(properties["BacktrackWindow"]) === "number" && { BacktrackWindow: backtrackWindowValue(properties["BacktrackWindow"]) },
|
|
290
|
-
...typeof localWriteForwardingFlag(properties["EnableLocalWriteForwarding"]) === "boolean" && { EnableLocalWriteForwarding: localWriteForwardingFlag(properties["EnableLocalWriteForwarding"]) }
|
|
291
|
-
};
|
|
292
|
-
}
|
|
293
|
-
function clusterModifyScalarMembers(properties, previousProperties, context) {
|
|
294
|
-
const changed = (key) => instanceValueChanged(properties, previousProperties, key, context);
|
|
295
|
-
const members = {};
|
|
296
|
-
if (changed("AutoMinorVersionUpgrade")) members.AutoMinorVersionUpgrade = properties["AutoMinorVersionUpgrade"];
|
|
297
|
-
if (changed("NetworkType")) members.NetworkType = properties["NetworkType"];
|
|
298
|
-
const insightsModeChanged = changed("DatabaseInsightsMode");
|
|
299
|
-
if (insightsModeChanged || CLUSTER_PERFORMANCE_INSIGHTS_MEMBERS.some(([key]) => changed(key))) Object.assign(members, clusterPerformanceInsightsMembers(properties));
|
|
300
|
-
if (insightsModeChanged) members.DatabaseInsightsMode = properties["DatabaseInsightsMode"];
|
|
301
|
-
const backtrackWindow = backtrackWindowValue(properties["BacktrackWindow"]);
|
|
302
|
-
if (typeof backtrackWindow === "number" && changed("BacktrackWindow")) members.BacktrackWindow = backtrackWindow;
|
|
303
|
-
const localWriteForwarding = localWriteForwardingToSend(properties, previousProperties, context);
|
|
304
|
-
if (typeof localWriteForwarding === "boolean") members.EnableLocalWriteForwarding = localWriteForwarding;
|
|
305
|
-
return members;
|
|
306
|
-
}
|
|
307
|
-
function backtrackWindowValue(value) {
|
|
308
|
-
return retentionPeriodValue(value);
|
|
309
|
-
}
|
|
310
|
-
function localWriteForwardingFlag(value) {
|
|
311
|
-
return httpEndpointFlag(value);
|
|
312
|
-
}
|
|
313
|
-
function localWriteForwardingToSend(properties, previousProperties, context) {
|
|
314
|
-
const desired = localWriteForwardingFlag(properties["EnableLocalWriteForwarding"]);
|
|
315
|
-
const previousFlag = localWriteForwardingFlag(previousProperties["EnableLocalWriteForwarding"]);
|
|
316
|
-
const previous = typeof previousFlag === "boolean" ? previousFlag : void 0;
|
|
317
|
-
if (desired === void 0) return previous === true ? false : void 0;
|
|
318
|
-
if (desired === "malformed") return void 0;
|
|
319
|
-
if (previous === void 0 && desired === false) return void 0;
|
|
320
|
-
if (!instanceValueChanged(properties, previousProperties, "EnableLocalWriteForwarding", context)) return;
|
|
321
|
-
return desired && context?.desiredFromAwsReadback === true && context.declaredTrueProperties?.has("EnableLocalWriteForwarding") !== true ? "withheld" : desired;
|
|
322
|
-
}
|
|
323
|
-
function localWriteForwardingApplied(cluster, enabled) {
|
|
324
|
-
const status = cluster.LocalWriteForwardingStatus;
|
|
325
|
-
if (status === void 0) return true;
|
|
326
|
-
if (status === "enabling" || status === "disabling") return false;
|
|
327
|
-
return (status === "requested" || status === "enabled") === enabled;
|
|
328
|
-
}
|
|
329
|
-
function httpEndpointFlag(value) {
|
|
330
|
-
if (value == null) return void 0;
|
|
331
|
-
if (value === true || value === "true") return true;
|
|
332
|
-
if (value === false || value === "false") return false;
|
|
333
|
-
return "malformed";
|
|
334
|
-
}
|
|
335
|
-
const CLUSTER_BOOLEAN_SCALARS = [
|
|
336
|
-
"AutoMinorVersionUpgrade",
|
|
337
|
-
"PerformanceInsightsEnabled",
|
|
338
|
-
"EnableHttpEndpoint",
|
|
339
|
-
"EnableLocalWriteForwarding"
|
|
340
|
-
];
|
|
341
|
-
function retentionPeriodValue(value) {
|
|
342
|
-
if (value == null) return void 0;
|
|
343
|
-
const parsed = typeof value === "number" ? value : typeof value === "string" && /^\d+$/.test(value.trim()) ? Number(value) : NaN;
|
|
344
|
-
return Number.isInteger(parsed) && parsed >= 0 ? parsed : "malformed";
|
|
345
|
-
}
|
|
346
|
-
function clusterHttpEndpointAction(properties, previousProperties, resourceType, logicalId, physicalId, context) {
|
|
347
|
-
const desired = httpEndpointFlag(properties["EnableHttpEndpoint"]);
|
|
348
|
-
if (desired === "malformed") {
|
|
349
|
-
if (context?.replayingState === true || context?.desiredFromAwsReadback === true) return "skip";
|
|
350
|
-
throw markNonRetryable(new ProvisioningError(`${resourceType} ${logicalId}: EnableHttpEndpoint must be true or false`, resourceType, logicalId, physicalId));
|
|
351
|
-
}
|
|
352
|
-
const engine = properties["Engine"];
|
|
353
|
-
if (typeof engine !== "string") return void 0;
|
|
354
|
-
if (!["aurora-mysql", "aurora-postgresql"].includes(engine.toLowerCase())) return void 0;
|
|
355
|
-
const recorded = httpEndpointFlag(previousProperties["EnableHttpEndpoint"]);
|
|
356
|
-
if (desired === (recorded === "malformed" ? void 0 : recorded)) return void 0;
|
|
357
|
-
if (desired !== true) return "disable";
|
|
358
|
-
return context?.desiredFromAwsReadback === true && context.declaredTrueProperties?.has("EnableHttpEndpoint") !== true ? "withheld" : "enable";
|
|
359
|
-
}
|
|
360
|
-
function withPreviousValues(properties, previousProperties, skipped) {
|
|
361
|
-
const out = { ...properties };
|
|
362
|
-
for (const [key, usable] of skipped) {
|
|
363
|
-
delete out[key];
|
|
364
|
-
const previous = previousProperties[key];
|
|
365
|
-
if (previous != null && usable(previous)) out[key] = previous;
|
|
366
|
-
}
|
|
367
|
-
return out;
|
|
368
|
-
}
|
|
369
|
-
const usableHttpEndpoint = (value) => typeof httpEndpointFlag(value) === "boolean";
|
|
370
|
-
const usableRetentionPeriod = (value) => typeof retentionPeriodValue(value) === "number";
|
|
371
|
-
const usableBacktrackWindow = (value) => typeof backtrackWindowValue(value) === "number";
|
|
372
|
-
const usableLocalWriteForwarding = (value) => typeof localWriteForwardingFlag(value) === "boolean";
|
|
373
|
-
const usableAvailabilityZones = (value) => value == null || Array.isArray(value) && value.every((zone) => typeof zone === "string" && zone.trim() !== "");
|
|
374
|
-
function clusterEngineVersionChanged(properties, previousProperties, context) {
|
|
375
|
-
if (context?.replayingState === true) return false;
|
|
376
|
-
return instanceValueChanged(properties, previousProperties, "EngineVersion", context);
|
|
377
|
-
}
|
|
378
|
-
const SECURITY_GROUP_CHANGE_MEMBER_STATUSES = /* @__PURE__ */ new Set(["modifying"]);
|
|
379
|
-
const PORT_CHANGE_MEMBER_STATUSES = /* @__PURE__ */ new Set(["modifying", "rebooting"]);
|
|
380
|
-
function clusterPortToSend(properties, previousProperties) {
|
|
381
|
-
if (properties["Port"] != null) return Number(properties["Port"]);
|
|
382
|
-
if (previousProperties["Port"] == null) return void 0;
|
|
383
|
-
const engine = properties["Engine"] ?? previousProperties["Engine"];
|
|
384
|
-
const reset = typeof engine === "string" ? CLUSTER_REMOVED_PORT.get(engine.toLowerCase()) : void 0;
|
|
385
|
-
return reset === Number(previousProperties["Port"]) ? void 0 : reset;
|
|
386
|
-
}
|
|
387
|
-
const RDS_DELETE_WAIT_MS = Math.max(18e5, slowCcOperationTimeoutMs("AWS::RDS::DBCluster", "DELETE"), slowCcOperationTimeoutMs("AWS::RDS::DBInstance", "DELETE"));
|
|
388
|
-
function deleteAutomatedBackupsInput(properties) {
|
|
389
|
-
const value = properties?.["DeleteAutomatedBackups"];
|
|
390
|
-
if (value === true || value === "true") return { DeleteAutomatedBackups: true };
|
|
391
|
-
if (value === false || value === "false") return { DeleteAutomatedBackups: false };
|
|
392
|
-
return {};
|
|
393
|
-
}
|
|
394
|
-
function recordedGlobalClusterIdentifier(properties) {
|
|
395
|
-
const value = properties?.["GlobalClusterIdentifier"];
|
|
396
|
-
return typeof value === "string" && value.trim() !== "" ? value : void 0;
|
|
397
|
-
}
|
|
398
|
-
const HTTP_ENDPOINT_BUSY_FAULTS = /* @__PURE__ */ new Set(["InvalidResourceStateFault", "InvalidDBClusterStateFault"]);
|
|
399
|
-
const HTTP_ENDPOINT_MAX_ATTEMPTS = 8;
|
|
400
|
-
const TRANSIENT_DETACH_FAULTS = /* @__PURE__ */ new Set([
|
|
401
|
-
"InvalidDBClusterStateFault",
|
|
402
|
-
"InvalidGlobalClusterStateFault",
|
|
403
|
-
"ThrottlingException",
|
|
404
|
-
"Throttling",
|
|
405
|
-
"RequestLimitExceeded"
|
|
406
|
-
]);
|
|
407
|
-
function isDbIdentifier(id) {
|
|
408
|
-
return id.length <= 63 && /^[A-Za-z](?:-?[A-Za-z0-9])*$/.test(id);
|
|
409
|
-
}
|
|
410
|
-
function awsErrorName(error) {
|
|
411
|
-
return error?.name ?? "";
|
|
412
|
-
}
|
|
413
|
-
var GlobalClusterDetachError = class extends Error {
|
|
414
|
-
constructor(message) {
|
|
415
|
-
super(message);
|
|
416
|
-
this.name = "GlobalClusterDetachError";
|
|
417
|
-
}
|
|
418
|
-
};
|
|
419
|
-
var RDSProvider = class {
|
|
420
|
-
rdsClient;
|
|
421
|
-
createClient;
|
|
422
|
-
ec2Client;
|
|
423
|
-
providerRegion;
|
|
424
|
-
logger = getLogger().child("RDSProvider");
|
|
425
|
-
protectionFlips = new ProtectionFlipRegistry();
|
|
426
|
-
removalDefaults = /* @__PURE__ */ new Map();
|
|
427
|
-
handledProperties = /* @__PURE__ */ new Map([
|
|
428
|
-
["AWS::RDS::DBSubnetGroup", /* @__PURE__ */ new Set([
|
|
429
|
-
"DBSubnetGroupName",
|
|
430
|
-
"DBSubnetGroupDescription",
|
|
431
|
-
"SubnetIds",
|
|
432
|
-
"Tags"
|
|
433
|
-
])],
|
|
434
|
-
["AWS::RDS::DBCluster", /* @__PURE__ */ new Set([
|
|
435
|
-
"DBClusterIdentifier",
|
|
436
|
-
"Engine",
|
|
437
|
-
"EngineVersion",
|
|
438
|
-
"MasterUsername",
|
|
439
|
-
"MasterUserPassword",
|
|
440
|
-
"DatabaseName",
|
|
441
|
-
"Port",
|
|
442
|
-
"VpcSecurityGroupIds",
|
|
443
|
-
"DBSubnetGroupName",
|
|
444
|
-
"StorageEncrypted",
|
|
445
|
-
"KmsKeyId",
|
|
446
|
-
"BackupRetentionPeriod",
|
|
447
|
-
"DeletionProtection",
|
|
448
|
-
"ServerlessV2ScalingConfiguration",
|
|
449
|
-
"Tags",
|
|
450
|
-
"ManageMasterUserPassword",
|
|
451
|
-
"MasterUserSecret",
|
|
452
|
-
"MonitoringRoleArn",
|
|
453
|
-
"MonitoringInterval",
|
|
454
|
-
"EnableIAMDatabaseAuthentication",
|
|
455
|
-
"PubliclyAccessible",
|
|
456
|
-
"DBClusterParameterGroupName",
|
|
457
|
-
"PreferredBackupWindow",
|
|
458
|
-
"PreferredMaintenanceWindow",
|
|
459
|
-
"CopyTagsToSnapshot",
|
|
460
|
-
"StorageType",
|
|
461
|
-
"EnableCloudwatchLogsExports",
|
|
462
|
-
"AutoMinorVersionUpgrade",
|
|
463
|
-
"NetworkType",
|
|
464
|
-
"PerformanceInsightsEnabled",
|
|
465
|
-
"PerformanceInsightsKmsKeyId",
|
|
466
|
-
"PerformanceInsightsRetentionPeriod",
|
|
467
|
-
"EnableHttpEndpoint",
|
|
468
|
-
"DatabaseInsightsMode",
|
|
469
|
-
"EngineLifecycleSupport",
|
|
470
|
-
"MasterUserAuthenticationType",
|
|
471
|
-
"BacktrackWindow",
|
|
472
|
-
"EnableLocalWriteForwarding",
|
|
473
|
-
"ClusterScalabilityType",
|
|
474
|
-
"AssociatedRoles",
|
|
475
|
-
"EngineMode",
|
|
476
|
-
"AvailabilityZones"
|
|
477
|
-
])],
|
|
478
|
-
["AWS::RDS::DBInstance", /* @__PURE__ */ new Set([
|
|
479
|
-
"DBInstanceIdentifier",
|
|
480
|
-
"DBInstanceClass",
|
|
481
|
-
"Engine",
|
|
482
|
-
"DBClusterIdentifier",
|
|
483
|
-
"DBSubnetGroupName",
|
|
484
|
-
"PubliclyAccessible",
|
|
485
|
-
"Tags",
|
|
486
|
-
"AllocatedStorage",
|
|
487
|
-
"DeletionProtection",
|
|
488
|
-
"EngineVersion",
|
|
489
|
-
"MasterUsername",
|
|
490
|
-
"MasterUserPassword",
|
|
491
|
-
"Port",
|
|
492
|
-
"StorageEncrypted",
|
|
493
|
-
"VPCSecurityGroups",
|
|
494
|
-
"KmsKeyId",
|
|
495
|
-
"MasterUserSecret",
|
|
496
|
-
"ManageMasterUserPassword",
|
|
497
|
-
"MonitoringRoleArn",
|
|
498
|
-
"MonitoringInterval",
|
|
499
|
-
"EnableIAMDatabaseAuthentication",
|
|
500
|
-
"BackupRetentionPeriod",
|
|
501
|
-
"PreferredBackupWindow",
|
|
502
|
-
"PreferredMaintenanceWindow",
|
|
503
|
-
"StorageType",
|
|
504
|
-
"MultiAZ",
|
|
505
|
-
"MaxAllocatedStorage",
|
|
506
|
-
"AutoMinorVersionUpgrade",
|
|
507
|
-
"CopyTagsToSnapshot",
|
|
508
|
-
"EnablePerformanceInsights",
|
|
509
|
-
"PerformanceInsightsKMSKeyId",
|
|
510
|
-
"PerformanceInsightsRetentionPeriod",
|
|
511
|
-
"Iops",
|
|
512
|
-
"StorageThroughput",
|
|
513
|
-
"OptionGroupName",
|
|
514
|
-
"CACertificateIdentifier",
|
|
515
|
-
"NetworkType",
|
|
516
|
-
"LicenseModel",
|
|
517
|
-
"PromotionTier",
|
|
518
|
-
"DatabaseInsightsMode",
|
|
519
|
-
"DedicatedLogVolume",
|
|
520
|
-
"AllowMajorVersionUpgrade",
|
|
521
|
-
"CertificateRotationRestart",
|
|
522
|
-
"DBParameterGroupName",
|
|
523
|
-
"EnableCloudwatchLogsExports",
|
|
524
|
-
"DBName",
|
|
525
|
-
"AvailabilityZone",
|
|
526
|
-
"EngineLifecycleSupport",
|
|
527
|
-
"MasterUserAuthenticationType",
|
|
528
|
-
"AssociatedRoles"
|
|
529
|
-
])]
|
|
530
|
-
]);
|
|
531
|
-
unhandledByDesign = /* @__PURE__ */ new Map([["AWS::RDS::DBCluster", /* @__PURE__ */ new Map([["DeleteAutomatedBackups", "delete-time flag, sent on the delete when the record carries it; kept unhandled so a template declaring it keeps its Cloud Control route. Final snapshots are governed by DeletionPolicy: Snapshot, which this flag does not control"], ["ScalingConfiguration", "Aurora Serverless v1 only (EngineMode serverless), retired by AWS: no aurora-mysql or aurora-postgresql engine version supports the serverless engine mode (DescribeDBEngineVersions, us-east-1, 2026-11-06). Aurora Serverless v2 uses ServerlessV2ScalingConfiguration"]])], ["AWS::RDS::DBInstance", /* @__PURE__ */ new Map([
|
|
532
|
-
["DBSecurityGroups", "EC2-Classic-only feature retired by AWS (2022-08-15); new accounts cannot use this — use VPCSecurityGroups instead"],
|
|
533
|
-
["ApplyImmediately", "cdkd always applies modifications immediately (rds:ModifyDBInstance.ApplyImmediately=true is hardcoded); users wanting maintenance-window deferral should run aws rds modify-db-instance directly"],
|
|
534
|
-
["DeleteAutomatedBackups", "delete-time flag, sent on the delete when the record carries it; kept unhandled so a template declaring it keeps its Cloud Control route. Final snapshots are governed by DeletionPolicy: Snapshot, which this flag does not control"]
|
|
535
|
-
])]]);
|
|
536
|
-
constructor(options) {
|
|
537
|
-
this.providerRegion = options?.region ?? ambientRegion();
|
|
538
|
-
}
|
|
539
|
-
getClient() {
|
|
540
|
-
if (!this.rdsClient) {
|
|
541
|
-
this.rdsClient = new RDSClient({
|
|
542
|
-
...ambientClientDefaults(),
|
|
543
|
-
...this.providerRegion ? { region: this.providerRegion } : {}
|
|
544
|
-
});
|
|
545
|
-
this.createClient = withoutServerErrorRetries(new RDSClient({
|
|
546
|
-
...ambientClientDefaults(),
|
|
547
|
-
...this.providerRegion ? { region: this.providerRegion } : {}
|
|
548
|
-
}));
|
|
549
|
-
}
|
|
550
|
-
return this.rdsClient;
|
|
551
|
-
}
|
|
552
|
-
getEc2Client() {
|
|
553
|
-
if (!this.ec2Client) this.ec2Client = new EC2Client({
|
|
554
|
-
...ambientClientDefaults(),
|
|
555
|
-
...this.providerRegion ? { region: this.providerRegion } : {}
|
|
556
|
-
});
|
|
557
|
-
return this.ec2Client;
|
|
558
|
-
}
|
|
559
|
-
getCreateClient() {
|
|
560
|
-
this.getClient();
|
|
561
|
-
return this.createClient;
|
|
562
|
-
}
|
|
563
|
-
async create(logicalId, resourceType, properties, context) {
|
|
564
|
-
const mask = context?.maskSecrets;
|
|
565
|
-
switch (resourceType) {
|
|
566
|
-
case "AWS::RDS::DBSubnetGroup": return this.createDBSubnetGroup(logicalId, resourceType, properties, mask);
|
|
567
|
-
case "AWS::RDS::DBCluster": return this.createDBCluster(logicalId, resourceType, properties, mask, context?.replayingState === true);
|
|
568
|
-
case "AWS::RDS::DBInstance": return this.createDBInstance(logicalId, resourceType, properties, mask, context?.replayingState === true);
|
|
569
|
-
default: throw new ProvisioningError(`Unsupported resource type: ${resourceType}`, resourceType, logicalId);
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
async update(logicalId, physicalId, resourceType, properties, previousProperties, context) {
|
|
573
|
-
properties = withRemovalDefaults(this.removalDefaults, resourceType, properties, previousProperties, context);
|
|
574
|
-
switch (resourceType) {
|
|
575
|
-
case "AWS::RDS::DBSubnetGroup": return this.updateDBSubnetGroup(logicalId, physicalId, resourceType, properties, previousProperties, context?.maskSecrets);
|
|
576
|
-
case "AWS::RDS::DBCluster": return this.updateDBCluster(logicalId, physicalId, resourceType, properties, previousProperties, context);
|
|
577
|
-
case "AWS::RDS::DBInstance": return this.updateDBInstance(logicalId, physicalId, resourceType, properties, previousProperties, context);
|
|
578
|
-
default: throw new ProvisioningError(`Unsupported resource type: ${resourceType}`, resourceType, logicalId, physicalId);
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
async delete(logicalId, physicalId, resourceType, properties, context) {
|
|
582
|
-
switch (resourceType) {
|
|
583
|
-
case "AWS::RDS::DBSubnetGroup": return this.deleteDBSubnetGroup(logicalId, physicalId, resourceType, context);
|
|
584
|
-
case "AWS::RDS::DBCluster": return this.deleteDBCluster(logicalId, physicalId, resourceType, properties, context);
|
|
585
|
-
case "AWS::RDS::DBInstance": return this.deleteDBInstance(logicalId, physicalId, resourceType, properties, context);
|
|
586
|
-
default: throw new ProvisioningError(`Unsupported resource type: ${resourceType}`, resourceType, logicalId, physicalId);
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
async createDBSubnetGroup(logicalId, resourceType, properties, mask) {
|
|
590
|
-
this.logger.debug(`Creating DBSubnetGroup ${logicalId}`);
|
|
591
|
-
const tags = refuseMalformedDesiredTags(properties["Tags"], resourceType, logicalId);
|
|
592
|
-
const dbSubnetGroupName = properties["DBSubnetGroupName"] || generatedNameFor("AWS::RDS::DBSubnetGroup", logicalId);
|
|
593
|
-
try {
|
|
594
|
-
const created = await this.getCreateClient().send(new CreateDBSubnetGroupCommand({
|
|
595
|
-
DBSubnetGroupName: dbSubnetGroupName,
|
|
596
|
-
DBSubnetGroupDescription: properties["DBSubnetGroupDescription"] || `Subnet group for ${logicalId}`,
|
|
597
|
-
SubnetIds: properties["SubnetIds"],
|
|
598
|
-
...tags.length > 0 && { Tags: tags }
|
|
599
|
-
}));
|
|
600
|
-
this.logger.debug(`Successfully created DBSubnetGroup ${logicalId}: ${dbSubnetGroupName}`);
|
|
601
|
-
const dbSubnetGroupArn = created.DBSubnetGroup?.DBSubnetGroupArn;
|
|
602
|
-
return {
|
|
603
|
-
physicalId: dbSubnetGroupName,
|
|
604
|
-
attributes: {
|
|
605
|
-
DBSubnetGroupName: dbSubnetGroupName,
|
|
606
|
-
...dbSubnetGroupArn !== void 0 && { DBSubnetGroupArn: dbSubnetGroupArn }
|
|
607
|
-
}
|
|
608
|
-
};
|
|
609
|
-
} catch (error) {
|
|
610
|
-
const cause = error instanceof Error ? error : void 0;
|
|
611
|
-
throw this.wrapCaughtError(mask, error, (text) => new ProvisioningError(`Failed to create DBSubnetGroup ${logicalId}: ${text}`, resourceType, logicalId, dbSubnetGroupName, cause));
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
async updateDBSubnetGroup(logicalId, physicalId, resourceType, properties, previousProperties, mask) {
|
|
615
|
-
this.logger.debug(`Updating DBSubnetGroup ${logicalId}: ${physicalId}`);
|
|
616
|
-
refuseMalformedDesiredTags(properties["Tags"], resourceType, logicalId, physicalId);
|
|
617
|
-
try {
|
|
618
|
-
const subnetIds = properties["SubnetIds"];
|
|
619
|
-
const sendSubnetIds = subnetIds !== void 0 && subnetIds.length > 0;
|
|
620
|
-
const modifyInput = {
|
|
621
|
-
DBSubnetGroupName: physicalId,
|
|
622
|
-
DBSubnetGroupDescription: properties["DBSubnetGroupDescription"],
|
|
623
|
-
...sendSubnetIds && { SubnetIds: subnetIds }
|
|
624
|
-
};
|
|
625
|
-
await this.getClient().send(new ModifyDBSubnetGroupCommand(modifyInput));
|
|
626
|
-
const arn = (await this.getClient().send(new DescribeDBSubnetGroupsCommand({ DBSubnetGroupName: physicalId }))).DBSubnetGroups?.[0]?.DBSubnetGroupArn;
|
|
627
|
-
if (arn) await this.applyTagDiff(arn, resourceType, logicalId, previousProperties["Tags"], properties["Tags"]);
|
|
628
|
-
this.logger.debug(`Successfully updated DBSubnetGroup ${logicalId}`);
|
|
629
|
-
return {
|
|
630
|
-
physicalId,
|
|
631
|
-
wasReplaced: false,
|
|
632
|
-
attributes: {
|
|
633
|
-
DBSubnetGroupName: physicalId,
|
|
634
|
-
...arn !== void 0 && { DBSubnetGroupArn: arn }
|
|
635
|
-
}
|
|
636
|
-
};
|
|
637
|
-
} catch (error) {
|
|
638
|
-
const cause = error instanceof Error ? error : void 0;
|
|
639
|
-
throw this.wrapCaughtError(mask, error, (text) => new ProvisioningError(`Failed to update DBSubnetGroup ${logicalId}: ${text}`, resourceType, logicalId, physicalId, cause));
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
async deleteDBSubnetGroup(logicalId, physicalId, resourceType, context) {
|
|
643
|
-
this.logger.debug(`Deleting DBSubnetGroup ${logicalId}: ${physicalId}`);
|
|
644
|
-
try {
|
|
645
|
-
await this.getClient().send(new DeleteDBSubnetGroupCommand({ DBSubnetGroupName: physicalId }));
|
|
646
|
-
this.logger.debug(`Successfully deleted DBSubnetGroup ${logicalId}`);
|
|
647
|
-
} catch (error) {
|
|
648
|
-
if (this.isNotFoundError(error, "DBSubnetGroupNotFoundFault")) {
|
|
649
|
-
const clientRegion = await this.getClient().config.region();
|
|
650
|
-
assertRegionMatch(clientRegion, context?.expectedRegion, resourceType, logicalId, physicalId);
|
|
651
|
-
this.logger.debug(`DBSubnetGroup ${physicalId} does not exist, skipping deletion`);
|
|
652
|
-
return;
|
|
653
|
-
}
|
|
654
|
-
const cause = error instanceof Error ? error : void 0;
|
|
655
|
-
throw this.wrapDeleteError(context?.maskSecrets, error, (text) => new ProvisioningError(`Failed to delete DBSubnetGroup ${logicalId}: ${text}`, resourceType, logicalId, physicalId, cause));
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
async createDBCluster(logicalId, resourceType, properties, mask, replaying = false) {
|
|
659
|
-
this.logger.debug(`Creating DBCluster ${logicalId}`);
|
|
660
|
-
const tags = refuseMalformedDesiredTags(properties["Tags"], resourceType, logicalId);
|
|
661
|
-
let httpEndpoint = httpEndpointFlag(properties["EnableHttpEndpoint"]);
|
|
662
|
-
if (httpEndpoint === "malformed") {
|
|
663
|
-
if (!replaying) throw markNonRetryable(new ProvisioningError(`${resourceType} ${logicalId}: EnableHttpEndpoint must be true or false`, resourceType, logicalId));
|
|
664
|
-
this.logger.warn(safeMsg`DBCluster ${logicalId}: the replayed EnableHttpEndpoint is not true or false; the cluster is created with the Data API off`);
|
|
665
|
-
httpEndpoint = void 0;
|
|
666
|
-
}
|
|
667
|
-
const retentionSkipped = retentionPeriodValue(properties["PerformanceInsightsRetentionPeriod"]) === "malformed";
|
|
668
|
-
if (retentionSkipped) {
|
|
669
|
-
if (!replaying) throw markNonRetryable(new ProvisioningError(`${resourceType} ${logicalId}: PerformanceInsightsRetentionPeriod must be a whole number of days`, resourceType, logicalId));
|
|
670
|
-
this.logger.warn(safeMsg`DBCluster ${logicalId}: the replayed PerformanceInsightsRetentionPeriod is not a whole number of days; the cluster is created with AWS's default retention`);
|
|
671
|
-
}
|
|
672
|
-
const backtrackSkipped = backtrackWindowValue(properties["BacktrackWindow"]) === "malformed";
|
|
673
|
-
const forwardingSkipped = localWriteForwardingFlag(properties["EnableLocalWriteForwarding"]) === "malformed";
|
|
674
|
-
const rawAvailabilityZones = properties["AvailabilityZones"];
|
|
675
|
-
const availabilityZonesSkipped = !usableAvailabilityZones(rawAvailabilityZones);
|
|
676
|
-
const availabilityZones = rawAvailabilityZones != null && !availabilityZonesSkipped ? rawAvailabilityZones : void 0;
|
|
677
|
-
for (const [skipped, key, expected, created] of [
|
|
678
|
-
[
|
|
679
|
-
backtrackSkipped,
|
|
680
|
-
"BacktrackWindow",
|
|
681
|
-
"a whole number of seconds",
|
|
682
|
-
"backtracking off"
|
|
683
|
-
],
|
|
684
|
-
[
|
|
685
|
-
forwardingSkipped,
|
|
686
|
-
"EnableLocalWriteForwarding",
|
|
687
|
-
"true or false",
|
|
688
|
-
"write forwarding off"
|
|
689
|
-
],
|
|
690
|
-
[
|
|
691
|
-
availabilityZonesSkipped,
|
|
692
|
-
"AvailabilityZones",
|
|
693
|
-
"a list of Availability Zone names",
|
|
694
|
-
"the Availability Zones RDS picks"
|
|
695
|
-
]
|
|
696
|
-
]) {
|
|
697
|
-
if (!skipped) continue;
|
|
698
|
-
if (!replaying) throw markNonRetryable(new ProvisioningError(`${resourceType} ${logicalId}: ${key} must be ${expected}`, resourceType, logicalId));
|
|
699
|
-
this.logger.warn(safeMsg`DBCluster ${logicalId}: the replayed ${key} is not ${expected}; the cluster is created with ${created}`);
|
|
700
|
-
}
|
|
701
|
-
const roles = this.desiredAssociatedRoles(properties, resourceType, logicalId, void 0, replaying);
|
|
702
|
-
const skippedKeys = [
|
|
703
|
-
...roles === "skipped" ? ["AssociatedRoles"] : [],
|
|
704
|
-
...properties["EnableHttpEndpoint"] != null && httpEndpoint === void 0 ? ["EnableHttpEndpoint"] : [],
|
|
705
|
-
...retentionSkipped ? ["PerformanceInsightsRetentionPeriod"] : [],
|
|
706
|
-
...backtrackSkipped ? ["BacktrackWindow"] : [],
|
|
707
|
-
...forwardingSkipped ? ["EnableLocalWriteForwarding"] : [],
|
|
708
|
-
...availabilityZonesSkipped ? ["AvailabilityZones"] : []
|
|
709
|
-
];
|
|
710
|
-
const effectiveProperties = skippedKeys.length > 0 ? Object.fromEntries(Object.entries(properties).filter(([key]) => !skippedKeys.includes(key))) : void 0;
|
|
711
|
-
const logExports = desiredLogExports(properties, resourceType, logicalId);
|
|
712
|
-
const dbClusterIdentifier = properties["DBClusterIdentifier"] || generatedNameFor("AWS::RDS::DBCluster", logicalId);
|
|
713
|
-
let clusterLeftBehind = false;
|
|
714
|
-
let createdResourceId;
|
|
715
|
-
try {
|
|
716
|
-
const serverlessV2Config = properties["ServerlessV2ScalingConfiguration"];
|
|
717
|
-
const masterUserSecret = properties["MasterUserSecret"];
|
|
718
|
-
const response = await this.getCreateClient().send(new CreateDBClusterCommand({
|
|
719
|
-
DBClusterIdentifier: dbClusterIdentifier,
|
|
720
|
-
Engine: properties["Engine"],
|
|
721
|
-
EngineVersion: properties["EngineVersion"],
|
|
722
|
-
MasterUsername: properties["MasterUsername"],
|
|
723
|
-
MasterUserPassword: properties["MasterUserPassword"],
|
|
724
|
-
DatabaseName: properties["DatabaseName"],
|
|
725
|
-
Port: properties["Port"] != null ? Number(properties["Port"]) : void 0,
|
|
726
|
-
VpcSecurityGroupIds: properties["VpcSecurityGroupIds"],
|
|
727
|
-
DBSubnetGroupName: properties["DBSubnetGroupName"],
|
|
728
|
-
StorageEncrypted: properties["StorageEncrypted"],
|
|
729
|
-
KmsKeyId: properties["KmsKeyId"],
|
|
730
|
-
BackupRetentionPeriod: properties["BackupRetentionPeriod"] != null ? Number(properties["BackupRetentionPeriod"]) : void 0,
|
|
731
|
-
DeletionProtection: properties["DeletionProtection"],
|
|
732
|
-
...properties["ManageMasterUserPassword"] !== void 0 && { ManageMasterUserPassword: properties["ManageMasterUserPassword"] },
|
|
733
|
-
...masterUserSecret?.KmsKeyId !== void 0 && { MasterUserSecretKmsKeyId: masterUserSecret.KmsKeyId },
|
|
734
|
-
...properties["MonitoringRoleArn"] !== void 0 && { MonitoringRoleArn: properties["MonitoringRoleArn"] },
|
|
735
|
-
...properties["MonitoringInterval"] !== void 0 && { MonitoringInterval: Number(properties["MonitoringInterval"]) },
|
|
736
|
-
...properties["EnableIAMDatabaseAuthentication"] !== void 0 && { EnableIAMDatabaseAuthentication: properties["EnableIAMDatabaseAuthentication"] },
|
|
737
|
-
...properties["PubliclyAccessible"] !== void 0 && { PubliclyAccessible: properties["PubliclyAccessible"] },
|
|
738
|
-
...serverlessV2Config && { ServerlessV2ScalingConfiguration: serverlessV2ScalingToSend(serverlessV2Config) },
|
|
739
|
-
...clusterCreateBackfillMembers(properties),
|
|
740
|
-
...logExports !== void 0 && logExports.length > 0 && { EnableCloudwatchLogsExports: logExports },
|
|
741
|
-
...clusterCreateScalarMembers(properties),
|
|
742
|
-
...httpEndpoint !== void 0 && { EnableHttpEndpoint: httpEndpoint },
|
|
743
|
-
...properties["ClusterScalabilityType"] != null && { ClusterScalabilityType: properties["ClusterScalabilityType"] },
|
|
744
|
-
...properties["EngineMode"] != null && { EngineMode: properties["EngineMode"] },
|
|
745
|
-
...availabilityZones !== void 0 && availabilityZones.length > 0 && { AvailabilityZones: availabilityZones },
|
|
746
|
-
...tags.length > 0 && { Tags: tags }
|
|
747
|
-
}));
|
|
748
|
-
clusterLeftBehind = true;
|
|
749
|
-
createdResourceId = response.DBCluster?.DbClusterResourceId;
|
|
750
|
-
reportCreatedResource(logicalId, resourceType, dbClusterIdentifier, createdResourceId);
|
|
751
|
-
if (!response.DBCluster) throw new Error("CreateDBCluster did not return DBCluster");
|
|
752
|
-
this.logger.debug(`Successfully created DBCluster ${logicalId}: ${dbClusterIdentifier}`);
|
|
753
|
-
const wantsDeletionProtection = properties["DeletionProtection"] === true;
|
|
754
|
-
try {
|
|
755
|
-
if (process.env["CDKD_NO_WAIT"] !== "true") {
|
|
756
|
-
await this.waitForClusterAvailable(logicalId, dbClusterIdentifier);
|
|
757
|
-
if (localWriteForwardingFlag(properties["EnableLocalWriteForwarding"]) === true) await this.waitForClusterState(logicalId, dbClusterIdentifier, (cluster) => localWriteForwardingApplied(cluster, true), "local write forwarding setting");
|
|
758
|
-
}
|
|
759
|
-
if (roles !== "skipped") try {
|
|
760
|
-
await this.applyAssociatedRoles("cluster", logicalId, dbClusterIdentifier, roles, [], mask, void 0);
|
|
761
|
-
} catch (roleError) {
|
|
762
|
-
markAuxiliaryFailure(roleError, logicalId);
|
|
763
|
-
throw roleError;
|
|
764
|
-
}
|
|
765
|
-
const described = await this.describeDBCluster(dbClusterIdentifier);
|
|
766
|
-
return {
|
|
767
|
-
physicalId: dbClusterIdentifier,
|
|
768
|
-
attributes: definedAttributes({
|
|
769
|
-
"Endpoint.Address": described?.Endpoint,
|
|
770
|
-
"Endpoint.Port": stringifyIfAssigned(described?.Port),
|
|
771
|
-
"ReadEndpoint.Address": described?.ReaderEndpoint,
|
|
772
|
-
Arn: described?.DBClusterArn,
|
|
773
|
-
DBClusterResourceId: described?.DbClusterResourceId
|
|
774
|
-
}),
|
|
775
|
-
...effectiveProperties !== void 0 && { effectiveProperties }
|
|
776
|
-
};
|
|
777
|
-
} catch (innerError) {
|
|
778
|
-
try {
|
|
779
|
-
if (wantsDeletionProtection) try {
|
|
780
|
-
await this.getClient().send(new ModifyDBClusterCommand({
|
|
781
|
-
DBClusterIdentifier: dbClusterIdentifier,
|
|
782
|
-
DeletionProtection: false,
|
|
783
|
-
ApplyImmediately: true
|
|
784
|
-
}));
|
|
785
|
-
} catch (disableError) {
|
|
786
|
-
this.logger.debug(maskerOrIdentity(mask)(`Could not disable DeletionProtection on partially-created DBCluster ${dbClusterIdentifier}: ${describeAwsFailure(disableError).detail} (proceeding with DeleteDBCluster anyway)`));
|
|
787
|
-
}
|
|
788
|
-
await this.getClient().send(new DeleteDBClusterCommand({
|
|
789
|
-
DBClusterIdentifier: dbClusterIdentifier,
|
|
790
|
-
SkipFinalSnapshot: true
|
|
791
|
-
}));
|
|
792
|
-
clusterLeftBehind = false;
|
|
793
|
-
retractCreatedResource(logicalId, resourceType, dbClusterIdentifier);
|
|
794
|
-
this.logger.debug(`Delete requested for partially-created DBCluster ${logicalId} (${dbClusterIdentifier}) after wiring failure (not waiting for deleted state)`);
|
|
795
|
-
} catch (cleanupError) {
|
|
796
|
-
const retiring = await this.partialClusterRetiring(dbClusterIdentifier);
|
|
797
|
-
if (retiring !== void 0) {
|
|
798
|
-
this.logger.debug(maskerOrIdentity(mask)(`Cleanup delete of partially-created DBCluster ${logicalId} refused: ${maskerOrIdentity(mask)(describeAwsFailure(cleanupError).detail)}`));
|
|
799
|
-
this.logger.warn(maskerOrIdentity(mask)(`Partially-created DBCluster ${logicalId} (${dbClusterIdentifier}) is ${retiring === "gone" ? "read as already deleted" : "already in status 'deleting'"}; cdkd did not delete it again. Outside a rollback's re-create, the failed deploy's rollback journal still records it, so \`cdkd rollback --revert-failed\` confirms it is gone`));
|
|
800
|
-
throw innerError;
|
|
801
|
-
}
|
|
802
|
-
const aws = pasteableAwsCommand();
|
|
803
|
-
const unprotect = wantsDeletionProtection ? aws`aws rds modify-db-cluster --db-cluster-identifier ${dbClusterIdentifier} --no-deletion-protection --apply-immediately; ` : aws``;
|
|
804
|
-
const m = maskerOrIdentity(mask);
|
|
805
|
-
const cleanupFailure = describeAwsFailure(cleanupError);
|
|
806
|
-
const cleanupHead = `Failed to delete partially-created DBCluster ${logicalId} (${dbClusterIdentifier}): `;
|
|
807
|
-
if (cleanupFailure.redacted) this.logger.debug(m(`${cleanupHead}${m(cleanupFailure.detail)}`));
|
|
808
|
-
this.logger.warn(`${cleanupHead}${cleanupFailure.redacted ? `${m(cleanupFailure.summary)} ` : `${m(cleanupFailure.detail)}. `}THE CLUSTER IS STILL RUNNING AND BILLING. Outside a rollback's re-create, the failed deploy's rollback journal records it for \`cdkd rollback --revert-failed\`${wantsDeletionProtection ? ", which cannot delete it while its DeletionProtection is on" : ""}; otherwise delete it yourself: ${aws`${unprotect}aws rds delete-db-cluster --db-cluster-identifier ${dbClusterIdentifier} --skip-final-snapshot`.render()}`);
|
|
809
|
-
}
|
|
810
|
-
throw innerError;
|
|
811
|
-
}
|
|
812
|
-
} catch (error) {
|
|
813
|
-
const thrown = error instanceof ProvisioningError ? error : this.wrapCaughtError(mask, error, (text) => new ProvisioningError(`Failed to create DBCluster ${logicalId}: ${text}`, resourceType, logicalId, dbClusterIdentifier, error instanceof Error ? error : void 0));
|
|
814
|
-
if (clusterLeftBehind) markCreatedBeforeFailure(thrown, logicalId, resourceType, dbClusterIdentifier, createdResourceId);
|
|
815
|
-
throw thrown;
|
|
816
|
-
}
|
|
817
|
-
}
|
|
818
|
-
async updateDBCluster(logicalId, physicalId, resourceType, properties, previousProperties, context) {
|
|
819
|
-
this.logger.debug(`Updating DBCluster ${logicalId}: ${physicalId}`);
|
|
820
|
-
refuseMalformedDesiredTags(properties["Tags"], resourceType, logicalId, physicalId);
|
|
821
|
-
const roles = this.desiredAssociatedRoles(properties, resourceType, logicalId, physicalId, false);
|
|
822
|
-
const logExportConfig = logExportsDelta(desiredLogExports(properties, resourceType, logicalId, physicalId), previousProperties["EnableCloudwatchLogsExports"]);
|
|
823
|
-
const httpEndpointAction = clusterHttpEndpointAction(properties, previousProperties, resourceType, logicalId, physicalId, context);
|
|
824
|
-
if (httpEndpointAction === "skip") this.logger.warn(safeMsg`DBCluster ${logicalId}: the replayed EnableHttpEndpoint is not true or false; the Data API setting is left as it is`);
|
|
825
|
-
if (httpEndpointAction === "withheld") this.logger.warn(safeMsg`DBCluster ${logicalId}: drift --revert does not turn the Data API (EnableHttpEndpoint) back on, because the template does not declare EnableHttpEndpoint: true; declare it and deploy, or turn the Data API on with aws rds enable-http-endpoint`);
|
|
826
|
-
const skippedKeys = httpEndpointAction === "skip" || httpEndpointAction === "withheld" ? [["EnableHttpEndpoint", usableHttpEndpoint]] : [];
|
|
827
|
-
if (retentionPeriodValue(properties["PerformanceInsightsRetentionPeriod"]) === "malformed") {
|
|
828
|
-
if (context?.replayingState !== true && context?.desiredFromAwsReadback !== true) throw markNonRetryable(new ProvisioningError(`${resourceType} ${logicalId}: PerformanceInsightsRetentionPeriod must be a whole number of days`, resourceType, logicalId, physicalId));
|
|
829
|
-
this.logger.warn(safeMsg`DBCluster ${logicalId}: the replayed PerformanceInsightsRetentionPeriod is not a whole number of days; the retention period is left as it is`);
|
|
830
|
-
skippedKeys.push(["PerformanceInsightsRetentionPeriod", usableRetentionPeriod]);
|
|
831
|
-
}
|
|
832
|
-
if (!usableAvailabilityZones(properties["AvailabilityZones"])) {
|
|
833
|
-
if (context?.replayingState !== true && context?.desiredFromAwsReadback !== true) throw markNonRetryable(new ProvisioningError(`${resourceType} ${logicalId}: AvailabilityZones must be a list of Availability Zone names`, resourceType, logicalId, physicalId));
|
|
834
|
-
this.logger.warn(safeMsg`DBCluster ${logicalId}: the replayed AvailabilityZones is not a list of Availability Zone names; the record keeps the previous list`);
|
|
835
|
-
skippedKeys.push(["AvailabilityZones", usableAvailabilityZones]);
|
|
836
|
-
}
|
|
837
|
-
for (const [malformed, key, expected, usable] of [[
|
|
838
|
-
backtrackWindowValue(properties["BacktrackWindow"]) === "malformed",
|
|
839
|
-
"BacktrackWindow",
|
|
840
|
-
"a whole number of seconds",
|
|
841
|
-
usableBacktrackWindow
|
|
842
|
-
], [
|
|
843
|
-
localWriteForwardingFlag(properties["EnableLocalWriteForwarding"]) === "malformed",
|
|
844
|
-
"EnableLocalWriteForwarding",
|
|
845
|
-
"true or false",
|
|
846
|
-
usableLocalWriteForwarding
|
|
847
|
-
]]) {
|
|
848
|
-
if (!malformed) continue;
|
|
849
|
-
if (context?.replayingState !== true && context?.desiredFromAwsReadback !== true) throw markNonRetryable(new ProvisioningError(`${resourceType} ${logicalId}: ${key} must be ${expected}`, resourceType, logicalId, physicalId));
|
|
850
|
-
this.logger.warn(safeMsg`DBCluster ${logicalId}: the replayed ${key} is not ${expected}; the setting is left as it is`);
|
|
851
|
-
skippedKeys.push([key, usable]);
|
|
852
|
-
}
|
|
853
|
-
if (localWriteForwardingToSend(properties, previousProperties, context) === "withheld") {
|
|
854
|
-
this.logger.warn(safeMsg`DBCluster ${logicalId}: drift --revert does not turn local write forwarding (EnableLocalWriteForwarding) back on, because the template does not declare EnableLocalWriteForwarding: true; declare it and deploy, or turn it on with aws rds modify-db-cluster --enable-local-write-forwarding`);
|
|
855
|
-
skippedKeys.push(["EnableLocalWriteForwarding", usableLocalWriteForwarding]);
|
|
856
|
-
}
|
|
857
|
-
try {
|
|
858
|
-
const engineLifecycleSupport = await this.engineLifecycleSupportToSend("DB cluster", logicalId, physicalId, resourceType, properties, previousProperties, context);
|
|
859
|
-
let authenticationType = masterUserAuthenticationTypeToSend(properties, previousProperties, context);
|
|
860
|
-
let passwordCompanion = passwordAuthenticationCompanion(properties, previousProperties, authenticationType);
|
|
861
|
-
if (passwordCompanion?.kind === "missing" && context?.replayingState === true) {
|
|
862
|
-
this.logger.warn(safeMsg`${logicalId}: the rollback leaves MasterUserAuthenticationType as it is, because the restored properties declare neither MasterUserPassword nor ManageMasterUserPassword: true, which RDS needs beside a switch to password`);
|
|
863
|
-
authenticationType = void 0;
|
|
864
|
-
passwordCompanion = void 0;
|
|
865
|
-
}
|
|
866
|
-
if (passwordCompanion?.kind === "missing") throw markNonRetryable(new ProvisioningError(passwordAuthenticationMissingText(resourceType, logicalId), resourceType, logicalId, physicalId));
|
|
867
|
-
const vpcSgIds = await this.securityGroupsToSend("DBCluster", logicalId, physicalId, resourceType, properties, previousProperties, context);
|
|
868
|
-
const serverlessV2Config = properties["ServerlessV2ScalingConfiguration"];
|
|
869
|
-
const hasServerlessV2 = serverlessV2Config !== void 0 && (serverlessV2Config.MinCapacity !== void 0 || serverlessV2Config.MaxCapacity !== void 0 || serverlessV2Config.SecondsUntilAutoPause !== void 0);
|
|
870
|
-
const masterUserSecret = properties["MasterUserSecret"];
|
|
871
|
-
const sendCredentialSettings = masterCredentialSettingsChanged(properties, previousProperties, context);
|
|
872
|
-
const sendManagedPasswordSetting = managedPasswordSettingRides(sendCredentialSettings, authenticationType);
|
|
873
|
-
const manageMasterUserPasswordOff = managedPasswordOnRemoval(properties, previousProperties);
|
|
874
|
-
const portToSend = clusterPortToSend(properties, previousProperties);
|
|
875
|
-
const engineVersionChanged = clusterEngineVersionChanged(properties, previousProperties, context);
|
|
876
|
-
const scalarMembers = clusterModifyScalarMembers(properties, previousProperties, context);
|
|
877
|
-
await this.getClient().send(new ModifyDBClusterCommand({
|
|
878
|
-
DBClusterIdentifier: physicalId,
|
|
879
|
-
...engineVersionChanged && {
|
|
880
|
-
EngineVersion: properties["EngineVersion"],
|
|
881
|
-
AllowMajorVersionUpgrade: true
|
|
882
|
-
},
|
|
883
|
-
DeletionProtection: properties["DeletionProtection"],
|
|
884
|
-
BackupRetentionPeriod: clearOnUpdateRemoval(properties["BackupRetentionPeriod"] != null ? Number(properties["BackupRetentionPeriod"]) : void 0, previousProperties["BackupRetentionPeriod"] != null ? Number(previousProperties["BackupRetentionPeriod"]) : void 0, 1),
|
|
885
|
-
...vpcSgIds !== void 0 && { VpcSecurityGroupIds: vpcSgIds },
|
|
886
|
-
MasterUserPassword: masterUserPasswordToSend(properties, previousProperties, context) ?? (passwordCompanion?.kind === "password" ? passwordCompanion.password : void 0),
|
|
887
|
-
Port: portToSend,
|
|
888
|
-
...sendManagedPasswordSetting && properties["ManageMasterUserPassword"] !== void 0 && { ManageMasterUserPassword: properties["ManageMasterUserPassword"] },
|
|
889
|
-
...manageMasterUserPasswordOff && { ManageMasterUserPassword: false },
|
|
890
|
-
...(sendCredentialSettings || passwordCompanion?.kind === "managed") && masterUserSecret?.KmsKeyId !== void 0 && { MasterUserSecretKmsKeyId: masterUserSecret.KmsKeyId },
|
|
891
|
-
...properties["MonitoringRoleArn"] !== void 0 && { MonitoringRoleArn: properties["MonitoringRoleArn"] },
|
|
892
|
-
...properties["MonitoringInterval"] != null && { MonitoringInterval: Number(properties["MonitoringInterval"]) },
|
|
893
|
-
EnableIAMDatabaseAuthentication: properties["EnableIAMDatabaseAuthentication"],
|
|
894
|
-
...hasServerlessV2 && { ServerlessV2ScalingConfiguration: serverlessV2ScalingToSend(serverlessV2Config) },
|
|
895
|
-
...clusterModifyBackfillMembers(properties, previousProperties, context),
|
|
896
|
-
...scalarMembers,
|
|
897
|
-
...engineLifecycleSupport !== void 0 && { EngineLifecycleSupport: engineLifecycleSupport },
|
|
898
|
-
...authenticationType !== void 0 && { MasterUserAuthenticationType: authenticationType },
|
|
899
|
-
...logExportConfig !== void 0 && { CloudwatchLogsExportConfiguration: logExportConfig },
|
|
900
|
-
ApplyImmediately: true
|
|
901
|
-
}));
|
|
902
|
-
this.logger.debug(`Successfully updated DBCluster ${logicalId}`);
|
|
903
|
-
const noWait = process.env["CDKD_NO_WAIT"] === "true";
|
|
904
|
-
const portChanged = portToSend !== void 0 && portToSend !== numberOrUndefined(previousProperties["Port"]);
|
|
905
|
-
if (!noWait && portChanged) await this.waitForClusterPortApplied(physicalId, logicalId, portToSend);
|
|
906
|
-
if (!noWait && logExportConfig !== void 0) await this.waitForClusterState(logicalId, physicalId, (cluster) => logExportsApplied(logExportConfig, cluster.EnabledCloudwatchLogsExports, cluster.PendingModifiedValues?.PendingCloudwatchLogsExports), "CloudWatch Logs exports");
|
|
907
|
-
const forwardingSent = scalarMembers.EnableLocalWriteForwarding;
|
|
908
|
-
if (!noWait && forwardingSent !== void 0) await this.waitForClusterState(logicalId, physicalId, (cluster) => localWriteForwardingApplied(cluster, forwardingSent), "local write forwarding setting");
|
|
909
|
-
const backtrackSent = scalarMembers.BacktrackWindow;
|
|
910
|
-
if (!noWait && backtrackSent !== void 0) await this.waitForClusterState(logicalId, physicalId, (cluster) => cluster.BacktrackWindow === void 0 || cluster.BacktrackWindow === backtrackSent, "backtrack window");
|
|
911
|
-
const described = await this.describeDBCluster(physicalId);
|
|
912
|
-
if (httpEndpointAction === "enable" || httpEndpointAction === "disable") {
|
|
913
|
-
const arn = described?.DBClusterArn;
|
|
914
|
-
if (!arn) throw new Error(`DescribeDBClusters did not report the cluster ARN, which ${httpEndpointAction === "enable" ? "EnableHttpEndpoint" : "DisableHttpEndpoint"} needs`);
|
|
915
|
-
const enable = httpEndpointAction === "enable";
|
|
916
|
-
await this.sendHttpEndpointChange(logicalId, physicalId, arn, enable);
|
|
917
|
-
if (!noWait) await this.waitForClusterState(logicalId, physicalId, (cluster) => (cluster.HttpEndpointEnabled ?? false) === enable, "HTTP endpoint (Data API) setting");
|
|
918
|
-
}
|
|
919
|
-
if (!noWait && portChanged) {
|
|
920
|
-
for (const member of described?.DBClusterMembers ?? []) if (member.DBInstanceIdentifier) await this.waitForMemberAfterClusterChange(member.DBInstanceIdentifier, logicalId, PORT_CHANGE_MEMBER_STATUSES, "port");
|
|
921
|
-
}
|
|
922
|
-
if (!noWait && securityGroupListChanged(vpcSgIds, previousProperties["VpcSecurityGroupIds"])) {
|
|
923
|
-
await this.waitForSecurityGroupsApplied(physicalId, logicalId, vpcSgIds ?? []);
|
|
924
|
-
for (const member of described?.DBClusterMembers ?? []) if (member.DBInstanceIdentifier) await this.waitForMemberAfterClusterChange(member.DBInstanceIdentifier, logicalId, SECURITY_GROUP_CHANGE_MEMBER_STATUSES, "VPC security groups");
|
|
925
|
-
}
|
|
926
|
-
await this.applyAssociatedRoles("cluster", logicalId, physicalId, roles, associatedRoleList(previousProperties["AssociatedRoles"]) ?? [], context?.maskSecrets, context);
|
|
927
|
-
if (described?.DBClusterArn) await this.applyTagDiff(described.DBClusterArn, resourceType, logicalId, previousProperties["Tags"], properties["Tags"]);
|
|
928
|
-
return {
|
|
929
|
-
physicalId,
|
|
930
|
-
wasReplaced: false,
|
|
931
|
-
attributes: definedAttributes({
|
|
932
|
-
"Endpoint.Address": described?.Endpoint,
|
|
933
|
-
"Endpoint.Port": stringifyIfAssigned(noWait && portChanged && described !== void 0 ? portToSend : described?.Port),
|
|
934
|
-
"ReadEndpoint.Address": described?.ReaderEndpoint,
|
|
935
|
-
Arn: described?.DBClusterArn,
|
|
936
|
-
DBClusterResourceId: described?.DbClusterResourceId
|
|
937
|
-
}),
|
|
938
|
-
...skippedKeys.length > 0 && { effectiveProperties: withPreviousValues(properties, previousProperties, skippedKeys) }
|
|
939
|
-
};
|
|
940
|
-
} catch (error) {
|
|
941
|
-
if (error instanceof ProvisioningError) throw error;
|
|
942
|
-
const cause = error instanceof Error ? error : void 0;
|
|
943
|
-
throw this.wrapCaughtError(context?.maskSecrets, error, (text) => new ProvisioningError(`Failed to update DBCluster ${logicalId}: ${text}`, resourceType, logicalId, physicalId, cause));
|
|
944
|
-
}
|
|
945
|
-
}
|
|
946
|
-
async deleteDBCluster(logicalId, physicalId, resourceType, properties, context) {
|
|
947
|
-
await deleteWithProtectionCompensation({
|
|
948
|
-
registry: this.protectionFlips,
|
|
949
|
-
key: protectionFlipKey(resourceType, physicalId, context?.expectedRegion),
|
|
950
|
-
run: (flip) => this.deleteDBClusterOnce(logicalId, physicalId, resourceType, properties, context, flip),
|
|
951
|
-
compensation: {
|
|
952
|
-
logicalId,
|
|
953
|
-
physicalId,
|
|
954
|
-
logger: this.logger,
|
|
955
|
-
site: rdsFamilyProtectionSite({
|
|
956
|
-
cliService: "rds",
|
|
957
|
-
serviceLabel: "RDS",
|
|
958
|
-
kind: "cluster",
|
|
959
|
-
physicalId,
|
|
960
|
-
region: context?.expectedRegion,
|
|
961
|
-
notFoundFault: "DBClusterNotFoundFault",
|
|
962
|
-
isNotFound: (error) => this.isNotFoundError(error, "DBClusterNotFoundFault")
|
|
963
|
-
}),
|
|
964
|
-
reEnable: async () => {
|
|
965
|
-
await modifyDbInstanceWhenAvailable({
|
|
966
|
-
send: () => this.getClient().send(new ModifyDBClusterCommand({
|
|
967
|
-
DBClusterIdentifier: physicalId,
|
|
968
|
-
DeletionProtection: true,
|
|
969
|
-
ApplyImmediately: true
|
|
970
|
-
})),
|
|
971
|
-
readStatus: async () => (await this.describeDBCluster(physicalId))?.Status,
|
|
972
|
-
sleep: (ms) => this.sleep(ms),
|
|
973
|
-
logger: this.logger,
|
|
974
|
-
label: "RDS DBCluster",
|
|
975
|
-
subject: "cluster",
|
|
976
|
-
isRefusal: isClusterBusyRefusal,
|
|
977
|
-
logicalId,
|
|
978
|
-
remainingMs: enclosingDeadlineRemainingMs(),
|
|
979
|
-
maxWaitMs: PROTECTION_FLIP_RETRY_WAIT_MS,
|
|
980
|
-
command: "destroy"
|
|
981
|
-
});
|
|
982
|
-
}
|
|
983
|
-
}
|
|
984
|
-
});
|
|
985
|
-
}
|
|
986
|
-
async deleteDBClusterOnce(logicalId, physicalId, resourceType, properties, context, flip) {
|
|
987
|
-
this.logger.debug(`Deleting DBCluster ${logicalId}`);
|
|
988
|
-
let detachedFrom;
|
|
989
|
-
const progress = { stripped: false };
|
|
990
|
-
try {
|
|
991
|
-
if (context?.removeProtection === true) try {
|
|
992
|
-
await observeThenDisableProtection({
|
|
993
|
-
flip,
|
|
994
|
-
logger: this.logger,
|
|
995
|
-
physicalId,
|
|
996
|
-
mask: context?.maskSecrets,
|
|
997
|
-
guardName: "DeletionProtection",
|
|
998
|
-
observe: async () => (await this.describeDBCluster(physicalId))?.DeletionProtection === true,
|
|
999
|
-
disable: async () => {
|
|
1000
|
-
await modifyDbInstanceWhenAvailable({
|
|
1001
|
-
send: () => this.getClient().send(new ModifyDBClusterCommand({
|
|
1002
|
-
DBClusterIdentifier: physicalId,
|
|
1003
|
-
DeletionProtection: false,
|
|
1004
|
-
ApplyImmediately: true
|
|
1005
|
-
})),
|
|
1006
|
-
readStatus: async () => (await this.describeDBCluster(physicalId))?.Status,
|
|
1007
|
-
sleep: (ms) => this.sleep(ms),
|
|
1008
|
-
logger: this.logger,
|
|
1009
|
-
label: "RDS DBCluster",
|
|
1010
|
-
subject: "cluster",
|
|
1011
|
-
isRefusal: isClusterBusyRefusal,
|
|
1012
|
-
logicalId,
|
|
1013
|
-
remainingMs: enclosingDeadlineRemainingMs(),
|
|
1014
|
-
maxWaitMs: PROTECTION_FLIP_RETRY_WAIT_MS,
|
|
1015
|
-
command: "destroy"
|
|
1016
|
-
});
|
|
1017
|
-
}
|
|
1018
|
-
});
|
|
1019
|
-
this.logger.debug(`Disabled DeletionProtection on DBCluster ${logicalId} before delete`);
|
|
1020
|
-
} catch (disableError) {
|
|
1021
|
-
if (!this.isNotFoundError(disableError, "DBClusterNotFoundFault")) this.logger.debug(maskerOrIdentity(context?.maskSecrets)(`Could not disable deletion protection for DBCluster ${logicalId}: ${describeAwsFailure(disableError).detail}`));
|
|
1022
|
-
}
|
|
1023
|
-
const globalClusterId = recordedGlobalClusterIdentifier(properties);
|
|
1024
|
-
if (globalClusterId !== void 0) detachedFrom = await this.detachFromGlobalCluster(logicalId, physicalId, globalClusterId, context?.removeProtection === true, progress, maskerOrIdentity(context?.maskSecrets)) ? globalClusterId : void 0;
|
|
1025
|
-
const finalSnapshotId = context?.finalSnapshotIdentifier;
|
|
1026
|
-
const sendDelete = () => this.getClient().send(new DeleteDBClusterCommand({
|
|
1027
|
-
DBClusterIdentifier: physicalId,
|
|
1028
|
-
...finalSnapshotId ? {
|
|
1029
|
-
SkipFinalSnapshot: false,
|
|
1030
|
-
FinalDBSnapshotIdentifier: finalSnapshotId
|
|
1031
|
-
} : { SkipFinalSnapshot: true },
|
|
1032
|
-
...deleteAutomatedBackupsInput(properties)
|
|
1033
|
-
}));
|
|
1034
|
-
if (finalSnapshotId && flip.flippedOffByThisRun && !flip.deleteAccepted) await this.deleteAfterProtectionFlip(logicalId, physicalId, sendDelete);
|
|
1035
|
-
else await sendDelete();
|
|
1036
|
-
flip.deleteAccepted = true;
|
|
1037
|
-
if (finalSnapshotId) this.logger.info(`Deleting DBCluster ${logicalId} with a final snapshot (DeletionPolicy: Snapshot)`);
|
|
1038
|
-
this.logger.debug(`Successfully initiated deletion of DBCluster ${logicalId}`);
|
|
1039
|
-
await this.waitForClusterDeleted(logicalId, physicalId, RDS_DELETE_WAIT_MS);
|
|
1040
|
-
} catch (error) {
|
|
1041
|
-
if (error instanceof GlobalClusterDetachError) {
|
|
1042
|
-
const detachFailure = markNotGone(markNonRetryable(new ProvisioningError(`Failed to delete DBCluster ${logicalId}: ${error.message}`, resourceType, logicalId, physicalId, error)));
|
|
1043
|
-
throw progress.stripped ? markDeleteStarted(detachFailure) : detachFailure;
|
|
1044
|
-
}
|
|
1045
|
-
if (this.isNotFoundError(error, "DBClusterNotFoundFault")) {
|
|
1046
|
-
const clientRegion = await this.getClient().config.region();
|
|
1047
|
-
assertRegionMatch(clientRegion, context?.expectedRegion, resourceType, logicalId, physicalId);
|
|
1048
|
-
if (context?.failedCreateOrphan === true) this.logger.info(safeMsg` RDS DB cluster ${physicalId} (${logicalId}), which a failed deploy created, is already gone; nothing to delete`);
|
|
1049
|
-
else this.logger.debug(`DBCluster ${logicalId} does not exist, skipping deletion`);
|
|
1050
|
-
return;
|
|
1051
|
-
}
|
|
1052
|
-
const cause = error instanceof Error ? error : void 0;
|
|
1053
|
-
const detachedNote = detachedFrom !== void 0 ? " (it was already detached from its global cluster, and stays a standalone cluster)" : "";
|
|
1054
|
-
const failure = this.wrapDeleteError(context?.maskSecrets, error, (text) => new ProvisioningError(`Failed to delete DBCluster ${logicalId}: ${text}${detachedNote}`, resourceType, logicalId, physicalId, cause));
|
|
1055
|
-
throw progress.stripped ? markDeleteStarted(failure) : failure;
|
|
1056
|
-
}
|
|
1057
|
-
}
|
|
1058
|
-
async createDBInstance(logicalId, resourceType, properties, mask, replaying = false) {
|
|
1059
|
-
this.logger.debug(`Creating DBInstance ${logicalId}`);
|
|
1060
|
-
const tags = refuseMalformedDesiredTags(properties["Tags"], resourceType, logicalId);
|
|
1061
|
-
const roles = this.desiredAssociatedRoles(properties, resourceType, logicalId, void 0, replaying);
|
|
1062
|
-
const logExports = desiredLogExports(properties, resourceType, logicalId);
|
|
1063
|
-
const dbInstanceIdentifier = properties["DBInstanceIdentifier"] || generatedNameFor("AWS::RDS::DBInstance", logicalId);
|
|
1064
|
-
let instanceCreated = false;
|
|
1065
|
-
let createdResourceId;
|
|
1066
|
-
try {
|
|
1067
|
-
const masterUserSecret = properties["MasterUserSecret"];
|
|
1068
|
-
const response = await this.getCreateClient().send(new CreateDBInstanceCommand({
|
|
1069
|
-
DBInstanceIdentifier: dbInstanceIdentifier,
|
|
1070
|
-
DBInstanceClass: properties["DBInstanceClass"],
|
|
1071
|
-
Engine: properties["Engine"],
|
|
1072
|
-
DBClusterIdentifier: properties["DBClusterIdentifier"],
|
|
1073
|
-
DBSubnetGroupName: properties["DBSubnetGroupName"],
|
|
1074
|
-
PubliclyAccessible: properties["PubliclyAccessible"],
|
|
1075
|
-
...properties["AllocatedStorage"] !== void 0 && { AllocatedStorage: Number(properties["AllocatedStorage"]) },
|
|
1076
|
-
...properties["MasterUsername"] !== void 0 && { MasterUsername: properties["MasterUsername"] },
|
|
1077
|
-
...properties["DeletionProtection"] !== void 0 && { DeletionProtection: properties["DeletionProtection"] },
|
|
1078
|
-
...properties["EngineVersion"] !== void 0 && { EngineVersion: properties["EngineVersion"] },
|
|
1079
|
-
...properties["Port"] !== void 0 && { Port: Number(properties["Port"]) },
|
|
1080
|
-
...properties["MasterUserPassword"] !== void 0 && { MasterUserPassword: properties["MasterUserPassword"] },
|
|
1081
|
-
...properties["StorageEncrypted"] !== void 0 && { StorageEncrypted: properties["StorageEncrypted"] },
|
|
1082
|
-
...properties["VPCSecurityGroups"] !== void 0 && { VpcSecurityGroupIds: properties["VPCSecurityGroups"] },
|
|
1083
|
-
...properties["KmsKeyId"] !== void 0 && { KmsKeyId: properties["KmsKeyId"] },
|
|
1084
|
-
...masterUserSecret?.KmsKeyId !== void 0 && { MasterUserSecretKmsKeyId: masterUserSecret.KmsKeyId },
|
|
1085
|
-
...properties["ManageMasterUserPassword"] !== void 0 && { ManageMasterUserPassword: properties["ManageMasterUserPassword"] },
|
|
1086
|
-
...properties["MonitoringRoleArn"] !== void 0 && { MonitoringRoleArn: properties["MonitoringRoleArn"] },
|
|
1087
|
-
...properties["MonitoringInterval"] !== void 0 && { MonitoringInterval: Number(properties["MonitoringInterval"]) },
|
|
1088
|
-
...properties["EnableIAMDatabaseAuthentication"] !== void 0 && { EnableIAMDatabaseAuthentication: properties["EnableIAMDatabaseAuthentication"] },
|
|
1089
|
-
...properties["BackupRetentionPeriod"] != null && { BackupRetentionPeriod: Number(properties["BackupRetentionPeriod"]) },
|
|
1090
|
-
...properties["PreferredBackupWindow"] != null && { PreferredBackupWindow: properties["PreferredBackupWindow"] },
|
|
1091
|
-
...properties["PreferredMaintenanceWindow"] != null && { PreferredMaintenanceWindow: properties["PreferredMaintenanceWindow"] },
|
|
1092
|
-
...properties["StorageType"] != null && { StorageType: properties["StorageType"] },
|
|
1093
|
-
...properties["Iops"] != null && { Iops: Number(properties["Iops"]) },
|
|
1094
|
-
...properties["StorageThroughput"] != null && { StorageThroughput: Number(properties["StorageThroughput"]) },
|
|
1095
|
-
...properties["MaxAllocatedStorage"] != null && { MaxAllocatedStorage: Number(properties["MaxAllocatedStorage"]) },
|
|
1096
|
-
...properties["MultiAZ"] != null && { MultiAZ: properties["MultiAZ"] },
|
|
1097
|
-
...properties["AutoMinorVersionUpgrade"] != null && { AutoMinorVersionUpgrade: properties["AutoMinorVersionUpgrade"] },
|
|
1098
|
-
...properties["CopyTagsToSnapshot"] != null && { CopyTagsToSnapshot: properties["CopyTagsToSnapshot"] },
|
|
1099
|
-
...properties["OptionGroupName"] != null && { OptionGroupName: properties["OptionGroupName"] },
|
|
1100
|
-
...properties["CACertificateIdentifier"] != null && { CACertificateIdentifier: properties["CACertificateIdentifier"] },
|
|
1101
|
-
...String(properties["EnablePerformanceInsights"]) === "true" && {
|
|
1102
|
-
EnablePerformanceInsights: true,
|
|
1103
|
-
...properties["PerformanceInsightsKMSKeyId"] != null && { PerformanceInsightsKMSKeyId: properties["PerformanceInsightsKMSKeyId"] }
|
|
1104
|
-
},
|
|
1105
|
-
...properties["PerformanceInsightsRetentionPeriod"] != null && { PerformanceInsightsRetentionPeriod: Number(properties["PerformanceInsightsRetentionPeriod"]) },
|
|
1106
|
-
...properties["NetworkType"] != null && { NetworkType: properties["NetworkType"] },
|
|
1107
|
-
...properties["LicenseModel"] != null && { LicenseModel: properties["LicenseModel"] },
|
|
1108
|
-
...properties["PromotionTier"] != null && { PromotionTier: Number(properties["PromotionTier"]) },
|
|
1109
|
-
...properties["DatabaseInsightsMode"] != null && { DatabaseInsightsMode: properties["DatabaseInsightsMode"] },
|
|
1110
|
-
...properties["DedicatedLogVolume"] != null && { DedicatedLogVolume: properties["DedicatedLogVolume"] },
|
|
1111
|
-
...engineLifecycleSupportOf(properties) !== void 0 && { EngineLifecycleSupport: engineLifecycleSupportOf(properties) },
|
|
1112
|
-
...properties["MasterUserAuthenticationType"] != null && { MasterUserAuthenticationType: properties["MasterUserAuthenticationType"] },
|
|
1113
|
-
...properties["DBParameterGroupName"] != null && { DBParameterGroupName: properties["DBParameterGroupName"] },
|
|
1114
|
-
...logExports !== void 0 && logExports.length > 0 && { EnableCloudwatchLogsExports: logExports },
|
|
1115
|
-
...properties["DBName"] != null && { DBName: properties["DBName"] },
|
|
1116
|
-
...properties["AvailabilityZone"] != null && { AvailabilityZone: properties["AvailabilityZone"] },
|
|
1117
|
-
...tags.length > 0 && { Tags: tags }
|
|
1118
|
-
}));
|
|
1119
|
-
instanceCreated = true;
|
|
1120
|
-
createdResourceId = response.DBInstance?.DbiResourceId;
|
|
1121
|
-
reportCreatedResource(logicalId, resourceType, dbInstanceIdentifier, createdResourceId);
|
|
1122
|
-
if (!response.DBInstance) throw new Error("CreateDBInstance did not return DBInstance");
|
|
1123
|
-
this.logger.debug(`Successfully created DBInstance ${logicalId}: ${dbInstanceIdentifier}`);
|
|
1124
|
-
if (process.env["CDKD_NO_WAIT"] !== "true") await this.waitForInstanceAvailable(logicalId, dbInstanceIdentifier);
|
|
1125
|
-
if (roles !== "skipped") try {
|
|
1126
|
-
await this.applyAssociatedRoles("instance", logicalId, dbInstanceIdentifier, roles, [], mask, void 0);
|
|
1127
|
-
} catch (roleError) {
|
|
1128
|
-
markAuxiliaryFailure(roleError, logicalId);
|
|
1129
|
-
throw roleError;
|
|
1130
|
-
}
|
|
1131
|
-
const described = await this.describeDBInstance(dbInstanceIdentifier);
|
|
1132
|
-
return {
|
|
1133
|
-
physicalId: dbInstanceIdentifier,
|
|
1134
|
-
attributes: definedAttributes({
|
|
1135
|
-
"Endpoint.Address": described?.Endpoint?.Address,
|
|
1136
|
-
"Endpoint.Port": stringifyIfAssigned(described?.Endpoint?.Port),
|
|
1137
|
-
Arn: described?.DBInstanceArn
|
|
1138
|
-
}),
|
|
1139
|
-
...roles === "skipped" && { effectiveProperties: Object.fromEntries(Object.entries(properties).filter(([key]) => key !== "AssociatedRoles")) }
|
|
1140
|
-
};
|
|
1141
|
-
} catch (error) {
|
|
1142
|
-
const thrown = error instanceof ProvisioningError ? error : this.wrapCaughtError(mask, error, (text) => new ProvisioningError(`Failed to create DBInstance ${logicalId}: ${text}`, resourceType, logicalId, dbInstanceIdentifier, error instanceof Error ? error : void 0));
|
|
1143
|
-
if (instanceCreated) markCreatedBeforeFailure(thrown, logicalId, resourceType, dbInstanceIdentifier, createdResourceId);
|
|
1144
|
-
throw thrown;
|
|
1145
|
-
}
|
|
1146
|
-
}
|
|
1147
|
-
async updateDBInstance(logicalId, physicalId, resourceType, properties, previousProperties, context) {
|
|
1148
|
-
this.logger.debug(`Updating DBInstance ${logicalId}: ${physicalId}`);
|
|
1149
|
-
refuseMalformedDesiredTags(properties["Tags"], resourceType, logicalId, physicalId);
|
|
1150
|
-
const roles = this.desiredAssociatedRoles(properties, resourceType, logicalId, physicalId, false);
|
|
1151
|
-
const logExportConfig = logExportsDelta(desiredLogExports(properties, resourceType, logicalId, physicalId), previousProperties["EnableCloudwatchLogsExports"]);
|
|
1152
|
-
const vpcSgIds = await this.securityGroupsToSend("DBInstance", logicalId, physicalId, resourceType, properties, previousProperties, context);
|
|
1153
|
-
const engineLifecycleSupport = await this.engineLifecycleSupportToSend("DB instance", logicalId, physicalId, resourceType, properties, previousProperties, context);
|
|
1154
|
-
let authenticationType = masterUserAuthenticationTypeToSend(properties, previousProperties, context);
|
|
1155
|
-
let passwordCompanion = passwordAuthenticationCompanion(properties, previousProperties, authenticationType);
|
|
1156
|
-
if (passwordCompanion?.kind === "missing" && context?.replayingState === true) {
|
|
1157
|
-
this.logger.warn(safeMsg`${logicalId}: the rollback leaves MasterUserAuthenticationType as it is, because the restored properties declare neither MasterUserPassword nor ManageMasterUserPassword: true, which RDS needs beside a switch to password`);
|
|
1158
|
-
authenticationType = void 0;
|
|
1159
|
-
passwordCompanion = void 0;
|
|
1160
|
-
}
|
|
1161
|
-
if (passwordCompanion?.kind === "missing") throw markNonRetryable(new ProvisioningError(passwordAuthenticationMissingText(resourceType, logicalId), resourceType, logicalId, physicalId));
|
|
1162
|
-
try {
|
|
1163
|
-
const { mask: zoneMask } = withDerivedNameMasks(this.logger, createMaskedLogSinks(this.logger, context?.maskSecrets), [[previousProperties["DBInstanceIdentifier"], physicalId]]);
|
|
1164
|
-
const desiredZone = properties["AvailabilityZone"];
|
|
1165
|
-
let zoneKept = context?.desiredFromAwsReadback === true || context?.replayingState === true && (desiredZone == null || desiredZone === "") || instanceAvailabilityZoneKept(properties, previousProperties);
|
|
1166
|
-
let liveZoneRead = "read";
|
|
1167
|
-
if (!zoneKept && typeof desiredZone === "string" && desiredZone !== "") zoneKept = await this.describeDBInstance(physicalId).then((instance) => {
|
|
1168
|
-
if (instance === void 0) liveZoneRead = "not-found";
|
|
1169
|
-
return instance?.AvailabilityZone;
|
|
1170
|
-
}, (err) => {
|
|
1171
|
-
liveZoneRead = err?.name === "DBInstanceNotFoundFault" ? "not-found" : "unreadable";
|
|
1172
|
-
this.logger.debug(zoneMask(safeMsg`DBInstance ${logicalId}: could not read the live zone: ${describeAwsFailure(err).summary}`));
|
|
1173
|
-
}) === desiredZone;
|
|
1174
|
-
if (!zoneKept && context?.replayingState !== true) throw new ResourceUpdateNotSupportedError(resourceType, logicalId, zoneMask(`AvailabilityZone cannot change on an existing DB instance — ModifyDBInstance has no such member, and CloudFormation refuses the same update ("Resource is immutable"). Nothing was applied to DB instance ${physicalId}. ` + (liveZoneRead === "not-found" ? "RDS reports no such DB instance: it was deleted outside cdkd, so the state record no longer matches AWS. " : liveZoneRead === "unreadable" ? "cdkd could not read the instance's live zone (an AWS read failed), so it could not tell whether the instance already sits in the declared one; a re-run may succeed. " : "") + "To keep the instance where it is, declare the zone the previous deploy declared (or none, if it declared none), or drop the zone and declare MultiAZ: true. The replace flags below apply to the WHOLE deploy: every other stateful resource in the same run whose in-place update is refused or that needs a replacement is recreated too, so run them with nothing else pending. To move it, " + (String(previousProperties["DeletionProtection"]) === "true" ? protectedReplacementAdvice({
|
|
1175
|
-
evidence: "cdkd's properties for this DB instance carry DeletionProtection: true",
|
|
1176
|
-
replaceFlags: "cdkd deploy --replace --force-stateful-recreation",
|
|
1177
|
-
disable: {
|
|
1178
|
-
before: "aws rds modify-db-instance --db-instance-identifier",
|
|
1179
|
-
identifier: physicalId,
|
|
1180
|
-
after: "--no-deletion-protection --apply-immediately",
|
|
1181
|
-
maskSecrets: zoneMask
|
|
1182
|
-
}
|
|
1183
|
-
}) : "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)")));
|
|
1184
|
-
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.`));
|
|
1185
|
-
const effectiveProperties = zoneKept ? void 0 : withPreviousAvailabilityZone(properties, previousProperties);
|
|
1186
|
-
const masterUserSecret = properties["MasterUserSecret"];
|
|
1187
|
-
const sendCredentialSettings = masterCredentialSettingsChanged(properties, previousProperties, context);
|
|
1188
|
-
const sendManagedPasswordSetting = managedPasswordSettingRides(sendCredentialSettings, authenticationType);
|
|
1189
|
-
const instancePassword = masterUserPasswordToSend(properties, previousProperties, context) ?? (passwordCompanion?.kind === "password" ? passwordCompanion.password : void 0);
|
|
1190
|
-
const manageMasterUserPasswordOff = managedPasswordOnRemoval(properties, previousProperties);
|
|
1191
|
-
let liveInstance;
|
|
1192
|
-
const backfillMembers = await instanceModifyBackfillMembers(properties, previousProperties, () => liveInstance ??= this.describeDBInstance(physicalId).then((instance) => instance?.AllocatedStorage), logicalId, context);
|
|
1193
|
-
await modifyDbInstanceWhenAvailable({
|
|
1194
|
-
send: () => this.getClient().send(new ModifyDBInstanceCommand({
|
|
1195
|
-
DBInstanceIdentifier: physicalId,
|
|
1196
|
-
DBInstanceClass: properties["DBInstanceClass"],
|
|
1197
|
-
PubliclyAccessible: properties["PubliclyAccessible"],
|
|
1198
|
-
ApplyImmediately: true,
|
|
1199
|
-
...backfillMembers,
|
|
1200
|
-
DeletionProtection: properties["DeletionProtection"],
|
|
1201
|
-
...previousProperties["Engine"] !== properties["Engine"] && dbInstanceEngineChangeIsInPlace(previousProperties["Engine"], properties["Engine"]) && { Engine: properties["Engine"] },
|
|
1202
|
-
...properties["Port"] !== void 0 && { DBPortNumber: Number(properties["Port"]) },
|
|
1203
|
-
...instancePassword !== void 0 && { MasterUserPassword: instancePassword },
|
|
1204
|
-
...vpcSgIds !== void 0 && { VpcSecurityGroupIds: vpcSgIds },
|
|
1205
|
-
...(sendCredentialSettings || passwordCompanion?.kind === "managed") && masterUserSecret?.KmsKeyId !== void 0 && { MasterUserSecretKmsKeyId: masterUserSecret.KmsKeyId },
|
|
1206
|
-
...sendManagedPasswordSetting && properties["ManageMasterUserPassword"] !== void 0 && { ManageMasterUserPassword: properties["ManageMasterUserPassword"] },
|
|
1207
|
-
...manageMasterUserPasswordOff && { ManageMasterUserPassword: false },
|
|
1208
|
-
...properties["MonitoringRoleArn"] !== void 0 && { MonitoringRoleArn: properties["MonitoringRoleArn"] },
|
|
1209
|
-
...properties["MonitoringInterval"] != null && { MonitoringInterval: Number(properties["MonitoringInterval"]) },
|
|
1210
|
-
EnableIAMDatabaseAuthentication: properties["EnableIAMDatabaseAuthentication"],
|
|
1211
|
-
...logExportConfig !== void 0 && { CloudwatchLogsExportConfiguration: logExportConfig },
|
|
1212
|
-
...engineLifecycleSupport !== void 0 && { EngineLifecycleSupport: engineLifecycleSupport },
|
|
1213
|
-
...authenticationType !== void 0 && { MasterUserAuthenticationType: authenticationType }
|
|
1214
|
-
})),
|
|
1215
|
-
readStatus: async () => (await this.describeDBInstance(physicalId))?.DBInstanceStatus,
|
|
1216
|
-
sleep: (ms) => this.sleep(ms),
|
|
1217
|
-
logger: this.logger,
|
|
1218
|
-
label: "RDS DBInstance",
|
|
1219
|
-
logicalId,
|
|
1220
|
-
remainingMs: enclosingDeadlineRemainingMs()
|
|
1221
|
-
});
|
|
1222
|
-
this.logger.debug(`Successfully updated DBInstance ${logicalId}`);
|
|
1223
|
-
if (process.env["CDKD_NO_WAIT"] !== "true" && logExportConfig !== void 0) await this.waitForInstanceState(logicalId, physicalId, (instance) => logExportsApplied(logExportConfig, instance.EnabledCloudwatchLogsExports, instance.PendingModifiedValues?.PendingCloudwatchLogsExports), "CloudWatch Logs exports change");
|
|
1224
|
-
let described = await this.describeDBInstance(physicalId);
|
|
1225
|
-
const sentGroup = backfillMembers.DBParameterGroupName;
|
|
1226
|
-
if (sentGroup !== void 0 || instanceParameterGroupPendingReboot(described) || instanceParameterGroupApplying(described)) described = await this.rebootForPendingParameterGroup(logicalId, physicalId, sentGroup, String(properties["CertificateRotationRestart"]) === "true");
|
|
1227
|
-
await this.applyAssociatedRoles("instance", logicalId, physicalId, roles, associatedRoleList(previousProperties["AssociatedRoles"], { featureNameRequired: true }) ?? [], context?.maskSecrets, context);
|
|
1228
|
-
if (described?.DBInstanceArn) await this.applyTagDiff(described.DBInstanceArn, resourceType, logicalId, previousProperties["Tags"], properties["Tags"]);
|
|
1229
|
-
return {
|
|
1230
|
-
physicalId,
|
|
1231
|
-
wasReplaced: false,
|
|
1232
|
-
attributes: definedAttributes({
|
|
1233
|
-
"Endpoint.Address": described?.Endpoint?.Address,
|
|
1234
|
-
"Endpoint.Port": stringifyIfAssigned(described?.Endpoint?.Port),
|
|
1235
|
-
Arn: described?.DBInstanceArn
|
|
1236
|
-
}),
|
|
1237
|
-
...effectiveProperties !== void 0 && { effectiveProperties }
|
|
1238
|
-
};
|
|
1239
|
-
} catch (error) {
|
|
1240
|
-
if (error instanceof ResourceUpdateNotSupportedError) throw error;
|
|
1241
|
-
const cause = error instanceof Error ? error : void 0;
|
|
1242
|
-
throw this.wrapCaughtError(context?.maskSecrets, error, (text) => new ProvisioningError(`Failed to update DBInstance ${logicalId}: ${text}`, resourceType, logicalId, physicalId, cause));
|
|
1243
|
-
}
|
|
1244
|
-
}
|
|
1245
|
-
async deleteDBInstance(logicalId, physicalId, resourceType, properties, context) {
|
|
1246
|
-
await deleteWithProtectionCompensation({
|
|
1247
|
-
registry: this.protectionFlips,
|
|
1248
|
-
key: protectionFlipKey(resourceType, physicalId, context?.expectedRegion),
|
|
1249
|
-
run: (flip) => this.deleteDBInstanceOnce(logicalId, physicalId, resourceType, properties, context, flip),
|
|
1250
|
-
compensation: {
|
|
1251
|
-
logicalId,
|
|
1252
|
-
physicalId,
|
|
1253
|
-
logger: this.logger,
|
|
1254
|
-
site: rdsFamilyProtectionSite({
|
|
1255
|
-
cliService: "rds",
|
|
1256
|
-
serviceLabel: "RDS",
|
|
1257
|
-
kind: "instance",
|
|
1258
|
-
physicalId,
|
|
1259
|
-
region: context?.expectedRegion,
|
|
1260
|
-
notFoundFault: "DBInstanceNotFoundFault",
|
|
1261
|
-
isNotFound: (error) => this.isNotFoundError(error, "DBInstanceNotFoundFault")
|
|
1262
|
-
}),
|
|
1263
|
-
reEnable: async () => {
|
|
1264
|
-
await modifyDbInstanceWhenAvailable({
|
|
1265
|
-
send: () => this.getClient().send(new ModifyDBInstanceCommand({
|
|
1266
|
-
DBInstanceIdentifier: physicalId,
|
|
1267
|
-
DeletionProtection: true,
|
|
1268
|
-
ApplyImmediately: true
|
|
1269
|
-
})),
|
|
1270
|
-
readStatus: async () => (await this.describeDBInstance(physicalId))?.DBInstanceStatus,
|
|
1271
|
-
sleep: (ms) => this.sleep(ms),
|
|
1272
|
-
logger: this.logger,
|
|
1273
|
-
label: "RDS DBInstance",
|
|
1274
|
-
logicalId,
|
|
1275
|
-
remainingMs: enclosingDeadlineRemainingMs(),
|
|
1276
|
-
maxWaitMs: PROTECTION_FLIP_RETRY_WAIT_MS,
|
|
1277
|
-
command: "destroy"
|
|
1278
|
-
});
|
|
1279
|
-
}
|
|
1280
|
-
}
|
|
1281
|
-
});
|
|
1282
|
-
}
|
|
1283
|
-
async deleteDBInstanceOnce(logicalId, physicalId, resourceType, properties, context, flip) {
|
|
1284
|
-
this.logger.debug(`Deleting DBInstance ${logicalId}`);
|
|
1285
|
-
try {
|
|
1286
|
-
if (context?.removeProtection === true) try {
|
|
1287
|
-
await observeThenDisableProtection({
|
|
1288
|
-
flip,
|
|
1289
|
-
logger: this.logger,
|
|
1290
|
-
physicalId,
|
|
1291
|
-
mask: context?.maskSecrets,
|
|
1292
|
-
guardName: "DeletionProtection",
|
|
1293
|
-
observe: async () => (await this.describeDBInstance(physicalId))?.DeletionProtection === true,
|
|
1294
|
-
disable: async () => {
|
|
1295
|
-
await modifyDbInstanceWhenAvailable({
|
|
1296
|
-
send: () => this.getClient().send(new ModifyDBInstanceCommand({
|
|
1297
|
-
DBInstanceIdentifier: physicalId,
|
|
1298
|
-
DeletionProtection: false,
|
|
1299
|
-
ApplyImmediately: true
|
|
1300
|
-
})),
|
|
1301
|
-
readStatus: async () => (await this.describeDBInstance(physicalId))?.DBInstanceStatus,
|
|
1302
|
-
sleep: (ms) => this.sleep(ms),
|
|
1303
|
-
logger: this.logger,
|
|
1304
|
-
label: "RDS DBInstance",
|
|
1305
|
-
logicalId,
|
|
1306
|
-
remainingMs: enclosingDeadlineRemainingMs(),
|
|
1307
|
-
maxWaitMs: PROTECTION_FLIP_RETRY_WAIT_MS,
|
|
1308
|
-
command: "destroy"
|
|
1309
|
-
});
|
|
1310
|
-
}
|
|
1311
|
-
});
|
|
1312
|
-
this.logger.debug(`Disabled DeletionProtection on DBInstance ${logicalId} before delete`);
|
|
1313
|
-
} catch (disableError) {
|
|
1314
|
-
if (!this.isNotFoundError(disableError, "DBInstanceNotFoundFault")) this.logger.debug(maskerOrIdentity(context?.maskSecrets)(`Could not disable deletion protection for DBInstance ${logicalId}: ${describeAwsFailure(disableError).detail}`));
|
|
1315
|
-
}
|
|
1316
|
-
const finalSnapshotId = properties?.["DBClusterIdentifier"] === void 0 ? context?.finalSnapshotIdentifier : void 0;
|
|
1317
|
-
const sendDelete = () => this.getClient().send(new DeleteDBInstanceCommand({
|
|
1318
|
-
DBInstanceIdentifier: physicalId,
|
|
1319
|
-
...finalSnapshotId ? {
|
|
1320
|
-
SkipFinalSnapshot: false,
|
|
1321
|
-
FinalDBSnapshotIdentifier: finalSnapshotId
|
|
1322
|
-
} : { SkipFinalSnapshot: true },
|
|
1323
|
-
...deleteAutomatedBackupsInput(properties)
|
|
1324
|
-
}));
|
|
1325
|
-
if (finalSnapshotId && flip.flippedOffByThisRun && !flip.deleteAccepted) await this.deleteInstanceAfterProtectionFlip(logicalId, physicalId, sendDelete);
|
|
1326
|
-
else await sendDelete();
|
|
1327
|
-
flip.deleteAccepted = true;
|
|
1328
|
-
if (finalSnapshotId) this.logger.info(`Deleting DBInstance ${logicalId} with a final snapshot (DeletionPolicy: Snapshot)`);
|
|
1329
|
-
this.logger.debug(`Successfully initiated deletion of DBInstance ${logicalId}`);
|
|
1330
|
-
await this.waitForInstanceDeleted(logicalId, physicalId, RDS_DELETE_WAIT_MS);
|
|
1331
|
-
} catch (error) {
|
|
1332
|
-
if (this.isNotFoundError(error, "DBInstanceNotFoundFault")) {
|
|
1333
|
-
const clientRegion = await this.getClient().config.region();
|
|
1334
|
-
assertRegionMatch(clientRegion, context?.expectedRegion, resourceType, logicalId, physicalId);
|
|
1335
|
-
if (context?.failedCreateOrphan === true) this.logger.info(safeMsg` RDS DB instance ${physicalId} (${logicalId}), which a failed deploy created, is already gone; nothing to delete`);
|
|
1336
|
-
else this.logger.debug(`DBInstance ${logicalId} does not exist, skipping deletion`);
|
|
1337
|
-
return;
|
|
1338
|
-
}
|
|
1339
|
-
const cause = error instanceof Error ? error : void 0;
|
|
1340
|
-
throw this.wrapDeleteError(context?.maskSecrets, error, (text) => new ProvisioningError(`Failed to delete DBInstance ${logicalId}: ${text}`, resourceType, logicalId, physicalId, cause));
|
|
1341
|
-
}
|
|
1342
|
-
}
|
|
1343
|
-
async applyTagDiff(arn, resourceType, logicalId, oldTagsRaw, newTagsRaw) {
|
|
1344
|
-
const plan = planTagDiff(oldTagsRaw, newTagsRaw);
|
|
1345
|
-
const tagWarning = tagPlanWarning(plan, resourceType, logicalId);
|
|
1346
|
-
if (tagWarning !== void 0) this.logger.warn(tagWarning);
|
|
1347
|
-
const tagsToAdd = [...plan.set].map(([Key, Value]) => ({
|
|
1348
|
-
Key,
|
|
1349
|
-
Value
|
|
1350
|
-
}));
|
|
1351
|
-
const tagsToRemove = plan.remove;
|
|
1352
|
-
if (tagsToRemove.length > 0) {
|
|
1353
|
-
await this.getClient().send(new RemoveTagsFromResourceCommand({
|
|
1354
|
-
ResourceName: arn,
|
|
1355
|
-
TagKeys: tagsToRemove
|
|
1356
|
-
}));
|
|
1357
|
-
this.logger.debug(`Removed ${tagsToRemove.length} tag(s) from RDS resource ${arn}`);
|
|
1358
|
-
}
|
|
1359
|
-
if (tagsToAdd.length > 0) {
|
|
1360
|
-
await this.getClient().send(new AddTagsToResourceCommand({
|
|
1361
|
-
ResourceName: arn,
|
|
1362
|
-
Tags: tagsToAdd
|
|
1363
|
-
}));
|
|
1364
|
-
this.logger.debug(`Added/updated ${tagsToAdd.length} tag(s) on RDS resource ${arn}`);
|
|
1365
|
-
}
|
|
1366
|
-
}
|
|
1367
|
-
async partialClusterRetiring(dbClusterIdentifier) {
|
|
1368
|
-
try {
|
|
1369
|
-
return (await this.describeDBCluster(dbClusterIdentifier))?.Status === "deleting" ? "deleting" : void 0;
|
|
1370
|
-
} catch (error) {
|
|
1371
|
-
return error instanceof Error && error.name === "DBClusterNotFoundFault" ? "gone" : void 0;
|
|
1372
|
-
}
|
|
1373
|
-
}
|
|
1374
|
-
isNotFoundError(error, faultName) {
|
|
1375
|
-
if (!(error instanceof Error)) return false;
|
|
1376
|
-
const name = error.name ?? "";
|
|
1377
|
-
const message = error.message.toLowerCase();
|
|
1378
|
-
return name === faultName || message.includes("not found") || message.includes("does not exist");
|
|
1379
|
-
}
|
|
1380
|
-
wrapCaughtError(mask, error, build) {
|
|
1381
|
-
const m = maskerOrIdentity(mask);
|
|
1382
|
-
const failure = describeAwsFailure(error);
|
|
1383
|
-
if (!failure.redacted) return wrapMaskedAwsError(m, error, build);
|
|
1384
|
-
this.logger.debug(m(build(m(failure.detail)).message));
|
|
1385
|
-
const wrapped = build(`${m(failure.summary)}${relayedNameCollision(failure.detail)}`);
|
|
1386
|
-
return error instanceof Error ? markRedactedCause(wrapped) : wrapped;
|
|
1387
|
-
}
|
|
1388
|
-
wrapDeleteError(mask, error, build) {
|
|
1389
|
-
const thrown = this.wrapCaughtError(mask, error, build);
|
|
1390
|
-
return error instanceof Error && error.name.includes("NotFound") ? markNotGone(thrown) : thrown;
|
|
1391
|
-
}
|
|
1392
|
-
wrapGlobalClusterDetachError(error, mask, build) {
|
|
1393
|
-
const failure = describeAwsFailure(error);
|
|
1394
|
-
if (failure.redacted) this.logger.debug(mask(build(mask(failure.detail))));
|
|
1395
|
-
return new GlobalClusterDetachError(build(mask(failure.summary)));
|
|
1396
|
-
}
|
|
1397
|
-
async detachFromGlobalCluster(logicalId, physicalId, globalClusterId, removeProtection, progress, mask) {
|
|
1398
|
-
let cluster = await this.describeDBCluster(physicalId);
|
|
1399
|
-
for (let i = 0; removeProtection && cluster?.DeletionProtection === true && i < 6; i++) {
|
|
1400
|
-
await this.sleep(5e3);
|
|
1401
|
-
cluster = await this.describeDBCluster(physicalId);
|
|
1402
|
-
}
|
|
1403
|
-
if (cluster === void 0) return false;
|
|
1404
|
-
if (cluster.DeletionProtection === true) throw new GlobalClusterDetachError(safeMsg`${physicalId} has deletion protection on, so cdkd did not detach it from global cluster ${globalClusterId}; turn it off (cdkd destroy --remove-protection does) and re-run`);
|
|
1405
|
-
const clusterArn = cluster.DBClusterArn;
|
|
1406
|
-
if (typeof clusterArn !== "string" || clusterArn === "") throw new GlobalClusterDetachError(safeMsg`could not read the ARN of ${physicalId} to detach it from global cluster ${globalClusterId}`);
|
|
1407
|
-
const startTime = Date.now();
|
|
1408
|
-
let delay = 5e3;
|
|
1409
|
-
const backOff = async () => {
|
|
1410
|
-
if (Date.now() - startTime >= RDS_DELETE_WAIT_MS) throw new GlobalClusterDetachError(safeMsg`timed out waiting for ${physicalId} to leave global cluster ${globalClusterId}`);
|
|
1411
|
-
await this.sleep(delay);
|
|
1412
|
-
delay = Math.min(delay * 2, 1e4);
|
|
1413
|
-
};
|
|
1414
|
-
for (;;) try {
|
|
1415
|
-
await this.getClient().send(new RemoveFromGlobalClusterCommand({
|
|
1416
|
-
GlobalClusterIdentifier: globalClusterId,
|
|
1417
|
-
DbClusterIdentifier: clusterArn
|
|
1418
|
-
}));
|
|
1419
|
-
progress.stripped = true;
|
|
1420
|
-
this.logger.info(safeMsg`Detaching DBCluster ${logicalId} from global cluster ${globalClusterId} before the delete`);
|
|
1421
|
-
break;
|
|
1422
|
-
} catch (error) {
|
|
1423
|
-
const name = awsErrorName(error);
|
|
1424
|
-
if (name === "GlobalClusterNotFoundFault") return false;
|
|
1425
|
-
if (name === "DBClusterNotFoundFault") break;
|
|
1426
|
-
if (!TRANSIENT_DETACH_FAULTS.has(name)) throw this.wrapGlobalClusterDetachError(error, mask, (text) => safeMsg`detaching ${physicalId} from global cluster ${globalClusterId} failed (${text})`);
|
|
1427
|
-
await backOff();
|
|
1428
|
-
}
|
|
1429
|
-
for (;;) {
|
|
1430
|
-
let stillMember;
|
|
1431
|
-
try {
|
|
1432
|
-
stillMember = ((await this.getClient().send(new DescribeGlobalClustersCommand({ GlobalClusterIdentifier: globalClusterId }))).GlobalClusters?.[0]?.GlobalClusterMembers ?? []).some((member) => member.DBClusterArn === clusterArn);
|
|
1433
|
-
} catch (error) {
|
|
1434
|
-
const name = awsErrorName(error);
|
|
1435
|
-
if (name === "GlobalClusterNotFoundFault") stillMember = false;
|
|
1436
|
-
else if (!TRANSIENT_DETACH_FAULTS.has(name)) throw this.wrapGlobalClusterDetachError(error, mask, (text) => safeMsg`could not confirm ${physicalId} left global cluster ${globalClusterId} (${text})`);
|
|
1437
|
-
}
|
|
1438
|
-
if (stillMember === false) {
|
|
1439
|
-
const after = await this.describeDBCluster(physicalId);
|
|
1440
|
-
if (after === void 0) return true;
|
|
1441
|
-
this.logger.debug(safeMsg`DBCluster ${physicalId} status after the detach: ${after.Status}`);
|
|
1442
|
-
if (after.Status === "available") return true;
|
|
1443
|
-
}
|
|
1444
|
-
await backOff();
|
|
1445
|
-
}
|
|
1446
|
-
}
|
|
1447
|
-
async engineLifecycleSupportToSend(kind, logicalId, physicalId, resourceType, properties, previousProperties, context) {
|
|
1448
|
-
const action = engineLifecycleSupportAction(properties, previousProperties, context);
|
|
1449
|
-
if (action === "unchanged") return void 0;
|
|
1450
|
-
const desired = engineLifecycleSupportOf(properties);
|
|
1451
|
-
if (action === "send") return desired;
|
|
1452
|
-
const idKey = kind === "DB cluster" ? "DBClusterIdentifier" : "DBInstanceIdentifier";
|
|
1453
|
-
const { mask } = withDerivedNameMasks(this.logger, createMaskedLogSinks(this.logger, context?.maskSecrets), [[previousProperties[idKey], physicalId]]);
|
|
1454
|
-
let liveRead = "read";
|
|
1455
|
-
if (action === "check-live") try {
|
|
1456
|
-
const resource = kind === "DB cluster" ? await this.describeDBCluster(physicalId) : await this.describeDBInstance(physicalId);
|
|
1457
|
-
if (resource === void 0) liveRead = "not-found";
|
|
1458
|
-
else if (resource.EngineLifecycleSupport === desired) liveRead = void 0;
|
|
1459
|
-
} catch (err) {
|
|
1460
|
-
if (err instanceof CdkdError) throw err;
|
|
1461
|
-
const faultName = err?.name;
|
|
1462
|
-
if (faultName === "DBClusterNotFoundFault" || faultName === "DBInstanceNotFoundFault") liveRead = "not-found";
|
|
1463
|
-
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));
|
|
1464
|
-
}
|
|
1465
|
-
if (liveRead === void 0) return void 0;
|
|
1466
|
-
throw markNonRetryable(new ProvisioningError(mask(engineLifecycleSupportRefusalText(resourceType, logicalId, physicalId, kind, liveRead)), resourceType, logicalId, physicalId));
|
|
1467
|
-
}
|
|
1468
|
-
async describeDBCluster(dbClusterIdentifier) {
|
|
1469
|
-
return (await this.getClient().send(new DescribeDBClustersCommand({ DBClusterIdentifier: dbClusterIdentifier }))).DBClusters?.[0];
|
|
1470
|
-
}
|
|
1471
|
-
async securityGroupsToSend(target, logicalId, physicalId, resourceType, properties, previousProperties, context) {
|
|
1472
|
-
const key = target === "DBCluster" ? "VpcSecurityGroupIds" : "VPCSecurityGroups";
|
|
1473
|
-
const noun = target === "DBCluster" ? "cluster" : "instance";
|
|
1474
|
-
const desired = properties[key];
|
|
1475
|
-
if (desired !== void 0) return desired.length > 0 ? desired : void 0;
|
|
1476
|
-
const previous = previousProperties[key];
|
|
1477
|
-
if (context?.desiredFromAwsReadback === true) return void 0;
|
|
1478
|
-
if (!Array.isArray(previous) || previous.length === 0) return void 0;
|
|
1479
|
-
let groupId;
|
|
1480
|
-
let missing;
|
|
1481
|
-
let awsError;
|
|
1482
|
-
try {
|
|
1483
|
-
let subnetGroupName;
|
|
1484
|
-
let vpcId;
|
|
1485
|
-
if (target === "DBInstance") {
|
|
1486
|
-
const subnetGroup = (await this.describeDBInstance(physicalId))?.DBSubnetGroup;
|
|
1487
|
-
subnetGroupName = subnetGroup?.DBSubnetGroupName;
|
|
1488
|
-
vpcId = subnetGroupName ? subnetGroup?.VpcId : void 0;
|
|
1489
|
-
} else {
|
|
1490
|
-
subnetGroupName = (await this.describeDBCluster(physicalId))?.DBSubnetGroup;
|
|
1491
|
-
vpcId = subnetGroupName ? (await this.getClient().send(new DescribeDBSubnetGroupsCommand({ DBSubnetGroupName: subnetGroupName }))).DBSubnetGroups?.[0]?.VpcId : void 0;
|
|
1492
|
-
}
|
|
1493
|
-
if (!subnetGroupName) missing = `the ${noun} reports no DB subnet group`;
|
|
1494
|
-
else if (!vpcId) missing = `DB subnet group ${subnetGroupName} reports no VPC`;
|
|
1495
|
-
else {
|
|
1496
|
-
groupId = (await this.getEc2Client().send(new DescribeSecurityGroupsCommand({ Filters: [{
|
|
1497
|
-
Name: "vpc-id",
|
|
1498
|
-
Values: [vpcId]
|
|
1499
|
-
}, {
|
|
1500
|
-
Name: "group-name",
|
|
1501
|
-
Values: ["default"]
|
|
1502
|
-
}] }))).SecurityGroups?.[0]?.GroupId;
|
|
1503
|
-
if (!groupId) missing = `VPC ${vpcId} has no security group named default`;
|
|
1504
|
-
}
|
|
1505
|
-
} catch (error) {
|
|
1506
|
-
awsError = error;
|
|
1507
|
-
}
|
|
1508
|
-
if (groupId === void 0) {
|
|
1509
|
-
const mask = context?.maskSecrets ?? ((text) => text);
|
|
1510
|
-
const failure = missing === void 0 ? describeAwsFailure(awsError) : void 0;
|
|
1511
|
-
if (failure?.redacted === true) this.logger.debug(safeMsg`${logicalId}: the VPC default security group lookup failed: ${mask(failure.detail)}`);
|
|
1512
|
-
const shown = mask(failure?.summary ?? "");
|
|
1513
|
-
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);
|
|
1514
|
-
if (missing !== void 0) throw markNonRetryable(refusal);
|
|
1515
|
-
throw awsError instanceof Error && (failure?.redacted === true || shown !== (failure?.summary ?? "")) ? markRedactedCause(refusal) : refusal;
|
|
1516
|
-
}
|
|
1517
|
-
this.logger.warn(safeMsg`${logicalId}: ${key} was removed from the template; attaching the VPC's default security group ${groupId}, as CloudFormation does.`);
|
|
1518
|
-
return [groupId];
|
|
1519
|
-
}
|
|
1520
|
-
async describeDBInstance(dbInstanceIdentifier) {
|
|
1521
|
-
return (await this.getClient().send(new DescribeDBInstancesCommand({ DBInstanceIdentifier: dbInstanceIdentifier }))).DBInstances?.[0];
|
|
1522
|
-
}
|
|
1523
|
-
async waitForMemberAfterClusterChange(dbInstanceIdentifier, clusterLogicalId, transitional, change, maxWaitMs = 18e5) {
|
|
1524
|
-
const startTime = Date.now();
|
|
1525
|
-
let delay = 5e3;
|
|
1526
|
-
while (Date.now() - startTime < maxWaitMs) {
|
|
1527
|
-
let status;
|
|
1528
|
-
try {
|
|
1529
|
-
status = (await this.describeDBInstance(dbInstanceIdentifier))?.DBInstanceStatus;
|
|
1530
|
-
} catch (error) {
|
|
1531
|
-
if (this.isNotFoundError(error, "DBInstanceNotFoundFault")) return;
|
|
1532
|
-
throw error;
|
|
1533
|
-
}
|
|
1534
|
-
if (status === void 0 || !transitional.has(status)) return;
|
|
1535
|
-
await this.sleep(delay);
|
|
1536
|
-
delay = Math.min(delay * 2, 1e4);
|
|
1537
|
-
}
|
|
1538
|
-
throw new Error(safeMsg`Timed out waiting for a member instance of DBCluster ${clusterLogicalId} to finish applying its new ${change}`);
|
|
1539
|
-
}
|
|
1540
|
-
requireClusterWhileWaiting(cluster, logicalId, change) {
|
|
1541
|
-
if (cluster === void 0) throw new Error(safeMsg`DescribeDBClusters returned no cluster for DBCluster ${logicalId} while waiting for its new ${change}`);
|
|
1542
|
-
if (isTerminalDbWaitStatus(cluster.Status)) throw new Error(safeMsg`DBCluster ${logicalId} entered status ${cluster.Status ?? ""} while applying its new ${change}`);
|
|
1543
|
-
return cluster;
|
|
1544
|
-
}
|
|
1545
|
-
async waitForClusterPortApplied(dbClusterIdentifier, logicalId, port, maxWaitMs = 18e5) {
|
|
1546
|
-
const startTime = Date.now();
|
|
1547
|
-
let delay = 5e3;
|
|
1548
|
-
while (Date.now() - startTime < maxWaitMs) {
|
|
1549
|
-
const cluster = this.requireClusterWhileWaiting(await this.describeDBCluster(dbClusterIdentifier), logicalId, "port");
|
|
1550
|
-
if (cluster.Status !== "modifying" && cluster.Port === port) return;
|
|
1551
|
-
this.logger.debug(safeMsg`DBCluster ${logicalId} port not applied yet (status ${cluster.Status ?? "unknown"})`);
|
|
1552
|
-
await this.sleep(delay);
|
|
1553
|
-
delay = Math.min(delay * 2, 1e4);
|
|
1554
|
-
}
|
|
1555
|
-
throw new Error(`Timed out waiting for DBCluster ${logicalId} to apply its new port`);
|
|
1556
|
-
}
|
|
1557
|
-
async waitForSecurityGroupsApplied(dbClusterIdentifier, logicalId, expected, maxWaitMs = 18e5) {
|
|
1558
|
-
const want = [...new Set(expected)].sort().join(" ");
|
|
1559
|
-
const startTime = Date.now();
|
|
1560
|
-
let delay = 5e3;
|
|
1561
|
-
while (Date.now() - startTime < maxWaitMs) {
|
|
1562
|
-
const cluster = this.requireClusterWhileWaiting(await this.describeDBCluster(dbClusterIdentifier), logicalId, "VPC security groups");
|
|
1563
|
-
const groups = cluster.VpcSecurityGroups ?? [];
|
|
1564
|
-
const ids = groups.map((group) => group.VpcSecurityGroupId ?? "").sort().join(" ");
|
|
1565
|
-
if (cluster.Status !== "modifying" && groups.every((group) => group.Status === "active") && ids === want) return;
|
|
1566
|
-
this.logger.debug(safeMsg`DBCluster ${logicalId} security groups not settled yet (status ${cluster.Status ?? "unknown"})`);
|
|
1567
|
-
await this.sleep(delay);
|
|
1568
|
-
delay = Math.min(delay * 2, 1e4);
|
|
1569
|
-
}
|
|
1570
|
-
throw new Error(`Timed out waiting for DBCluster ${logicalId} to apply its new VPC security groups`);
|
|
1571
|
-
}
|
|
1572
|
-
async waitForClusterState(logicalId, dbClusterIdentifier, done, change) {
|
|
1573
|
-
const remaining = enclosingDeadlineRemainingMs();
|
|
1574
|
-
const maxWaitMs = Number.isFinite(remaining) ? remaining : 18e5;
|
|
1575
|
-
const startTime = Date.now();
|
|
1576
|
-
let delay = 5e3;
|
|
1577
|
-
while (Date.now() - startTime < maxWaitMs) {
|
|
1578
|
-
const cluster = this.requireClusterWhileWaiting(await this.describeDBCluster(dbClusterIdentifier), logicalId, change);
|
|
1579
|
-
if (done(cluster)) return;
|
|
1580
|
-
this.logger.debug(safeMsg`DBCluster ${logicalId} waiting for its ${change} (status ${cluster.Status ?? "unknown"})`);
|
|
1581
|
-
await this.sleep(delay);
|
|
1582
|
-
delay = Math.min(delay * 2, 1e4);
|
|
1583
|
-
}
|
|
1584
|
-
throw new Error(safeMsg`Timed out waiting for DBCluster ${logicalId}'s ${change}`);
|
|
1585
|
-
}
|
|
1586
|
-
async sendHttpEndpointChange(logicalId, physicalId, arn, enable) {
|
|
1587
|
-
let delay = 5e3;
|
|
1588
|
-
for (let attempt = 1;; attempt += 1) {
|
|
1589
|
-
await this.waitForClusterState(logicalId, physicalId, (cluster) => cluster.Status === "available", "pending changes to settle before the Data API call");
|
|
1590
|
-
try {
|
|
1591
|
-
await this.getClient().send(enable ? new EnableHttpEndpointCommand({ ResourceArn: arn }) : new DisableHttpEndpointCommand({ ResourceArn: arn }));
|
|
1592
|
-
return;
|
|
1593
|
-
} catch (error) {
|
|
1594
|
-
const name = awsErrorName(error);
|
|
1595
|
-
if (!HTTP_ENDPOINT_BUSY_FAULTS.has(name) || attempt >= HTTP_ENDPOINT_MAX_ATTEMPTS) throw error;
|
|
1596
|
-
this.logger.debug(safeMsg`DBCluster ${logicalId}: the Data API call was refused as busy (${name}); retrying`);
|
|
1597
|
-
await this.sleep(delay);
|
|
1598
|
-
delay = Math.min(delay * 2, 1e4);
|
|
1599
|
-
}
|
|
1600
|
-
}
|
|
1601
|
-
}
|
|
1602
|
-
async deleteAfterProtectionFlip(logicalId, physicalId, send) {
|
|
1603
|
-
await deleteAfterProtectionFlipWithFinalSnapshot({
|
|
1604
|
-
stateFault: "InvalidDBClusterStateFault",
|
|
1605
|
-
send,
|
|
1606
|
-
noun: "cluster",
|
|
1607
|
-
label: "DBCluster",
|
|
1608
|
-
logicalId,
|
|
1609
|
-
read: async () => {
|
|
1610
|
-
const current = await this.describeDBCluster(physicalId);
|
|
1611
|
-
return current === void 0 ? void 0 : {
|
|
1612
|
-
deletionProtection: current.DeletionProtection,
|
|
1613
|
-
status: current.Status
|
|
1614
|
-
};
|
|
1615
|
-
},
|
|
1616
|
-
sleep: (ms) => this.sleep(ms),
|
|
1617
|
-
logger: this.logger,
|
|
1618
|
-
remainingMs: enclosingDeadlineRemainingMs()
|
|
1619
|
-
});
|
|
1620
|
-
}
|
|
1621
|
-
async deleteInstanceAfterProtectionFlip(logicalId, physicalId, send) {
|
|
1622
|
-
await deleteAfterProtectionFlipWithFinalSnapshot({
|
|
1623
|
-
stateFault: "InvalidDBInstanceStateFault",
|
|
1624
|
-
send,
|
|
1625
|
-
noun: "instance",
|
|
1626
|
-
label: "DBInstance",
|
|
1627
|
-
logicalId,
|
|
1628
|
-
read: async () => {
|
|
1629
|
-
const current = await this.describeDBInstance(physicalId);
|
|
1630
|
-
return current === void 0 ? void 0 : {
|
|
1631
|
-
deletionProtection: current.DeletionProtection,
|
|
1632
|
-
status: current.DBInstanceStatus
|
|
1633
|
-
};
|
|
1634
|
-
},
|
|
1635
|
-
sleep: (ms) => this.sleep(ms),
|
|
1636
|
-
logger: this.logger,
|
|
1637
|
-
remainingMs: enclosingDeadlineRemainingMs()
|
|
1638
|
-
});
|
|
1639
|
-
}
|
|
1640
|
-
desiredAssociatedRoles(properties, resourceType, logicalId, physicalId, replayingCreate) {
|
|
1641
|
-
const instance = resourceType === "AWS::RDS::DBInstance";
|
|
1642
|
-
const roles = associatedRoleList(properties["AssociatedRoles"], { featureNameRequired: instance });
|
|
1643
|
-
if (roles !== void 0) return roles;
|
|
1644
|
-
const expected = instance ? "a list of objects with a RoleArn and a FeatureName" : "a list of objects with a RoleArn";
|
|
1645
|
-
if (!replayingCreate) throw markNonRetryable(new ProvisioningError(`${resourceType} ${logicalId}: AssociatedRoles must be ${expected}; nothing was changed`, resourceType, logicalId, physicalId));
|
|
1646
|
-
this.logger.warn(safeMsg`${logicalId} (${resourceType}): the replayed AssociatedRoles is not ${expected}, so no role is attached`);
|
|
1647
|
-
return "skipped";
|
|
1648
|
-
}
|
|
1649
|
-
async applyAssociatedRoles(target, logicalId, physicalId, desired, previous, mask, marks) {
|
|
1650
|
-
const candidates = planAssociatedRoleChanges(desired, previous);
|
|
1651
|
-
if (candidates.toAdd.length === 0 && candidates.toRemove.length === 0) return;
|
|
1652
|
-
const label = target === "cluster" ? "RDS DBCluster" : "RDS DBInstance";
|
|
1653
|
-
const waitBudgetMs = Math.min(18e5, enclosingDeadlineRemainingMs() - 3e4);
|
|
1654
|
-
if (waitBudgetMs <= 0) throw new Error(`the resource timeout leaves no more time to change the roles of the ${target}; re-run the deploy, or with a longer --resource-timeout`);
|
|
1655
|
-
if (target === "cluster") await this.waitForClusterAvailable(logicalId, physicalId, waitBudgetMs, "changing its roles");
|
|
1656
|
-
else await this.waitForInstanceAvailable(logicalId, physicalId, waitBudgetMs, "changing its roles");
|
|
1657
|
-
const resource = target === "cluster" ? await this.describeDBCluster(physicalId) : await this.describeDBInstance(physicalId);
|
|
1658
|
-
if (resource === void 0) throw new Error(`Describe returned no ${target} while planning its role changes; no role was attached or detached`);
|
|
1659
|
-
const { toAdd, toRemove } = planAssociatedRoleChanges(desired, previous, resource.AssociatedRoles ?? []);
|
|
1660
|
-
if (toAdd.length === 0 && toRemove.length === 0) return;
|
|
1661
|
-
marks?.markUnsettled?.("AssociatedRoles");
|
|
1662
|
-
const readStatus = target === "cluster" ? async () => (await this.describeDBCluster(physicalId))?.Status : async () => (await this.describeDBInstance(physicalId))?.DBInstanceStatus;
|
|
1663
|
-
const whenAvailable = (send) => modifyDbInstanceWhenAvailable({
|
|
1664
|
-
send,
|
|
1665
|
-
readStatus,
|
|
1666
|
-
sleep: (ms) => this.sleep(ms),
|
|
1667
|
-
logger: this.logger,
|
|
1668
|
-
label,
|
|
1669
|
-
subject: target,
|
|
1670
|
-
isRefusal: (error) => isRoleCallNotAvailableRefusal(error) || isModifyNotAvailableRefusal(error),
|
|
1671
|
-
logicalId,
|
|
1672
|
-
remainingMs: enclosingDeadlineRemainingMs()
|
|
1673
|
-
});
|
|
1674
|
-
for (const role of toRemove) {
|
|
1675
|
-
marks?.markAttempted?.("AssociatedRoles", [associatedRoleKey(role)]);
|
|
1676
|
-
await whenAvailable(() => target === "cluster" ? this.getClient().send(new RemoveRoleFromDBClusterCommand({
|
|
1677
|
-
DBClusterIdentifier: physicalId,
|
|
1678
|
-
...role
|
|
1679
|
-
})) : this.getClient().send(new RemoveRoleFromDBInstanceCommand({
|
|
1680
|
-
DBInstanceIdentifier: physicalId,
|
|
1681
|
-
RoleArn: role.RoleArn,
|
|
1682
|
-
FeatureName: role.FeatureName
|
|
1683
|
-
})));
|
|
1684
|
-
}
|
|
1685
|
-
for (const role of toAdd) {
|
|
1686
|
-
await whenAvailable(() => target === "cluster" ? this.getClient().send(new AddRoleToDBClusterCommand({
|
|
1687
|
-
DBClusterIdentifier: physicalId,
|
|
1688
|
-
...role
|
|
1689
|
-
})) : this.getClient().send(new AddRoleToDBInstanceCommand({
|
|
1690
|
-
DBInstanceIdentifier: physicalId,
|
|
1691
|
-
RoleArn: role.RoleArn,
|
|
1692
|
-
FeatureName: role.FeatureName
|
|
1693
|
-
})));
|
|
1694
|
-
marks?.markAttempted?.("AssociatedRoles", [associatedRoleKey(role)]);
|
|
1695
|
-
}
|
|
1696
|
-
if (process.env["CDKD_NO_WAIT"] === "true") return;
|
|
1697
|
-
const attached = toAdd.map(associatedRoleKey);
|
|
1698
|
-
const detached = toRemove.map(associatedRoleKey);
|
|
1699
|
-
const settled = (roles) => {
|
|
1700
|
-
const held = new Set((roles ?? []).map(associatedRoleKey));
|
|
1701
|
-
return attached.every((key) => held.has(key)) && detached.every((key) => !held.has(key));
|
|
1702
|
-
};
|
|
1703
|
-
const change = `IAM role associations (${maskerOrIdentity(mask)(associatedRoleArns([...attached, ...detached]))})`;
|
|
1704
|
-
if (target === "cluster") await this.waitForClusterState(logicalId, physicalId, (cluster) => settled(cluster.AssociatedRoles), change);
|
|
1705
|
-
else await this.waitForInstanceState(logicalId, physicalId, (instance) => settled(instance.AssociatedRoles), change);
|
|
1706
|
-
}
|
|
1707
|
-
async waitForClusterAvailable(logicalId, dbClusterIdentifier, maxWaitMs = 18e5, doing = "being created") {
|
|
1708
|
-
const startTime = Date.now();
|
|
1709
|
-
let delay = 5e3;
|
|
1710
|
-
while (Date.now() - startTime < maxWaitMs) {
|
|
1711
|
-
const status = (await this.describeDBCluster(dbClusterIdentifier))?.Status;
|
|
1712
|
-
this.logger.debug(`DBCluster ${dbClusterIdentifier} status: ${status}`);
|
|
1713
|
-
if (status === "available") return;
|
|
1714
|
-
if (isTerminalDbWaitStatus(status)) throw new Error(safeMsg`DBCluster ${logicalId} entered status ${status ?? ""} while ${doing}, which it does not leave on its own`);
|
|
1715
|
-
await this.sleep(delay);
|
|
1716
|
-
delay = Math.min(delay * 2, 1e4);
|
|
1717
|
-
}
|
|
1718
|
-
throw new Error(`Timed out waiting for DBCluster ${dbClusterIdentifier} to become available`);
|
|
1719
|
-
}
|
|
1720
|
-
async waitForClusterDeleted(logicalId, dbClusterIdentifier, maxWaitMs = 18e5) {
|
|
1721
|
-
const startTime = Date.now();
|
|
1722
|
-
let delay = 5e3;
|
|
1723
|
-
while (Date.now() - startTime < maxWaitMs) {
|
|
1724
|
-
try {
|
|
1725
|
-
const cluster = await this.describeDBCluster(dbClusterIdentifier);
|
|
1726
|
-
const status = cluster?.Status;
|
|
1727
|
-
this.logger.debug(`DBCluster ${logicalId} status: ${status}`);
|
|
1728
|
-
if (!cluster) return;
|
|
1729
|
-
} catch (error) {
|
|
1730
|
-
if (this.isNotFoundError(error, "DBClusterNotFoundFault")) return;
|
|
1731
|
-
throw error;
|
|
1732
|
-
}
|
|
1733
|
-
await this.sleep(delay);
|
|
1734
|
-
delay = Math.min(delay * 2, 1e4);
|
|
1735
|
-
}
|
|
1736
|
-
throw new Error(`Timed out waiting for DBCluster ${logicalId} to be deleted`);
|
|
1737
|
-
}
|
|
1738
|
-
async rebootForPendingParameterGroup(logicalId, physicalId, sentGroup, caRotationRestarts) {
|
|
1739
|
-
const settled = await this.waitForInstanceState(logicalId, physicalId, (instance) => instanceParameterGroupSettled(instance, sentGroup, caRotationRestarts), "parameter group change to settle");
|
|
1740
|
-
if (!instanceParameterGroupPendingReboot(settled)) return settled;
|
|
1741
|
-
this.logger.info(safeMsg`Rebooting DBInstance ${logicalId} to apply its parameter group (pending-reboot), as CloudFormation does after an update`);
|
|
1742
|
-
await this.getClient().send(new RebootDBInstanceCommand({ DBInstanceIdentifier: physicalId }));
|
|
1743
|
-
if (process.env["CDKD_NO_WAIT"] === "true") return settled;
|
|
1744
|
-
return this.waitForInstanceState(logicalId, physicalId, instanceRebootApplied, "reboot to apply its parameter group");
|
|
1745
|
-
}
|
|
1746
|
-
async waitForInstanceState(logicalId, dbInstanceIdentifier, done, change) {
|
|
1747
|
-
const remaining = enclosingDeadlineRemainingMs();
|
|
1748
|
-
const maxWaitMs = Number.isFinite(remaining) ? remaining : 18e5;
|
|
1749
|
-
const startTime = Date.now();
|
|
1750
|
-
let delay = 5e3;
|
|
1751
|
-
while (Date.now() - startTime < maxWaitMs) {
|
|
1752
|
-
const instance = await this.describeDBInstance(dbInstanceIdentifier);
|
|
1753
|
-
if (instance === void 0) throw new Error(safeMsg`DescribeDBInstances returned no instance for DBInstance ${logicalId} while waiting for its ${change}`);
|
|
1754
|
-
if (isTerminalDbWaitStatus(instance.DBInstanceStatus)) throw new Error(safeMsg`DBInstance ${logicalId} entered status ${instance.DBInstanceStatus ?? ""} while waiting for its ${change}`);
|
|
1755
|
-
if (done(instance)) return instance;
|
|
1756
|
-
this.logger.debug(safeMsg`DBInstance ${logicalId} waiting for its ${change} (status ${instance.DBInstanceStatus ?? "unknown"})`);
|
|
1757
|
-
await this.sleep(delay);
|
|
1758
|
-
delay = Math.min(delay * 2, 1e4);
|
|
1759
|
-
}
|
|
1760
|
-
throw new Error(safeMsg`Timed out waiting for DBInstance ${logicalId}'s ${change}`);
|
|
1761
|
-
}
|
|
1762
|
-
async waitForInstanceAvailable(logicalId, dbInstanceIdentifier, maxWaitMs = 18e5, doing = "being created") {
|
|
1763
|
-
const startTime = Date.now();
|
|
1764
|
-
let delay = 1e4;
|
|
1765
|
-
while (Date.now() - startTime < maxWaitMs) {
|
|
1766
|
-
const status = (await this.describeDBInstance(dbInstanceIdentifier))?.DBInstanceStatus;
|
|
1767
|
-
this.logger.debug(`DBInstance ${dbInstanceIdentifier} status: ${status}`);
|
|
1768
|
-
if (status === "available") return;
|
|
1769
|
-
if (isTerminalDbWaitStatus(status)) throw new Error(safeMsg`DBInstance ${logicalId} entered status ${status ?? ""} while ${doing}, which it does not leave on its own`);
|
|
1770
|
-
await this.sleep(delay);
|
|
1771
|
-
delay = Math.min(delay * 2, 1e4);
|
|
1772
|
-
}
|
|
1773
|
-
throw new Error(`Timed out waiting for DBInstance ${dbInstanceIdentifier} to become available`);
|
|
1774
|
-
}
|
|
1775
|
-
async waitForInstanceDeleted(logicalId, dbInstanceIdentifier, maxWaitMs = 18e5) {
|
|
1776
|
-
const startTime = Date.now();
|
|
1777
|
-
let delay = 1e4;
|
|
1778
|
-
while (Date.now() - startTime < maxWaitMs) {
|
|
1779
|
-
try {
|
|
1780
|
-
const instance = await this.describeDBInstance(dbInstanceIdentifier);
|
|
1781
|
-
const status = instance?.DBInstanceStatus;
|
|
1782
|
-
this.logger.debug(`DBInstance ${logicalId} status: ${status}`);
|
|
1783
|
-
if (!instance) return;
|
|
1784
|
-
} catch (error) {
|
|
1785
|
-
if (this.isNotFoundError(error, "DBInstanceNotFoundFault")) return;
|
|
1786
|
-
throw error;
|
|
1787
|
-
}
|
|
1788
|
-
await this.sleep(delay);
|
|
1789
|
-
delay = Math.min(delay * 2, 1e4);
|
|
1790
|
-
}
|
|
1791
|
-
throw new Error(`Timed out waiting for DBInstance ${logicalId} to be deleted`);
|
|
1792
|
-
}
|
|
1793
|
-
sleep(ms) {
|
|
1794
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
1795
|
-
}
|
|
1796
|
-
async import(input) {
|
|
1797
|
-
switch (input.resourceType) {
|
|
1798
|
-
case "AWS::RDS::DBInstance": return this.importDBInstance(input);
|
|
1799
|
-
case "AWS::RDS::DBCluster": return this.importDBCluster(input);
|
|
1800
|
-
case "AWS::RDS::DBSubnetGroup": return this.importDBSubnetGroup(input);
|
|
1801
|
-
default: return null;
|
|
1802
|
-
}
|
|
1803
|
-
}
|
|
1804
|
-
getDriftUnorderedPaths(resourceType) {
|
|
1805
|
-
return resourceType === "AWS::RDS::DBCluster" || resourceType === "AWS::RDS::DBInstance" ? ["EnableCloudwatchLogsExports", "AssociatedRoles"] : [];
|
|
1806
|
-
}
|
|
1807
|
-
getDriftUnknownPaths(resourceType, properties) {
|
|
1808
|
-
if (resourceType === "AWS::RDS::DBInstance") return ["AllowMajorVersionUpgrade", "CertificateRotationRestart"];
|
|
1809
|
-
if (resourceType !== "AWS::RDS::DBCluster") return [];
|
|
1810
|
-
const neverRead = [
|
|
1811
|
-
"EngineMode",
|
|
1812
|
-
"AvailabilityZones",
|
|
1813
|
-
"ClusterScalabilityType",
|
|
1814
|
-
"MasterUserAuthenticationType"
|
|
1815
|
-
];
|
|
1816
|
-
if (properties === void 0 || Object.keys(properties).length === 0) return neverRead;
|
|
1817
|
-
return (properties?.["ServerlessV2ScalingConfiguration"])?.SecondsUntilAutoPause === void 0 ? [...neverRead, "ServerlessV2ScalingConfiguration.SecondsUntilAutoPause"] : neverRead;
|
|
1818
|
-
}
|
|
1819
|
-
canonicalizeDriftProperties(resourceType, properties) {
|
|
1820
|
-
if (resourceType !== "AWS::RDS::DBCluster" && resourceType !== "AWS::RDS::DBInstance") return properties;
|
|
1821
|
-
let out;
|
|
1822
|
-
const set = (key, value) => {
|
|
1823
|
-
out ??= { ...properties };
|
|
1824
|
-
out[key] = value;
|
|
1825
|
-
};
|
|
1826
|
-
if (Array.isArray(properties["AssociatedRoles"])) set("AssociatedRoles", canonicalAssociatedRoles(properties["AssociatedRoles"]));
|
|
1827
|
-
if (resourceType !== "AWS::RDS::DBCluster") return out ?? properties;
|
|
1828
|
-
for (const key of CLUSTER_BOOLEAN_SCALARS) {
|
|
1829
|
-
const value = properties[key];
|
|
1830
|
-
if (value === "true" || value === "false") set(key, value === "true");
|
|
1831
|
-
}
|
|
1832
|
-
for (const key of ["PerformanceInsightsRetentionPeriod", "BacktrackWindow"]) {
|
|
1833
|
-
const value = properties[key];
|
|
1834
|
-
if (typeof value === "string") {
|
|
1835
|
-
const parsed = retentionPeriodValue(value);
|
|
1836
|
-
if (typeof parsed === "number") set(key, parsed);
|
|
1837
|
-
}
|
|
1838
|
-
}
|
|
1839
|
-
return out ?? properties;
|
|
1840
|
-
}
|
|
1841
|
-
canonicalizeUnsettledProperties(resourceType, properties) {
|
|
1842
|
-
return this.canonicalizeDriftProperties(resourceType, properties);
|
|
1843
|
-
}
|
|
1844
|
-
async readUnsettled(physicalId, logicalId, resourceType, names, recordedProperties, desiredProperties, attemptedItems) {
|
|
1845
|
-
const live = await this.readCurrentState(physicalId, logicalId, resourceType);
|
|
1846
|
-
if (live === void 0 || live === RESOURCE_NOT_FOUND) return live;
|
|
1847
|
-
if (!names.has("AssociatedRoles")) return live;
|
|
1848
|
-
return {
|
|
1849
|
-
...live,
|
|
1850
|
-
AssociatedRoles: associatedRolesNamed(live["AssociatedRoles"], recordedProperties?.["AssociatedRoles"], desiredProperties?.["AssociatedRoles"], attemptedItems?.get("AssociatedRoles"))
|
|
1851
|
-
};
|
|
1852
|
-
}
|
|
1853
|
-
async readCurrentState(physicalId, _logicalId, resourceType) {
|
|
1854
|
-
switch (resourceType) {
|
|
1855
|
-
case "AWS::RDS::DBInstance": return this.readCurrentStateDBInstance(physicalId);
|
|
1856
|
-
case "AWS::RDS::DBCluster": return this.readCurrentStateDBCluster(physicalId);
|
|
1857
|
-
case "AWS::RDS::DBSubnetGroup": return this.readCurrentStateDBSubnetGroup(physicalId);
|
|
1858
|
-
default: return;
|
|
1859
|
-
}
|
|
1860
|
-
}
|
|
1861
|
-
async isSameResource(journaledPhysicalId, record, resourceType, context) {
|
|
1862
|
-
if (resourceType !== "AWS::RDS::DBCluster" && resourceType !== "AWS::RDS::DBInstance") return "unknown";
|
|
1863
|
-
if (!isDbIdentifier(journaledPhysicalId) || !isDbIdentifier(record.physicalId)) return "unknown";
|
|
1864
|
-
if (journaledPhysicalId.toLowerCase() === record.physicalId.toLowerCase()) return "same";
|
|
1865
|
-
if (await this.getClient().config.region() !== context.expectedRegion) return "unknown";
|
|
1866
|
-
const recordResourceId = await this.readDbResourceIdIfExists(resourceType, record.physicalId);
|
|
1867
|
-
if (recordResourceId === void 0) return "unknown";
|
|
1868
|
-
const journaledResourceId = await this.readDbResourceIdIfExists(resourceType, journaledPhysicalId);
|
|
1869
|
-
if (journaledResourceId === void 0) return "different";
|
|
1870
|
-
return journaledResourceId === recordResourceId ? "same" : "different";
|
|
1871
|
-
}
|
|
1872
|
-
async resourceIdentity(physicalId, resourceType, context) {
|
|
1873
|
-
if (resourceType !== "AWS::RDS::DBCluster" && resourceType !== "AWS::RDS::DBInstance") return;
|
|
1874
|
-
if (!isDbIdentifier(physicalId)) return void 0;
|
|
1875
|
-
if (await this.getClient().config.region() !== context.expectedRegion) return void 0;
|
|
1876
|
-
const live = await this.readDbResourceIdIfExists(resourceType, physicalId);
|
|
1877
|
-
return live === void 0 ? RESOURCE_NOT_FOUND : live;
|
|
1878
|
-
}
|
|
1879
|
-
async readDbResourceIdIfExists(resourceType, identifier) {
|
|
1880
|
-
const isCluster = resourceType === "AWS::RDS::DBCluster";
|
|
1881
|
-
let found;
|
|
1882
|
-
try {
|
|
1883
|
-
if (isCluster) {
|
|
1884
|
-
const cluster = await this.describeDBCluster(identifier);
|
|
1885
|
-
found = cluster && {
|
|
1886
|
-
identifier: cluster.DBClusterIdentifier,
|
|
1887
|
-
resourceId: cluster.DbClusterResourceId
|
|
1888
|
-
};
|
|
1889
|
-
} else {
|
|
1890
|
-
const instance = await this.describeDBInstance(identifier);
|
|
1891
|
-
found = instance && {
|
|
1892
|
-
identifier: instance.DBInstanceIdentifier,
|
|
1893
|
-
resourceId: instance.DbiResourceId
|
|
1894
|
-
};
|
|
1895
|
-
}
|
|
1896
|
-
} catch (error) {
|
|
1897
|
-
const notFound = isCluster ? "DBClusterNotFoundFault" : "DBInstanceNotFoundFault";
|
|
1898
|
-
if (error?.name === notFound) return void 0;
|
|
1899
|
-
throw error;
|
|
1900
|
-
}
|
|
1901
|
-
if (found === void 0) return void 0;
|
|
1902
|
-
const api = isCluster ? "DescribeDBClusters" : "DescribeDBInstances";
|
|
1903
|
-
if (found.identifier?.toLowerCase() !== identifier.toLowerCase()) throw new Error(`${api} answered for another identifier`);
|
|
1904
|
-
if (typeof found.resourceId !== "string" || found.resourceId === "") throw new Error(`${api} returned no resource id`);
|
|
1905
|
-
return found.resourceId;
|
|
1906
|
-
}
|
|
1907
|
-
async readCurrentStateDBInstance(physicalId) {
|
|
1908
|
-
let inst;
|
|
1909
|
-
try {
|
|
1910
|
-
inst = await this.describeDBInstance(physicalId);
|
|
1911
|
-
} catch (err) {
|
|
1912
|
-
if (err?.name === "DBInstanceNotFoundFault") return RESOURCE_NOT_FOUND;
|
|
1913
|
-
if (this.isNotFoundError(err, "DBInstanceNotFoundFault")) return void 0;
|
|
1914
|
-
throw err;
|
|
1915
|
-
}
|
|
1916
|
-
if (!inst) return RESOURCE_NOT_FOUND;
|
|
1917
|
-
const result = {};
|
|
1918
|
-
if (inst.DBInstanceIdentifier !== void 0) result["DBInstanceIdentifier"] = inst.DBInstanceIdentifier;
|
|
1919
|
-
if (inst.DBInstanceClass !== void 0) result["DBInstanceClass"] = inst.DBInstanceClass;
|
|
1920
|
-
if (inst.Engine !== void 0) result["Engine"] = inst.Engine;
|
|
1921
|
-
if (inst.DBClusterIdentifier !== void 0) result["DBClusterIdentifier"] = inst.DBClusterIdentifier;
|
|
1922
|
-
if (inst.DBSubnetGroup?.DBSubnetGroupName !== void 0) result["DBSubnetGroupName"] = inst.DBSubnetGroup.DBSubnetGroupName;
|
|
1923
|
-
if (inst.PubliclyAccessible !== void 0) result["PubliclyAccessible"] = inst.PubliclyAccessible;
|
|
1924
|
-
if (inst.AllocatedStorage !== void 0) result["AllocatedStorage"] = inst.AllocatedStorage;
|
|
1925
|
-
if (inst.MasterUsername !== void 0) result["MasterUsername"] = inst.MasterUsername;
|
|
1926
|
-
if (inst.DeletionProtection !== void 0) result["DeletionProtection"] = inst.DeletionProtection;
|
|
1927
|
-
if (inst.EngineVersion !== void 0) result["EngineVersion"] = inst.EngineVersion;
|
|
1928
|
-
if (inst.Endpoint?.Port !== void 0) result["Port"] = inst.Endpoint.Port;
|
|
1929
|
-
if (inst.StorageEncrypted !== void 0) result["StorageEncrypted"] = inst.StorageEncrypted;
|
|
1930
|
-
const sgIds = (inst.VpcSecurityGroups ?? []).map((sg) => sg.VpcSecurityGroupId).filter((id) => !!id);
|
|
1931
|
-
if (sgIds.length > 0) result["VPCSecurityGroups"] = sgIds;
|
|
1932
|
-
if (inst.KmsKeyId !== void 0) result["KmsKeyId"] = inst.KmsKeyId;
|
|
1933
|
-
if (inst.MonitoringRoleArn !== void 0) result["MonitoringRoleArn"] = inst.MonitoringRoleArn;
|
|
1934
|
-
if (inst.MonitoringInterval !== void 0) result["MonitoringInterval"] = inst.MonitoringInterval;
|
|
1935
|
-
if (inst.IAMDatabaseAuthenticationEnabled !== void 0) result["EnableIAMDatabaseAuthentication"] = inst.IAMDatabaseAuthenticationEnabled;
|
|
1936
|
-
if (inst.MasterUserSecret?.KmsKeyId !== void 0) result["MasterUserSecret"] = { KmsKeyId: inst.MasterUserSecret.KmsKeyId };
|
|
1937
|
-
for (const key of [
|
|
1938
|
-
"BackupRetentionPeriod",
|
|
1939
|
-
"PreferredBackupWindow",
|
|
1940
|
-
"PreferredMaintenanceWindow",
|
|
1941
|
-
"StorageType",
|
|
1942
|
-
"MultiAZ",
|
|
1943
|
-
"MaxAllocatedStorage",
|
|
1944
|
-
"AutoMinorVersionUpgrade",
|
|
1945
|
-
"CopyTagsToSnapshot",
|
|
1946
|
-
"PerformanceInsightsKMSKeyId",
|
|
1947
|
-
"PerformanceInsightsRetentionPeriod",
|
|
1948
|
-
"Iops",
|
|
1949
|
-
"StorageThroughput",
|
|
1950
|
-
"CACertificateIdentifier",
|
|
1951
|
-
"NetworkType",
|
|
1952
|
-
"LicenseModel",
|
|
1953
|
-
"PromotionTier",
|
|
1954
|
-
"DatabaseInsightsMode",
|
|
1955
|
-
"DedicatedLogVolume"
|
|
1956
|
-
]) if (inst[key] !== void 0) result[key] = inst[key];
|
|
1957
|
-
if (inst.PerformanceInsightsEnabled !== void 0) result["EnablePerformanceInsights"] = inst.PerformanceInsightsEnabled;
|
|
1958
|
-
const memberships = inst.OptionGroupMemberships ?? [];
|
|
1959
|
-
const optionGroupName = (memberships.find((m) => m.Status === "in-sync" || m.Status === "pending-apply") ?? memberships[0])?.OptionGroupName;
|
|
1960
|
-
if (optionGroupName !== void 0) result["OptionGroupName"] = optionGroupName;
|
|
1961
|
-
const parameterGroupName = inst.DBParameterGroups?.[0]?.DBParameterGroupName;
|
|
1962
|
-
if (parameterGroupName !== void 0) result["DBParameterGroupName"] = parameterGroupName;
|
|
1963
|
-
if (inst.DBClusterIdentifier === void 0) {
|
|
1964
|
-
const instanceLogs = liveLogExports(inst.EnabledCloudwatchLogsExports, inst.PendingModifiedValues?.PendingCloudwatchLogsExports);
|
|
1965
|
-
if (instanceLogs.length > 0) result["EnableCloudwatchLogsExports"] = instanceLogs;
|
|
1966
|
-
}
|
|
1967
|
-
if (inst.DBName !== void 0) result["DBName"] = inst.DBName;
|
|
1968
|
-
if (inst.AvailabilityZone !== void 0 && inst.MultiAZ !== true) result["AvailabilityZone"] = inst.AvailabilityZone;
|
|
1969
|
-
if (inst.EngineLifecycleSupport !== void 0 && inst.DBClusterIdentifier === void 0) result["EngineLifecycleSupport"] = inst.EngineLifecycleSupport;
|
|
1970
|
-
result["AssociatedRoles"] = associatedRolesReadback(inst.AssociatedRoles);
|
|
1971
|
-
if (inst.DBInstanceArn) await this.attachTags(result, inst.DBInstanceArn);
|
|
1972
|
-
return result;
|
|
1973
|
-
}
|
|
1974
|
-
async readCurrentStateDBCluster(physicalId) {
|
|
1975
|
-
let cluster;
|
|
1976
|
-
try {
|
|
1977
|
-
cluster = await this.describeDBCluster(physicalId);
|
|
1978
|
-
} catch (err) {
|
|
1979
|
-
if (err?.name === "DBClusterNotFoundFault") return RESOURCE_NOT_FOUND;
|
|
1980
|
-
if (this.isNotFoundError(err, "DBClusterNotFoundFault")) return void 0;
|
|
1981
|
-
throw err;
|
|
1982
|
-
}
|
|
1983
|
-
if (!cluster) return RESOURCE_NOT_FOUND;
|
|
1984
|
-
const result = {};
|
|
1985
|
-
if (cluster.DBClusterIdentifier !== void 0) result["DBClusterIdentifier"] = cluster.DBClusterIdentifier;
|
|
1986
|
-
if (cluster.Engine !== void 0) result["Engine"] = cluster.Engine;
|
|
1987
|
-
if (cluster.EngineVersion !== void 0) result["EngineVersion"] = cluster.EngineVersion;
|
|
1988
|
-
if (cluster.MasterUsername !== void 0) result["MasterUsername"] = cluster.MasterUsername;
|
|
1989
|
-
if (cluster.DatabaseName !== void 0) result["DatabaseName"] = cluster.DatabaseName;
|
|
1990
|
-
if (cluster.Port !== void 0) result["Port"] = cluster.Port;
|
|
1991
|
-
result["VpcSecurityGroupIds"] = (cluster.VpcSecurityGroups ?? []).map((sg) => sg.VpcSecurityGroupId).filter((id) => !!id);
|
|
1992
|
-
if (cluster.DBSubnetGroup !== void 0) result["DBSubnetGroupName"] = cluster.DBSubnetGroup;
|
|
1993
|
-
if (cluster.StorageEncrypted !== void 0) result["StorageEncrypted"] = cluster.StorageEncrypted;
|
|
1994
|
-
if (cluster.KmsKeyId !== void 0) result["KmsKeyId"] = cluster.KmsKeyId;
|
|
1995
|
-
if (cluster.BackupRetentionPeriod !== void 0) result["BackupRetentionPeriod"] = cluster.BackupRetentionPeriod;
|
|
1996
|
-
if (cluster.DeletionProtection !== void 0) result["DeletionProtection"] = cluster.DeletionProtection;
|
|
1997
|
-
if (cluster.MonitoringRoleArn !== void 0) result["MonitoringRoleArn"] = cluster.MonitoringRoleArn;
|
|
1998
|
-
if (cluster.MonitoringInterval !== void 0) result["MonitoringInterval"] = cluster.MonitoringInterval;
|
|
1999
|
-
if (cluster.IAMDatabaseAuthenticationEnabled !== void 0) result["EnableIAMDatabaseAuthentication"] = cluster.IAMDatabaseAuthenticationEnabled;
|
|
2000
|
-
if (cluster.PubliclyAccessible !== void 0) result["PubliclyAccessible"] = cluster.PubliclyAccessible;
|
|
2001
|
-
if (cluster.MasterUserSecret?.KmsKeyId !== void 0) result["MasterUserSecret"] = { KmsKeyId: cluster.MasterUserSecret.KmsKeyId };
|
|
2002
|
-
if (cluster.ServerlessV2ScalingConfiguration?.MinCapacity !== void 0 || cluster.ServerlessV2ScalingConfiguration?.MaxCapacity !== void 0) {
|
|
2003
|
-
const sc = {};
|
|
2004
|
-
if (cluster.ServerlessV2ScalingConfiguration?.MinCapacity !== void 0) sc["MinCapacity"] = cluster.ServerlessV2ScalingConfiguration.MinCapacity;
|
|
2005
|
-
if (cluster.ServerlessV2ScalingConfiguration?.MaxCapacity !== void 0) sc["MaxCapacity"] = cluster.ServerlessV2ScalingConfiguration.MaxCapacity;
|
|
2006
|
-
if (cluster.ServerlessV2ScalingConfiguration?.SecondsUntilAutoPause !== void 0) sc["SecondsUntilAutoPause"] = cluster.ServerlessV2ScalingConfiguration.SecondsUntilAutoPause;
|
|
2007
|
-
result["ServerlessV2ScalingConfiguration"] = sc;
|
|
2008
|
-
}
|
|
2009
|
-
if (cluster.DBClusterParameterGroup !== void 0) result["DBClusterParameterGroupName"] = cluster.DBClusterParameterGroup;
|
|
2010
|
-
if (cluster.PreferredBackupWindow !== void 0) result["PreferredBackupWindow"] = cluster.PreferredBackupWindow;
|
|
2011
|
-
if (cluster.PreferredMaintenanceWindow !== void 0) result["PreferredMaintenanceWindow"] = cluster.PreferredMaintenanceWindow;
|
|
2012
|
-
if (cluster.CopyTagsToSnapshot !== void 0) result["CopyTagsToSnapshot"] = cluster.CopyTagsToSnapshot;
|
|
2013
|
-
const storageType = cluster.PendingModifiedValues?.StorageType ?? cluster.StorageType ?? (cluster.Engine?.toLowerCase().startsWith("aurora") ? "aurora" : void 0);
|
|
2014
|
-
if (storageType !== void 0) result["StorageType"] = storageType;
|
|
2015
|
-
const clusterLogs = liveLogExports(cluster.EnabledCloudwatchLogsExports, cluster.PendingModifiedValues?.PendingCloudwatchLogsExports);
|
|
2016
|
-
if (clusterLogs.length > 0) result["EnableCloudwatchLogsExports"] = clusterLogs;
|
|
2017
|
-
if (cluster.AutoMinorVersionUpgrade !== void 0) result["AutoMinorVersionUpgrade"] = cluster.AutoMinorVersionUpgrade;
|
|
2018
|
-
if (cluster.NetworkType !== void 0) result["NetworkType"] = cluster.NetworkType;
|
|
2019
|
-
if (cluster.PerformanceInsightsEnabled !== void 0) result["PerformanceInsightsEnabled"] = cluster.PerformanceInsightsEnabled;
|
|
2020
|
-
if (cluster.PerformanceInsightsKMSKeyId !== void 0) result["PerformanceInsightsKmsKeyId"] = cluster.PerformanceInsightsKMSKeyId;
|
|
2021
|
-
if (cluster.PerformanceInsightsRetentionPeriod !== void 0) result["PerformanceInsightsRetentionPeriod"] = cluster.PerformanceInsightsRetentionPeriod;
|
|
2022
|
-
if (cluster.HttpEndpointEnabled !== void 0) result["EnableHttpEndpoint"] = cluster.HttpEndpointEnabled;
|
|
2023
|
-
if (cluster.DatabaseInsightsMode !== void 0) result["DatabaseInsightsMode"] = cluster.DatabaseInsightsMode;
|
|
2024
|
-
if (cluster.EngineLifecycleSupport !== void 0) result["EngineLifecycleSupport"] = cluster.EngineLifecycleSupport;
|
|
2025
|
-
if (cluster.BacktrackWindow !== void 0) result["BacktrackWindow"] = cluster.BacktrackWindow;
|
|
2026
|
-
if (cluster.LocalWriteForwardingStatus !== void 0) result["EnableLocalWriteForwarding"] = cluster.LocalWriteForwardingStatus === "requested" || cluster.LocalWriteForwardingStatus === "enabled";
|
|
2027
|
-
result["AssociatedRoles"] = associatedRolesReadback(cluster.AssociatedRoles);
|
|
2028
|
-
if (cluster.DBClusterArn) await this.attachTags(result, cluster.DBClusterArn);
|
|
2029
|
-
return result;
|
|
2030
|
-
}
|
|
2031
|
-
async readCurrentStateDBSubnetGroup(physicalId) {
|
|
2032
|
-
let resp;
|
|
2033
|
-
try {
|
|
2034
|
-
resp = await this.getClient().send(new DescribeDBSubnetGroupsCommand({ DBSubnetGroupName: physicalId }));
|
|
2035
|
-
} catch (err) {
|
|
2036
|
-
if (err?.name === "DBSubnetGroupNotFoundFault") return RESOURCE_NOT_FOUND;
|
|
2037
|
-
if (this.isNotFoundError(err, "DBSubnetGroupNotFoundFault")) return void 0;
|
|
2038
|
-
throw err;
|
|
2039
|
-
}
|
|
2040
|
-
const sg = resp.DBSubnetGroups?.[0];
|
|
2041
|
-
if (!sg) return RESOURCE_NOT_FOUND;
|
|
2042
|
-
const result = {};
|
|
2043
|
-
if (sg.DBSubnetGroupName !== void 0) result["DBSubnetGroupName"] = sg.DBSubnetGroupName;
|
|
2044
|
-
if (sg.DBSubnetGroupDescription !== void 0) result["DBSubnetGroupDescription"] = sg.DBSubnetGroupDescription;
|
|
2045
|
-
result["SubnetIds"] = (sg.Subnets ?? []).map((s) => s.SubnetIdentifier).filter((id) => !!id);
|
|
2046
|
-
if (sg.DBSubnetGroupArn) await this.attachTags(result, sg.DBSubnetGroupArn);
|
|
2047
|
-
return result;
|
|
2048
|
-
}
|
|
2049
|
-
async attachTags(result, arn) {
|
|
2050
|
-
try {
|
|
2051
|
-
const tagsResp = await this.getClient().send(new ListTagsForResourceCommand({ ResourceName: arn }));
|
|
2052
|
-
result["Tags"] = normalizeAwsTagsToCfn(tagsResp.TagList);
|
|
2053
|
-
} catch (err) {
|
|
2054
|
-
this.logger.debug(`RDS ListTagsForResource(${arn}) failed: ${describeAwsFailure(err).detail}`);
|
|
2055
|
-
}
|
|
2056
|
-
}
|
|
2057
|
-
async importDBInstance(input) {
|
|
2058
|
-
const explicit = resolveExplicitPhysicalId(input, "DBInstanceIdentifier");
|
|
2059
|
-
if (explicit) try {
|
|
2060
|
-
const described = (await this.getClient().send(new DescribeDBInstancesCommand({ DBInstanceIdentifier: explicit }))).DBInstances?.[0];
|
|
2061
|
-
return {
|
|
2062
|
-
physicalId: explicit,
|
|
2063
|
-
attributes: definedAttributes({
|
|
2064
|
-
"Endpoint.Address": described?.Endpoint?.Address,
|
|
2065
|
-
"Endpoint.Port": stringifyIfAssigned(described?.Endpoint?.Port),
|
|
2066
|
-
Arn: described?.DBInstanceArn
|
|
2067
|
-
})
|
|
2068
|
-
};
|
|
2069
|
-
} catch (err) {
|
|
2070
|
-
if (err.name === "DBInstanceNotFoundFault") return null;
|
|
2071
|
-
throw err;
|
|
2072
|
-
}
|
|
2073
|
-
return null;
|
|
2074
|
-
}
|
|
2075
|
-
async importDBCluster(input) {
|
|
2076
|
-
const explicit = resolveExplicitPhysicalId(input, "DBClusterIdentifier");
|
|
2077
|
-
if (explicit) try {
|
|
2078
|
-
const described = (await this.getClient().send(new DescribeDBClustersCommand({ DBClusterIdentifier: explicit }))).DBClusters?.[0];
|
|
2079
|
-
return {
|
|
2080
|
-
physicalId: explicit,
|
|
2081
|
-
attributes: definedAttributes({
|
|
2082
|
-
"Endpoint.Address": described?.Endpoint,
|
|
2083
|
-
"Endpoint.Port": stringifyIfAssigned(described?.Port),
|
|
2084
|
-
"ReadEndpoint.Address": described?.ReaderEndpoint,
|
|
2085
|
-
Arn: described?.DBClusterArn,
|
|
2086
|
-
DBClusterResourceId: described?.DbClusterResourceId
|
|
2087
|
-
})
|
|
2088
|
-
};
|
|
2089
|
-
} catch (err) {
|
|
2090
|
-
if (err.name === "DBClusterNotFoundFault") return null;
|
|
2091
|
-
throw err;
|
|
2092
|
-
}
|
|
2093
|
-
return null;
|
|
2094
|
-
}
|
|
2095
|
-
async importDBSubnetGroup(input) {
|
|
2096
|
-
const explicit = resolveExplicitPhysicalId(input, "DBSubnetGroupName");
|
|
2097
|
-
if (explicit) try {
|
|
2098
|
-
const arn = (await this.getClient().send(new DescribeDBSubnetGroupsCommand({ DBSubnetGroupName: explicit }))).DBSubnetGroups?.[0]?.DBSubnetGroupArn;
|
|
2099
|
-
return {
|
|
2100
|
-
physicalId: explicit,
|
|
2101
|
-
attributes: { ...arn !== void 0 && { DBSubnetGroupArn: arn } }
|
|
2102
|
-
};
|
|
2103
|
-
} catch (err) {
|
|
2104
|
-
if (err.name === "DBSubnetGroupNotFoundFault") return null;
|
|
2105
|
-
throw err;
|
|
2106
|
-
}
|
|
2107
|
-
return null;
|
|
2108
|
-
}
|
|
2109
|
-
};
|
|
2110
|
-
function securityGroupListChanged(sent, previous) {
|
|
2111
|
-
if (sent === void 0) return false;
|
|
2112
|
-
const before = Array.isArray(previous) ? previous.filter((id) => typeof id === "string") : [];
|
|
2113
|
-
return [...sent].sort().join(" ") !== [...before].sort().join(" ");
|
|
2114
|
-
}
|
|
2115
|
-
|
|
2116
|
-
export { RDSProvider };
|
|
2117
|
-
//# sourceMappingURL=rds-provider-uCvjWdCy.js.map
|