cdk-real-drift 0.12.62 → 0.12.64

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/cli.js CHANGED
@@ -5942,6 +5942,86 @@ function remapSortedIndexToDeclared(path, arrayKey, sortedDeclared, rawDeclared)
5942
5942
  const rawIdx = rawDeclared.findIndex((e) => deepEqual(e, el));
5943
5943
  return rawIdx < 0 ? path : `${arrayKey}.${rawIdx}${m[2]}`;
5944
5944
  }
5945
+ const S3_NOTIF_FILTER_RULE_NAMES = {
5946
+ prefix: "prefix",
5947
+ suffix: "suffix",
5948
+ Prefix: "prefix",
5949
+ Suffix: "suffix"
5950
+ };
5951
+ function canonS3NotifFilter(filter) {
5952
+ if (!filter || typeof filter !== "object") return filter;
5953
+ const f = filter;
5954
+ const inner = f.S3Key ?? f.Key;
5955
+ if (!inner || typeof inner !== "object") return filter;
5956
+ const rulesRaw = inner.Rules ?? inner.FilterRules;
5957
+ return { S3Key: { Rules: Array.isArray(rulesRaw) ? sortUnorderedObjectArray(rulesRaw.map((r) => {
5958
+ if (!r || typeof r !== "object") return r;
5959
+ const rule = r;
5960
+ const name = rule.Name;
5961
+ return {
5962
+ ...rule,
5963
+ Name: typeof name === "string" ? S3_NOTIF_FILTER_RULE_NAMES[name] ?? name : name
5964
+ };
5965
+ })) : rulesRaw } };
5966
+ }
5967
+ function translateBucketNotificationConfigs(configs, arnKey, targetKey) {
5968
+ if (!Array.isArray(configs)) return [];
5969
+ const out = [];
5970
+ for (const c of configs) {
5971
+ if (!c || typeof c !== "object") {
5972
+ out.push(c);
5973
+ continue;
5974
+ }
5975
+ const { Events, Filter, [arnKey]: arn, ...rest } = c;
5976
+ const base = { ...rest };
5977
+ if (arn !== void 0) base[targetKey] = arn;
5978
+ if (Filter !== void 0) base.Filter = canonS3NotifFilter(Filter);
5979
+ const events = Array.isArray(Events) ? Events : Events !== void 0 ? [Events] : void 0;
5980
+ if (events && events.length > 0) for (const ev of events) out.push({
5981
+ ...base,
5982
+ Event: ev
5983
+ });
5984
+ else out.push(base);
5985
+ }
5986
+ return out;
5987
+ }
5988
+ function canonS3NotifBucketConfig(config) {
5989
+ if (!config || typeof config !== "object" || Array.isArray(config)) return config;
5990
+ const c = config;
5991
+ const out = { ...c };
5992
+ for (const key of [
5993
+ "LambdaConfigurations",
5994
+ "QueueConfigurations",
5995
+ "TopicConfigurations"
5996
+ ]) {
5997
+ const arr = c[key];
5998
+ if (!Array.isArray(arr)) continue;
5999
+ out[key] = sortUnorderedObjectArray(arr.map((entry) => {
6000
+ if (!entry || typeof entry !== "object") return entry;
6001
+ const e = entry;
6002
+ return "Filter" in e ? {
6003
+ ...e,
6004
+ Filter: canonS3NotifFilter(e.Filter)
6005
+ } : e;
6006
+ }));
6007
+ }
6008
+ return out;
6009
+ }
6010
+ function translateDeclaredBucketNotification(declaredConfig) {
6011
+ const out = {};
6012
+ if ("EventBridgeConfiguration" in declaredConfig) out.EventBridgeConfiguration = declaredConfig.EventBridgeConfiguration;
6013
+ const lambda = translateBucketNotificationConfigs(declaredConfig.LambdaFunctionConfigurations ?? declaredConfig.LambdaConfigurations, "LambdaFunctionArn", "Function");
6014
+ if (lambda.length > 0) out.LambdaConfigurations = lambda;
6015
+ const queue = translateBucketNotificationConfigs(declaredConfig.QueueConfigurations, "QueueArn", "Queue");
6016
+ if (queue.length > 0) out.QueueConfigurations = queue;
6017
+ const topic = translateBucketNotificationConfigs(declaredConfig.TopicConfigurations, "TopicArn", "Topic");
6018
+ if (topic.length > 0) out.TopicConfigurations = topic;
6019
+ for (const [k, v] of Object.entries(declaredConfig)) {
6020
+ if (k === "EventBridgeConfiguration" || k === "LambdaFunctionConfigurations" || k === "LambdaConfigurations" || k === "QueueConfigurations" || k === "TopicConfigurations") continue;
6021
+ out[k] = v;
6022
+ }
6023
+ return out;
6024
+ }
5945
6025
  function expandExecuteApiResources(policy, arnPrefix) {
5946
6026
  if (!policy || typeof policy !== "object" || Array.isArray(policy)) return policy;
5947
6027
  const p = policy;
@@ -6131,7 +6211,9 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
6131
6211
  const selfDeclared = declaresTarget(declared.InstanceId) || declaresTarget(declared.NetworkInterfaceId);
6132
6212
  if (explained || selfDeclared) delete live.NetworkInterfaceId;
6133
6213
  }
6134
- if (resourceType === "AWS::S3::Bucket" && physicalId && opts.bucketNotificationManaged?.has(physicalId) && !("NotificationConfiguration" in declared)) delete live.NotificationConfiguration;
6214
+ if (resourceType === "AWS::S3::Bucket" && physicalId && opts.bucketNotificationManaged?.has(physicalId) && !("NotificationConfiguration" in declared)) {
6215
+ if (deepEqual(canonicalizeForCompare(canonS3NotifBucketConfig(translateDeclaredBucketNotification(opts.bucketNotificationConfigs?.[physicalId] ?? {})), resourceType), canonicalizeForCompare(canonS3NotifBucketConfig(live.NotificationConfiguration), resourceType))) delete live.NotificationConfiguration;
6216
+ }
6135
6217
  const echoSpec = CLUSTER_ECHO_CHILD[resourceType];
6136
6218
  const echoModel = echoSpec && physicalId ? opts.clusterEchoModel?.[physicalId] : void 0;
6137
6219
  if (echoSpec && echoModel) for (const k of Object.keys(live)) {
@@ -7148,12 +7230,52 @@ const CHILD_ENUMERATORS = {
7148
7230
  "AWS::RDS::DBCluster": enumerateRdsClusterChildren,
7149
7231
  "AWS::Route53::HostedZone": enumerateRoute53HostedZoneChildren
7150
7232
  };
7233
+ function normalizeApiPath(p) {
7234
+ let out = p.startsWith("/") ? p : `/${p}`;
7235
+ if (out.length > 1 && out.endsWith("/")) out = out.slice(0, -1);
7236
+ return out;
7237
+ }
7238
+ const OPENAPI_HTTP_VERBS = new Set([
7239
+ "get",
7240
+ "post",
7241
+ "put",
7242
+ "delete",
7243
+ "patch",
7244
+ "head",
7245
+ "options"
7246
+ ]);
7247
+ function deriveSpecRestApiPaths(body) {
7248
+ if (typeof body !== "object" || body === null || Array.isArray(body)) return null;
7249
+ const rawPaths = body.paths;
7250
+ if (typeof rawPaths !== "object" || rawPaths === null || Array.isArray(rawPaths)) return null;
7251
+ const paths = /* @__PURE__ */ new Set();
7252
+ const methods = /* @__PURE__ */ new Set();
7253
+ for (const [rawKey, ops] of Object.entries(rawPaths)) {
7254
+ const norm = normalizeApiPath(rawKey);
7255
+ const segs = norm.split("/").filter((s) => s.length > 0);
7256
+ paths.add("/");
7257
+ let acc = "";
7258
+ for (const s of segs) {
7259
+ acc = `${acc}/${s}`;
7260
+ paths.add(acc);
7261
+ }
7262
+ if (typeof ops === "object" && ops !== null && !Array.isArray(ops)) for (const opKey of Object.keys(ops)) {
7263
+ const lower = opKey.toLowerCase();
7264
+ if (OPENAPI_HTTP_VERBS.has(lower)) methods.add(`${norm}|${lower.toUpperCase()}`);
7265
+ else if (lower === "x-amazon-apigateway-any-method") methods.add(`${norm}|ANY`);
7266
+ }
7267
+ }
7268
+ return {
7269
+ paths,
7270
+ methods
7271
+ };
7272
+ }
7151
7273
  function isBodyDefinedRestApi(declared) {
7152
7274
  return declared.Body != null || declared.BodyS3Location != null;
7153
7275
  }
7154
7276
  function diffApiGatewayChildren(input) {
7155
- const { apiId, rootResourceId, declaredResourceIds, declaredMethodKeys, liveResources, liveMethodsByResource, bodyDefined } = input;
7156
- if (bodyDefined) return [];
7277
+ const { apiId, rootResourceId, declaredResourceIds, declaredMethodKeys, liveResources, liveMethodsByResource, bodyDefined, specChildren } = input;
7278
+ if (bodyDefined && !specChildren) return [];
7157
7279
  const liveRootId = liveResources.find((r) => r.path === "/")?.id;
7158
7280
  const declaredResources = new Set(declaredResourceIds);
7159
7281
  if (rootResourceId) declaredResources.add(rootResourceId);
@@ -7166,6 +7288,10 @@ function diffApiGatewayChildren(input) {
7166
7288
  const addedResourceIds = /* @__PURE__ */ new Set();
7167
7289
  for (const r of liveResources) {
7168
7290
  if (declaredResources.has(r.id)) continue;
7291
+ if (specChildren) {
7292
+ const normPath = r.path != null ? normalizeApiPath(r.path) : void 0;
7293
+ if (normPath != null && specChildren.paths.has(normPath)) continue;
7294
+ }
7169
7295
  addedResourceIds.add(r.id);
7170
7296
  added.push({
7171
7297
  resourceType: "AWS::ApiGateway::Resource",
@@ -7178,7 +7304,13 @@ function diffApiGatewayChildren(input) {
7178
7304
  if (addedResourceIds.has(resourceId)) continue;
7179
7305
  if (!rootResourceId && resourceId === liveRootId) continue;
7180
7306
  for (const m of methods) {
7181
- if (declaredMethods.has(`${resourceId}|${m.httpMethod}`)) continue;
7307
+ if (specChildren) {
7308
+ if (m.httpMethod === "OPTIONS") continue;
7309
+ const resPath = pathOf.get(resourceId);
7310
+ if (resPath === void 0) continue;
7311
+ const normResPath = normalizeApiPath(resPath);
7312
+ if (specChildren.methods.has(`${normResPath}|${m.httpMethod}`)) continue;
7313
+ } else if (declaredMethods.has(`${resourceId}|${m.httpMethod}`)) continue;
7182
7314
  added.push({
7183
7315
  resourceType: "AWS::ApiGateway::Method",
7184
7316
  identifier: `${apiId}|${resourceId}|${m.httpMethod}`,
@@ -7240,11 +7372,12 @@ async function enumerateRestApiChildren(ctx) {
7240
7372
  const name = typeof r.declared.StageName === "string" ? r.declared.StageName : r.physicalId;
7241
7373
  if (name) declaredStageNames.push(name);
7242
7374
  }
7375
+ const specChildren = bodyDefined ? deriveSpecRestApiPaths(parent.declared.Body) : null;
7243
7376
  const client = new APIGatewayClient({
7244
7377
  region,
7245
7378
  ...READ_RETRY
7246
7379
  });
7247
- const items = bodyDefined ? [] : await getAllResources(client, apiId);
7380
+ const items = bodyDefined && !specChildren ? [] : await getAllResources(client, apiId);
7248
7381
  const liveResources = items.filter((i) => typeof i.id === "string").map((i) => ({
7249
7382
  id: i.id,
7250
7383
  path: i.path,
@@ -7272,7 +7405,8 @@ async function enumerateRestApiChildren(ctx) {
7272
7405
  declaredMethodKeys,
7273
7406
  liveResources,
7274
7407
  liveMethodsByResource,
7275
- bodyDefined
7408
+ bodyDefined,
7409
+ specChildren
7276
7410
  });
7277
7411
  const authorizerAdded = diffApiGatewayAuthorizers({
7278
7412
  apiId,
@@ -7490,9 +7624,50 @@ function isBodyDefinedHttpApi(declared) {
7490
7624
  function isQuickCreateHttpApi(declared) {
7491
7625
  return declared.Target != null;
7492
7626
  }
7627
+ function deriveSpecHttpApiRouteKeys(body) {
7628
+ if (typeof body !== "object" || body === null || Array.isArray(body)) return null;
7629
+ const rawPaths = body.paths;
7630
+ if (typeof rawPaths !== "object" || rawPaths === null || Array.isArray(rawPaths)) return null;
7631
+ const keys = /* @__PURE__ */ new Set();
7632
+ for (const [rawKey, ops] of Object.entries(rawPaths)) {
7633
+ if (rawKey === "$default") {
7634
+ keys.add("$default");
7635
+ continue;
7636
+ }
7637
+ const norm = normalizeApiPath(rawKey);
7638
+ if (typeof ops === "object" && ops !== null && !Array.isArray(ops)) for (const opKey of Object.keys(ops)) {
7639
+ const lower = opKey.toLowerCase();
7640
+ if (OPENAPI_HTTP_VERBS.has(lower)) keys.add(`${lower.toUpperCase()} ${norm}`);
7641
+ else if (lower === "x-amazon-apigateway-any-method") keys.add(`ANY ${norm}`);
7642
+ }
7643
+ }
7644
+ return keys;
7645
+ }
7493
7646
  function diffApiGatewayV2Children(input) {
7494
- const { apiId, declaredRouteIds, declaredIntegrationIds, liveRoutes, liveIntegrations, specMaterialized } = input;
7495
- if (specMaterialized) return [];
7647
+ const { apiId, declaredRouteIds, declaredIntegrationIds, liveRoutes, liveIntegrations, specMaterialized, specRouteKeys, quickCreate } = input;
7648
+ if (specMaterialized) {
7649
+ if (!quickCreate && !specRouteKeys) return [];
7650
+ const added = [];
7651
+ for (const r of liveRoutes) {
7652
+ if (quickCreate) {
7653
+ if (r.key === "$default") continue;
7654
+ } else {
7655
+ const key = r.key != null ? normalizeV2RouteKey(r.key) : void 0;
7656
+ if (key != null && specRouteKeys?.has(key)) continue;
7657
+ if (key == null) continue;
7658
+ }
7659
+ added.push({
7660
+ resourceType: "AWS::ApiGatewayV2::Route",
7661
+ identifier: `${apiId}|${r.id}`,
7662
+ label: r.key ?? r.id,
7663
+ live: {
7664
+ RouteId: r.id,
7665
+ RouteKey: r.key
7666
+ }
7667
+ });
7668
+ }
7669
+ return added;
7670
+ }
7496
7671
  const declaredRoutes = new Set(declaredRouteIds);
7497
7672
  const declaredIntegrations = new Set(declaredIntegrationIds);
7498
7673
  const added = [];
@@ -7519,6 +7694,12 @@ function diffApiGatewayV2Children(input) {
7519
7694
  }
7520
7695
  return added;
7521
7696
  }
7697
+ function normalizeV2RouteKey(key) {
7698
+ if (key === "$default") return "$default";
7699
+ const sp = key.indexOf(" ");
7700
+ if (sp < 0) return key;
7701
+ return `${key.slice(0, sp).toUpperCase()} ${normalizeApiPath(key.slice(sp + 1).trim())}`;
7702
+ }
7522
7703
  function integrationLabel(i) {
7523
7704
  if (!i.IntegrationType) return void 0;
7524
7705
  return i.IntegrationUri ? `${i.IntegrationType} ${i.IntegrationUri}` : i.IntegrationType;
@@ -7620,6 +7801,8 @@ async function enumerateHttpApiChildren(ctx) {
7620
7801
  const bodyDefined = isBodyDefinedHttpApi(parent.declared);
7621
7802
  const quickCreate = isQuickCreateHttpApi(parent.declared);
7622
7803
  const specMaterialized = bodyDefined || quickCreate;
7804
+ const specRouteKeys = bodyDefined ? deriveSpecHttpApiRouteKeys(parent.declared.Body) : null;
7805
+ const skipRoutesSweep = bodyDefined && !quickCreate && !specRouteKeys;
7623
7806
  const declaredRouteIds = [];
7624
7807
  const declaredIntegrationIds = [];
7625
7808
  const declaredAuthorizerIds = [];
@@ -7639,7 +7822,7 @@ async function enumerateHttpApiChildren(ctx) {
7639
7822
  ...READ_RETRY
7640
7823
  });
7641
7824
  const [routes, integrations, authorizers, stages] = await Promise.all([
7642
- pageRoutes(client, apiId),
7825
+ skipRoutesSweep ? Promise.resolve([]) : pageRoutes(client, apiId),
7643
7826
  pageIntegrations(client, apiId),
7644
7827
  pageV2Authorizers(client, apiId),
7645
7828
  pageV2Stages(client, apiId)
@@ -7663,7 +7846,9 @@ async function enumerateHttpApiChildren(ctx) {
7663
7846
  declaredIntegrationIds,
7664
7847
  liveRoutes,
7665
7848
  liveIntegrations,
7666
- specMaterialized
7849
+ specMaterialized,
7850
+ specRouteKeys,
7851
+ quickCreate
7667
7852
  });
7668
7853
  const authorizerAdded = diffApiGatewayV2Authorizers({
7669
7854
  apiId,
@@ -8113,7 +8298,11 @@ async function openSearchDomainTargetsPool(region, userPoolId) {
8113
8298
  });
8114
8299
  const domainNames = ((await os.send(new ListDomainNamesCommand({}))).DomainNames ?? []).map((d) => d.DomainName).filter((n) => typeof n === "string");
8115
8300
  if (domainNames.length === 0) return false;
8116
- return ((await os.send(new DescribeDomainsCommand({ DomainNames: domainNames }))).DomainStatusList ?? []).some((d) => d.CognitoOptions?.Enabled === true && d.CognitoOptions.UserPoolId === userPoolId);
8301
+ for (let i = 0; i < domainNames.length; i += 5) {
8302
+ const batch = domainNames.slice(i, i + 5);
8303
+ if (((await os.send(new DescribeDomainsCommand({ DomainNames: batch }))).DomainStatusList ?? []).some((d) => d.CognitoOptions?.Enabled === true && d.CognitoOptions.UserPoolId === userPoolId)) return true;
8304
+ }
8305
+ return false;
8117
8306
  } catch {
8118
8307
  return true;
8119
8308
  }
@@ -12299,22 +12488,33 @@ function buildSiblingEventBusPolicies(desired) {
12299
12488
  return map;
12300
12489
  }
12301
12490
  const S3_NOTIFICATIONS_CR_TYPE = "Custom::S3BucketNotifications";
12302
- function buildBucketNotificationManaged(desired) {
12491
+ function resolveBucketNotificationCrs(desired) {
12303
12492
  const byLogicalId = /* @__PURE__ */ new Map();
12304
12493
  for (const r of desired.resources) if (r.physicalId) byLogicalId.set(r.logicalId, r.physicalId);
12305
- const managed = /* @__PURE__ */ new Set();
12494
+ const out = [];
12306
12495
  for (const r of desired.resources) {
12307
12496
  if (r.resourceType !== S3_NOTIFICATIONS_CR_TYPE) continue;
12308
12497
  const decl = r.declared;
12309
12498
  if (!decl || typeof decl !== "object") continue;
12310
- const bucketName = decl.BucketName;
12311
- if (typeof bucketName === "string" && bucketName) managed.add(bucketName);
12499
+ const d = decl;
12500
+ const bucketName = d.BucketName;
12501
+ const rawConfig = d.NotificationConfiguration;
12502
+ const config = rawConfig && typeof rawConfig === "object" && !Array.isArray(rawConfig) ? rawConfig : {};
12503
+ if (typeof bucketName === "string" && bucketName) out.push([bucketName, config]);
12312
12504
  else if (bucketName && typeof bucketName === "object" && "Ref" in bucketName) {
12313
12505
  const phys = byLogicalId.get(bucketName.Ref);
12314
- if (phys) managed.add(phys);
12506
+ if (phys) out.push([phys, config]);
12315
12507
  }
12316
12508
  }
12317
- return managed;
12509
+ return out;
12510
+ }
12511
+ function buildBucketNotificationManaged(desired) {
12512
+ return new Set(resolveBucketNotificationCrs(desired).map(([phys]) => phys));
12513
+ }
12514
+ function buildBucketNotificationConfigs(desired) {
12515
+ const out = {};
12516
+ for (const [phys, config] of resolveBucketNotificationCrs(desired)) out[phys] = config;
12517
+ return out;
12318
12518
  }
12319
12519
  const MANAGED_POLICY_TYPE = "AWS::IAM::ManagedPolicy";
12320
12520
  const MANAGED_POLICY_ATTACH_SIDES = [
@@ -12710,6 +12910,7 @@ async function gatherFindings(stackName, region, templateOverride, recoveryTempl
12710
12910
  siblingEipAssociations: buildSiblingEipAssociations(desired),
12711
12911
  siblingTargetGroupRegistrars: buildSiblingTargetGroupRegistrars(desired),
12712
12912
  bucketNotificationManaged: buildBucketNotificationManaged(desired),
12913
+ bucketNotificationConfigs: buildBucketNotificationConfigs(desired),
12713
12914
  clusterEchoModel: buildClusterEchoModels(desired),
12714
12915
  rdsOptionSettingDefaults: await buildRdsOptionSettingDefaults(desired, region)
12715
12916
  };
@@ -12780,6 +12981,7 @@ async function regatherTouched(gathered, touched, region) {
12780
12981
  siblingEipAssociations: buildSiblingEipAssociations(desired),
12781
12982
  siblingTargetGroupRegistrars: buildSiblingTargetGroupRegistrars(desired),
12782
12983
  bucketNotificationManaged: buildBucketNotificationManaged(desired),
12984
+ bucketNotificationConfigs: buildBucketNotificationConfigs(desired),
12783
12985
  clusterEchoModel: buildClusterEchoModels(desired),
12784
12986
  rdsOptionSettingDefaults: await buildRdsOptionSettingDefaults(desired, region)
12785
12987
  };
@@ -16369,7 +16571,7 @@ function isUnderCreateOnly(findingPath, createOnlyPaths) {
16369
16571
  }
16370
16572
  return false;
16371
16573
  }
16372
- const CC_DELETE_UNSUPPORTED_ADDED_TYPES = new Set(["AWS::EC2::NetworkAclEntry"]);
16574
+ const CC_DELETE_UNSUPPORTED_ADDED_TYPES = new Set(["AWS::EC2::NetworkAclEntry", "AWS::Route53::RecordSet"]);
16373
16575
  function buildRevertPlan(findings, baseline, opts = {}) {
16374
16576
  const itemsByLogical = /* @__PURE__ */ new Map();
16375
16577
  const notRevertable = [];