cdk-real-drift 0.9.5 → 0.9.7

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
@@ -2985,12 +2985,18 @@ const VALUE_INDEPENDENT_DEFAULT_TOPLEVEL_PATHS = {
2985
2985
  "AWS::Glue::Job": new Set(["MaxCapacity", "AllocatedCapacity"]),
2986
2986
  "AWS::EC2::SecurityGroupIngress": new Set(["SourceSecurityGroupName"]),
2987
2987
  "AWS::EC2::SecurityGroupEgress": new Set(["DestinationSecurityGroupName"]),
2988
- "AWS::DocDB::DBCluster": new Set(["PreferredMaintenanceWindow", "PreferredBackupWindow"]),
2988
+ "AWS::DocDB::DBCluster": new Set([
2989
+ "PreferredMaintenanceWindow",
2990
+ "PreferredBackupWindow",
2991
+ "EngineVersion",
2992
+ "KmsKeyId"
2993
+ ]),
2989
2994
  "AWS::DocDB::DBInstance": new Set(["PreferredMaintenanceWindow"]),
2990
2995
  "AWS::Neptune::DBCluster": new Set([
2991
2996
  "PreferredMaintenanceWindow",
2992
2997
  "PreferredBackupWindow",
2993
- "EngineVersion"
2998
+ "EngineVersion",
2999
+ "AvailabilityZones"
2994
3000
  ]),
2995
3001
  "AWS::Neptune::DBInstance": new Set(["PreferredMaintenanceWindow", "AvailabilityZone"]),
2996
3002
  "AWS::ElastiCache::CacheCluster": new Set([
@@ -3036,6 +3042,7 @@ const VALUE_INDEPENDENT_DEFAULT_TOPLEVEL_PATHS = {
3036
3042
  "AWS::EC2::VPCEndpoint": new Set(["ServiceRegion", "DnsOptions"]),
3037
3043
  "AWS::EC2::VPCPeeringConnection": new Set(["PeerRegion"]),
3038
3044
  "AWS::EC2::VPCCidrBlock": new Set(["Ipv6CidrBlock", "Ipv6CidrBlockNetworkBorderGroup"]),
3045
+ "AWS::EC2::TransitGateway": new Set(["AssociationDefaultRouteTableId", "PropagationDefaultRouteTableId"]),
3039
3046
  "AWS::Grafana::Workspace": new Set(["GrafanaVersion"]),
3040
3047
  "AWS::Bedrock::AgentAlias": new Set(["RoutingConfiguration"]),
3041
3048
  "AWS::AppSync::ApiKey": new Set(["Expires"]),
@@ -3593,6 +3600,7 @@ function alignNameValueSubset(declared, live, spec) {
3593
3600
  }
3594
3601
  const UNORDERED_ARRAY_PROPS = {
3595
3602
  "AWS::CloudFront::Distribution": new Set(["DistributionConfig.Restrictions.GeoRestriction.Locations"]),
3603
+ "AWS::Cognito::UserPool": new Set(["EnabledMfas"]),
3596
3604
  "AWS::Cognito::UserPoolClient": new Set([
3597
3605
  "AllowedOAuthFlows",
3598
3606
  "AllowedOAuthScopes",
@@ -6548,8 +6556,15 @@ async function getAllGatewayResponses(client, apiId) {
6548
6556
  } while (position);
6549
6557
  return out;
6550
6558
  }
6559
+ function isBodyDefinedHttpApi(declared) {
6560
+ return declared.Body != null || declared.BodyS3Location != null;
6561
+ }
6562
+ function isQuickCreateHttpApi(declared) {
6563
+ return declared.Target != null;
6564
+ }
6551
6565
  function diffApiGatewayV2Children(input) {
6552
- const { apiId, declaredRouteIds, declaredIntegrationIds, liveRoutes, liveIntegrations } = input;
6566
+ const { apiId, declaredRouteIds, declaredIntegrationIds, liveRoutes, liveIntegrations, specMaterialized } = input;
6567
+ if (specMaterialized) return [];
6553
6568
  const declaredRoutes = new Set(declaredRouteIds);
6554
6569
  const declaredIntegrations = new Set(declaredIntegrationIds);
6555
6570
  const added = [];
@@ -6607,7 +6622,8 @@ async function pageIntegrations(client, apiId) {
6607
6622
  return out;
6608
6623
  }
6609
6624
  function diffApiGatewayV2Authorizers(input) {
6610
- const { apiId, declaredAuthorizerIds, liveAuthorizers } = input;
6625
+ const { apiId, declaredAuthorizerIds, liveAuthorizers, bodyDefined } = input;
6626
+ if (bodyDefined) return [];
6611
6627
  const declared = new Set(declaredAuthorizerIds);
6612
6628
  const added = [];
6613
6629
  for (const a of liveAuthorizers) {
@@ -6638,11 +6654,12 @@ async function pageV2Authorizers(client, apiId) {
6638
6654
  return out;
6639
6655
  }
6640
6656
  function diffApiGatewayV2Stages(input) {
6641
- const { apiId, declaredStageNames, liveStages } = input;
6657
+ const { apiId, declaredStageNames, liveStages, quickCreate } = input;
6642
6658
  const declared = new Set(declaredStageNames);
6643
6659
  const added = [];
6644
6660
  for (const s of liveStages) {
6645
6661
  if (declared.has(s.name)) continue;
6662
+ if (quickCreate && s.name === "$default") continue;
6646
6663
  added.push({
6647
6664
  resourceType: "AWS::ApiGatewayV2::Stage",
6648
6665
  identifier: `${apiId}|${s.name}`,
@@ -6672,6 +6689,9 @@ async function enumerateHttpApiChildren(ctx) {
6672
6689
  const { parent, desired, region } = ctx;
6673
6690
  const apiId = parent.physicalId;
6674
6691
  if (!apiId) return [];
6692
+ const bodyDefined = isBodyDefinedHttpApi(parent.declared);
6693
+ const quickCreate = isQuickCreateHttpApi(parent.declared);
6694
+ const specMaterialized = bodyDefined || quickCreate;
6675
6695
  const declaredRouteIds = [];
6676
6696
  const declaredIntegrationIds = [];
6677
6697
  const declaredAuthorizerIds = [];
@@ -6714,17 +6734,20 @@ async function enumerateHttpApiChildren(ctx) {
6714
6734
  declaredRouteIds,
6715
6735
  declaredIntegrationIds,
6716
6736
  liveRoutes,
6717
- liveIntegrations
6737
+ liveIntegrations,
6738
+ specMaterialized
6718
6739
  });
6719
6740
  const authorizerAdded = diffApiGatewayV2Authorizers({
6720
6741
  apiId,
6721
6742
  declaredAuthorizerIds,
6722
- liveAuthorizers
6743
+ liveAuthorizers,
6744
+ bodyDefined
6723
6745
  });
6724
6746
  const stageAdded = diffApiGatewayV2Stages({
6725
6747
  apiId,
6726
6748
  declaredStageNames,
6727
- liveStages
6749
+ liveStages,
6750
+ quickCreate
6728
6751
  });
6729
6752
  return added.concat(authorizerAdded, stageAdded);
6730
6753
  }
@@ -6958,6 +6981,7 @@ function diffEventBusChildren(input) {
6958
6981
  const added = [];
6959
6982
  for (const r of input.liveRules) {
6960
6983
  if (declared.has(r.name)) continue;
6984
+ const siblingLookupId = input.isDefaultBus ? r.name : `${input.busName}|${r.name}`;
6961
6985
  added.push({
6962
6986
  resourceType: "AWS::Events::Rule",
6963
6987
  identifier: r.arn,
@@ -6965,7 +6989,8 @@ function diffEventBusChildren(input) {
6965
6989
  live: {
6966
6990
  Name: r.name,
6967
6991
  Arn: r.arn
6968
- }
6992
+ },
6993
+ siblingLookupId
6969
6994
  });
6970
6995
  }
6971
6996
  return added;
@@ -6997,16 +7022,19 @@ async function enumerateEventBusChildren(ctx) {
6997
7022
  const raw = r.physicalId ?? (typeof r.declared.Name === "string" ? r.declared.Name : void 0);
6998
7023
  if (raw) declaredRuleNames.push(raw.includes("|") ? raw.slice(raw.lastIndexOf("|") + 1) : raw);
6999
7024
  }
7025
+ const liveRules = (await pageRules(new EventBridgeClient({
7026
+ region,
7027
+ ...READ_RETRY
7028
+ }), busName)).filter((r) => typeof r.Name === "string" && typeof r.Arn === "string" && !r.ManagedBy).map((r) => ({
7029
+ name: r.Name,
7030
+ arn: r.Arn,
7031
+ label: r.Name
7032
+ }));
7000
7033
  return diffEventBusChildren({
7034
+ busName,
7035
+ isDefaultBus: busName === "default",
7001
7036
  declaredRuleNames,
7002
- liveRules: (await pageRules(new EventBridgeClient({
7003
- region,
7004
- ...READ_RETRY
7005
- }), busName)).filter((r) => typeof r.Name === "string" && typeof r.Arn === "string" && !r.ManagedBy).map((r) => ({
7006
- name: r.Name,
7007
- arn: r.Arn,
7008
- label: r.Name
7009
- }))
7037
+ liveRules
7010
7038
  });
7011
7039
  }
7012
7040
  function diffUserPoolChildren(input) {
@@ -10411,9 +10439,18 @@ async function readAddedModel(cc, cfn, c, schemas, oaiCanonicalIds) {
10411
10439
  };
10412
10440
  }
10413
10441
  }
10414
- async function isManagedBySiblingStack(cfn, c, cache) {
10415
- const physicalId = c.identifier;
10416
- if (physicalId.includes("|")) return "notManaged";
10442
+ function isDefinitiveNotManaged(physicalId, accountId, region) {
10443
+ if (!physicalId.startsWith("arn:")) return true;
10444
+ const seg = physicalId.split(":");
10445
+ const arnRegion = seg[3] ?? "";
10446
+ const arnAccount = seg[4] ?? "";
10447
+ if (arnRegion !== "" && arnRegion !== region) return false;
10448
+ if (arnAccount !== "" && arnAccount !== accountId) return false;
10449
+ return true;
10450
+ }
10451
+ async function isManagedBySiblingStack(cfn, c, cache, accountId, region) {
10452
+ const physicalId = c.siblingLookupId ?? c.identifier;
10453
+ if (c.siblingLookupId === void 0 && physicalId.includes("|")) return "notManaged";
10417
10454
  const cached = cache.get(physicalId);
10418
10455
  if (cached !== void 0) return cached;
10419
10456
  let managed = false;
@@ -10440,7 +10477,7 @@ async function isManagedBySiblingStack(cfn, c, cache) {
10440
10477
  }
10441
10478
  }
10442
10479
  } catch (e) {
10443
- if (e.name === "ValidationError") {
10480
+ if (e.name === "ValidationError" && isDefinitiveNotManaged(physicalId, accountId, region)) {
10444
10481
  cache.set(physicalId, "notManaged");
10445
10482
  return "notManaged";
10446
10483
  }
@@ -10731,7 +10768,7 @@ async function gatherFindings(stackName, region, templateOverride, recoveryTempl
10731
10768
  region
10732
10769
  });
10733
10770
  for (const c of children) {
10734
- const sibling = await isManagedBySiblingStack(cfn, c, siblingStackCache);
10771
+ const sibling = await isManagedBySiblingStack(cfn, c, siblingStackCache, desired.accountId, region);
10735
10772
  if (sibling === "managed") continue;
10736
10773
  if (sibling === "unverified") {
10737
10774
  findings.push({
@@ -14392,6 +14429,7 @@ async function applyRevertDelete(cc, item, identifier = item.physicalId, retry =
14392
14429
  const isDrift = (f) => (f.tier === "deleted" || f.tier === "added" || f.tier === "declared" || f.tier === "undeclared") && !f.unrecorded;
14393
14430
  const driftCount = (findings) => findings.filter(isDrift).length;
14394
14431
  const unrecordedCount = (findings) => findings.filter((f) => f.unrecorded === true).length;
14432
+ const findingKeyOf = (f) => `${f.logicalId}::${f.path}${f.attributeKey !== void 0 ? `[${f.attributeKey}]` : ""}`;
14395
14433
  const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
14396
14434
  /**
14397
14435
  * The per-stack label shown in a DECISION prompt — the SAME `Name (region)` form the
@@ -14976,7 +15014,7 @@ function augmentRevertPlan(plan, schemas, liveByLogical, declaredByLogical) {
14976
15014
  };
14977
15015
  }
14978
15016
  async function revertStack(p) {
14979
- const { stackName, region, gathered, baseline, config, dryRun, yes, removeUnrecorded, verbose, interactive, autoSelectAll, waitMs, waitNow, waitSleep } = p;
15017
+ const { stackName, region, gathered, baseline, config, dryRun, yes, removeUnrecorded, verbose, interactive, autoSelectAll, selectedFindingKeys, waitMs, waitNow, waitSleep } = p;
14980
15018
  const out = p.json ? () => {} : console.log;
14981
15019
  let worst = 0;
14982
15020
  const includeRemovals = includeUnrecordedRemovals(removeUnrecorded, interactive, yes);
@@ -14986,7 +15024,7 @@ async function revertStack(p) {
14986
15024
  constructPathByLogical: constructPathsByLogical(gathered.desired.resources),
14987
15025
  allLogicalIds: gathered.desired.resources.map((r) => r.logicalId)
14988
15026
  };
14989
- const drifted = applyIgnores(applyBaseline(gathered.findings, baseline, {
15027
+ const reconciled = applyIgnores(applyBaseline(gathered.findings, baseline, {
14990
15028
  ...baselineOpts,
14991
15029
  warn: console.error
14992
15030
  }), {
@@ -14994,6 +15032,7 @@ async function revertStack(p) {
14994
15032
  accountId: gathered.desired.accountId,
14995
15033
  region
14996
15034
  }, config);
15035
+ const drifted = selectedFindingKeys === void 0 ? reconciled : reconciled.filter((f) => selectedFindingKeys.has(findingKeyOf(f)));
14997
15036
  const resByLogical = new Map(gathered.desired.resources.map((res) => [res.logicalId, res]));
14998
15037
  const declaredForLogical = (logicalId) => resByLogical.get(logicalId)?.declared;
14999
15038
  const augment = (pl) => augmentRevertPlan(pl, gathered.schemas, gathered.liveByLogical, declaredForLogical);
@@ -16310,11 +16349,12 @@ async function perFinding(p, decidable) {
16310
16349
  region: p.region,
16311
16350
  gathered: {
16312
16351
  desired: p.desired,
16313
- findings: p.findings.filter((f) => revertKeys.has(keyOf(f))),
16352
+ findings: p.findings,
16314
16353
  schemas: p.schemas,
16315
16354
  liveByLogical: p.liveByLogical
16316
16355
  },
16317
16356
  baseline: p.baseline,
16357
+ selectedFindingKeys: revertKeys,
16318
16358
  config: p.config,
16319
16359
  dryRun: false,
16320
16360
  yes: false,