cdk-real-drift 0.25.3 → 0.25.5

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/README.md CHANGED
@@ -694,7 +694,8 @@ The table of every drift kind and its section label is up in
694
694
  in full as _potential_ (unconfirmed) drift and don't drive the `--fail` exit;
695
695
  `result:` points you at `cdkrd record` to accept them (or `revert` to remove).
696
696
  Once a resource is fully snapshotted, a value that _appears_ later is real drift
697
- (`appeared since record`).
697
+ (`appeared since record`) — and the same applies to a whole out-of-band-created
698
+ child resource once its parent's child inventory is recorded.
698
699
  - **`↳` origin hint**: when a finding's live value has a recognizable external
699
700
  source — e.g. the CloudWatch Application Signals / Lambda Insights
700
701
  auto-instrumentation footprint (an added Insights layer + tracer execution
package/dist/cli.js CHANGED
@@ -1982,7 +1982,8 @@ function buildCorpusCase(resource, liveRaw, schema, opts, findings) {
1982
1982
  } } : {},
1983
1983
  ...cvpnVpcKey !== void 0 && cvpnVpcMap !== void 0 ? { siblingClientVpnEndpointVpcs: { [cvpnVpcKey]: cvpnVpcMap[cvpnVpcKey] ?? null } } : {},
1984
1984
  ...cfCdKey !== void 0 && cfCdMap !== void 0 ? { siblingCloudFrontCdPolicyIds: { [cfCdKey]: cfCdMap[cfCdKey] ?? null } } : {},
1985
- ...rdsSrcKey !== void 0 && rdsSrcMap !== void 0 && rdsSrcMap[rdsSrcKey] ? { siblingRdsSourceModels: { [rdsSrcKey]: rdsSrcMap[rdsSrcKey] } } : {}
1985
+ ...rdsSrcKey !== void 0 && rdsSrcMap !== void 0 && rdsSrcMap[rdsSrcKey] ? { siblingRdsSourceModels: { [rdsSrcKey]: rdsSrcMap[rdsSrcKey] } } : {},
1986
+ ...resource.resourceType === "AWS::ElasticBeanstalk::Environment" && opts.ebSgNamesById && Object.keys(opts.ebSgNamesById).length > 0 ? { ebSgNamesById: opts.ebSgNamesById } : {}
1986
1987
  },
1987
1988
  expected: findings
1988
1989
  }, opts.accountId);
@@ -3632,15 +3633,20 @@ const EB_OPTION_VALUE_INDEPENDENT = new Set([
3632
3633
  "aws:elasticbeanstalk:healthreporting:system|ConfigDocument",
3633
3634
  "aws:elasticbeanstalk:healthreporting:system|EnhancedHealthAuthEnabled"
3634
3635
  ]);
3635
- function isEbGeneratedGroup(el) {
3636
- const name = el.trim();
3636
+ function isEbGeneratedGroup(el, sgNamesById) {
3637
+ let name = el.trim();
3637
3638
  if (name === "") return false;
3639
+ if (/^sg-[0-9a-f]+$/i.test(name)) {
3640
+ const resolved = sgNamesById?.[name];
3641
+ if (resolved === void 0) return false;
3642
+ name = resolved;
3643
+ }
3638
3644
  if (/^awseb-e-/i.test(name)) return true;
3639
3645
  return /AWSEB(LoadBalancer)?SecurityGroup/.test(name);
3640
3646
  }
3641
- function isAllEbGeneratedGroups(value) {
3647
+ function isAllEbGeneratedGroups(value, sgNamesById) {
3642
3648
  if (typeof value !== "string" || value === "") return false;
3643
- return value.split(",").every((el) => isEbGeneratedGroup(el));
3649
+ return value.split(",").every((el) => isEbGeneratedGroup(el, sgNamesById));
3644
3650
  }
3645
3651
  const EB_INSTANCE_TYPES_DEFAULT_BY_ARCH = {
3646
3652
  x86_64: new Set(["t3.micro", "t3.small"]),
@@ -3654,10 +3660,10 @@ function ebInstanceTypesDefaultSet(supportedArchitectures) {
3654
3660
  const arch = typeof supportedArchitectures === "string" && supportedArchitectures.trim() !== "" ? supportedArchitectures.split(",")[0]?.trim() : "x86_64";
3655
3661
  return arch === void 0 ? EB_INSTANCE_TYPES_DEFAULT_BY_ARCH.x86_64 : EB_INSTANCE_TYPES_DEFAULT_BY_ARCH[arch];
3656
3662
  }
3657
- function ebOptionSettingTier(namespace, optionName, value, envType, siblingOption) {
3663
+ function ebOptionSettingTier(namespace, optionName, value, envType, siblingOption, sgNamesById) {
3658
3664
  if (value == null || value === "") return "atDefault";
3659
3665
  const key = `${String(namespace)}|${String(optionName)}`;
3660
- if (key === "aws:autoscaling:launchconfiguration|SecurityGroups" || key === "aws:elb:loadbalancer|SecurityGroups") return isAllEbGeneratedGroups(value) ? "atDefault" : "undeclared";
3666
+ if (key === "aws:autoscaling:launchconfiguration|SecurityGroups" || key === "aws:elb:loadbalancer|SecurityGroups") return isAllEbGeneratedGroups(value, sgNamesById) ? "atDefault" : "undeclared";
3661
3667
  if (key === "aws:autoscaling:launchconfiguration|InstanceType") {
3662
3668
  const instanceTypes = siblingOption?.("aws:ec2:instances", "InstanceTypes");
3663
3669
  const first = typeof instanceTypes === "string" ? instanceTypes.split(",")[0]?.trim() : void 0;
@@ -4075,12 +4081,14 @@ const CASE_INSENSITIVE_PATHS = {
4075
4081
  "DBParameterGroupName",
4076
4082
  "DBSubnetGroupName",
4077
4083
  "OptionGroupName",
4078
- "DBClusterIdentifier"
4084
+ "DBClusterIdentifier",
4085
+ "Engine"
4079
4086
  ]),
4080
4087
  "AWS::RDS::DBCluster": new Set([
4081
4088
  "DBClusterIdentifier",
4082
4089
  "DBClusterParameterGroupName",
4083
- "DBSubnetGroupName"
4090
+ "DBSubnetGroupName",
4091
+ "Engine"
4084
4092
  ]),
4085
4093
  "AWS::ElastiCache::SubnetGroup": new Set(["CacheSubnetGroupName"]),
4086
4094
  "AWS::ElastiCache::ReplicationGroup": new Set([
@@ -4114,9 +4122,9 @@ const CASE_INSENSITIVE_PATHS = {
4114
4122
  "DBSubnetGroupName"
4115
4123
  ]),
4116
4124
  "AWS::Neptune::DBSubnetGroup": new Set(["DBSubnetGroupName"]),
4117
- "AWS::RDS::DBParameterGroup": new Set(["DBParameterGroupName"]),
4118
- "AWS::RDS::DBClusterParameterGroup": new Set(["DBClusterParameterGroupName"]),
4119
- "AWS::RDS::OptionGroup": new Set(["OptionGroupName"]),
4125
+ "AWS::RDS::DBParameterGroup": new Set(["DBParameterGroupName", "Family"]),
4126
+ "AWS::RDS::DBClusterParameterGroup": new Set(["DBClusterParameterGroupName", "Family"]),
4127
+ "AWS::RDS::OptionGroup": new Set(["OptionGroupName", "EngineName"]),
4120
4128
  "AWS::RDS::DBSubnetGroup": new Set(["DBSubnetGroupName"]),
4121
4129
  "AWS::Neptune::DBParameterGroup": new Set(["Name"]),
4122
4130
  "AWS::Neptune::DBClusterParameterGroup": new Set(["Name"]),
@@ -5557,6 +5565,30 @@ function logsDeliveryDerivedRetention(logGroupClass) {
5557
5565
  function rdsReplicaDerivedBackupRetention(sourceDbInstanceIdentifier) {
5558
5566
  return sourceDbInstanceIdentifier !== void 0 ? 0 : void 0;
5559
5567
  }
5568
+ function ecsDaemonDerivedMaximumPercent(schedulingStrategy) {
5569
+ return schedulingStrategy === "DAEMON" ? 100 : void 0;
5570
+ }
5571
+ function ecsDaemonDerivedMinimumHealthyPercent(schedulingStrategy) {
5572
+ return schedulingStrategy === "DAEMON" ? 0 : void 0;
5573
+ }
5574
+ function ecsDaemonDerivedDeploymentConfiguration(schedulingStrategy) {
5575
+ if (schedulingStrategy !== "DAEMON") return void 0;
5576
+ return {
5577
+ BakeTimeInMinutes: 0,
5578
+ Strategy: "ROLLING",
5579
+ DeploymentCircuitBreaker: {
5580
+ ThresholdConfiguration: {
5581
+ Type: "BOUNDED_PERCENT",
5582
+ Value: 50
5583
+ },
5584
+ Enable: false,
5585
+ ResetOnHealthyTask: true,
5586
+ Rollback: false
5587
+ },
5588
+ MaximumPercent: 100,
5589
+ MinimumHealthyPercent: 0
5590
+ };
5591
+ }
5560
5592
 
5561
5593
  //#endregion
5562
5594
  //#region src/read/kms-aliases.ts
@@ -6449,12 +6481,12 @@ const IAM_ATTACHMENT_SUBSET = { "AWS::IAM::ManagedPolicy": new Set([
6449
6481
  "Users",
6450
6482
  "Groups"
6451
6483
  ]) };
6452
- const ebOptionSettingsEntryTier = (entry, liveArray) => {
6484
+ const ebOptionSettingsEntryTier = (entry, liveArray, ebSgNamesById) => {
6453
6485
  const arr = Array.isArray(liveArray) ? liveArray : [];
6454
6486
  const envEntry = arr.find((e) => e && e.OptionName === "EnvironmentType");
6455
6487
  const envType = typeof envEntry?.Value === "string" ? envEntry.Value : "LoadBalanced";
6456
6488
  const siblingOption = (ns, opt) => arr.find((e) => e && e.Namespace === ns && e.OptionName === opt)?.Value;
6457
- return ebOptionSettingTier(entry.Namespace, entry.OptionName, entry.Value, envType, siblingOption);
6489
+ return ebOptionSettingTier(entry.Namespace, entry.OptionName, entry.Value, envType, siblingOption, ebSgNamesById);
6458
6490
  };
6459
6491
  const ebOptionSettingsSubsetSpec = {
6460
6492
  re: /(^|\.)OptionSettings$/,
@@ -7362,6 +7394,26 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
7362
7394
  StorageType: storageDefault
7363
7395
  };
7364
7396
  }
7397
+ if (resourceType === "AWS::ECS::Service") {
7398
+ const daemonMax = ecsDaemonDerivedMaximumPercent(declared["SchedulingStrategy"]);
7399
+ const daemonMin = ecsDaemonDerivedMinimumHealthyPercent(declared["SchedulingStrategy"]);
7400
+ if (daemonMax !== void 0 && daemonMin !== void 0) {
7401
+ const dcPin = knownDef["DeploymentConfiguration"];
7402
+ if (dcPin && typeof dcPin === "object") knownDef = {
7403
+ ...knownDef,
7404
+ DeploymentConfiguration: {
7405
+ ...dcPin,
7406
+ MaximumPercent: daemonMax,
7407
+ MinimumHealthyPercent: daemonMin
7408
+ }
7409
+ };
7410
+ knownDefPaths = {
7411
+ ...knownDefPaths,
7412
+ "DeploymentConfiguration.MaximumPercent": daemonMax,
7413
+ "DeploymentConfiguration.MinimumHealthyPercent": daemonMin
7414
+ };
7415
+ }
7416
+ }
7365
7417
  if (resourceType === "AWS::CE::AnomalySubscription") {
7366
7418
  const threshold = declared["Threshold"];
7367
7419
  if (typeof threshold === "number" && Number.isFinite(threshold)) {
@@ -7921,7 +7973,7 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
7921
7973
  const r = lo;
7922
7974
  const key = ckSubsetSpec.keyFields.map((f) => String(r[f])).join("|");
7923
7975
  findings.push({
7924
- tier: ckSubsetSpec.entryTier?.(r, d.awsValue) ?? "undeclared",
7976
+ tier: ckSubsetSpec.entryTier?.(r, d.awsValue, opts.ebSgNamesById) ?? "undeclared",
7925
7977
  logicalId,
7926
7978
  resourceType,
7927
7979
  path: `${d.path}[${key}]`,
@@ -8148,7 +8200,7 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
8148
8200
  continue;
8149
8201
  }
8150
8202
  }
8151
- if (k in schema.defaults && matchesKnownDefault(v, schema.defaults[k]) || k in schema.defaultPaths && matchesKnownDefault(v, schema.defaultPaths[k]) || k in knownDef && matchesKnownDefault(v, knownDef[k]) || KNOWN_DEFAULT_ONE_OF[resourceType]?.[k]?.some((d) => matchesKnownDefault(v, d)) || VALUE_INDEPENDENT_DEFAULT_TOPLEVEL_PATHS[resourceType]?.has(k) && !isTrivialEmpty(v) && !(k in knownDef) || clbDefaultSslPoliciesAtDefault(resourceType, k, v) || vpnTunnelOptionsAtDefault(resourceType, k, v)) {
8203
+ if (k in schema.defaults && matchesKnownDefault(v, schema.defaults[k]) || k in schema.defaultPaths && matchesKnownDefault(v, schema.defaultPaths[k]) || k in knownDef && matchesKnownDefault(v, knownDef[k]) || KNOWN_DEFAULT_ONE_OF[resourceType]?.[k]?.some((d) => matchesKnownDefault(v, d)) || VALUE_INDEPENDENT_DEFAULT_TOPLEVEL_PATHS[resourceType]?.has(k) && !isTrivialEmpty(v) && !(k in knownDef) || resourceType === "AWS::ECS::Service" && k === "DesiredCount" && declared["SchedulingStrategy"] === "DAEMON" || clbDefaultSslPoliciesAtDefault(resourceType, k, v) || vpnTunnelOptionsAtDefault(resourceType, k, v)) {
8152
8204
  findings.push({
8153
8205
  tier: "atDefault",
8154
8206
  logicalId,
@@ -11410,27 +11462,41 @@ function route53ZoneRefMatches(declared, hostedZoneId, zoneApex) {
11410
11462
  if (hzName === UNRESOLVED || hasUnresolved(hzName)) return true;
11411
11463
  return typeof hzName === "string" && zoneApex !== void 0 && canonRoute53Name(hzName) === canonRoute53Name(zoneApex);
11412
11464
  }
11413
- async function enumerateRoute53HostedZoneChildren(ctx) {
11414
- const { parent, desired, region } = ctx;
11415
- const hostedZoneId = parent.physicalId;
11416
- if (!hostedZoneId) return [];
11417
- const zoneApex = typeof parent.declared.Name === "string" ? parent.declared.Name : void 0;
11465
+ function collectDeclaredRoute53Records(resources, hostedZoneId, zoneApex) {
11418
11466
  const declaredRecords = [];
11419
- for (const r of desired.resources) {
11420
- if (r.resourceType !== "AWS::Route53::RecordSet") continue;
11421
- if (!route53ZoneRefMatches(r.declared, hostedZoneId, zoneApex)) continue;
11422
- const name = typeof r.declared.Name === "string" ? r.declared.Name : void 0;
11423
- const type = typeof r.declared.Type === "string" ? r.declared.Type : void 0;
11467
+ const pushDeclared = (rec) => {
11468
+ const name = typeof rec.Name === "string" ? rec.Name : void 0;
11469
+ const type = typeof rec.Type === "string" ? rec.Type : void 0;
11424
11470
  if (name && type) declaredRecords.push({
11425
11471
  name,
11426
11472
  type,
11427
- setIdentifier: typeof r.declared.SetIdentifier === "string" ? r.declared.SetIdentifier : void 0
11473
+ setIdentifier: typeof rec.SetIdentifier === "string" ? rec.SetIdentifier : void 0
11428
11474
  });
11475
+ };
11476
+ for (const r of resources) if (r.resourceType === "AWS::Route53::RecordSet") {
11477
+ if (!route53ZoneRefMatches(r.declared, hostedZoneId, zoneApex)) continue;
11478
+ pushDeclared(r.declared);
11479
+ } else if (r.resourceType === "AWS::Route53::RecordSetGroup") {
11480
+ const groupMatches = route53ZoneRefMatches(r.declared, hostedZoneId, zoneApex);
11481
+ const sets = Array.isArray(r.declared.RecordSets) ? r.declared.RecordSets : [];
11482
+ for (const rs of sets) {
11483
+ if (!rs || typeof rs !== "object") continue;
11484
+ const rec = rs;
11485
+ if (!groupMatches && !route53ZoneRefMatches(rec, hostedZoneId, zoneApex)) continue;
11486
+ pushDeclared(rec);
11487
+ }
11429
11488
  }
11489
+ return declaredRecords;
11490
+ }
11491
+ async function enumerateRoute53HostedZoneChildren(ctx) {
11492
+ const { parent, desired, region } = ctx;
11493
+ const hostedZoneId = parent.physicalId;
11494
+ if (!hostedZoneId) return [];
11495
+ const zoneApex = typeof parent.declared.Name === "string" ? parent.declared.Name : void 0;
11430
11496
  return diffRoute53HostedZoneChildren({
11431
11497
  hostedZoneId,
11432
11498
  zoneApex,
11433
- declaredRecords,
11499
+ declaredRecords: collectDeclaredRoute53Records(desired.resources, hostedZoneId, zoneApex),
11434
11500
  liveRecords: (await pageResourceRecordSets(new Route53Client({
11435
11501
  region,
11436
11502
  ...READ_RETRY
@@ -15056,6 +15122,52 @@ const DEFAULT_SG_LIST_TYPES = new Set([
15056
15122
  "AWS::EC2::VPCEndpoint"
15057
15123
  ]);
15058
15124
  const DEFAULT_SUBNET_LIST_TYPES = new Set(["AWS::RedshiftServerless::Workgroup"]);
15125
+ const EB_SG_OPTION_KEYS = new Set(["aws:elb:loadbalancer|SecurityGroups", "aws:autoscaling:launchconfiguration|SecurityGroups"]);
15126
+ function collectEbSecurityGroupIds(resources, liveById) {
15127
+ const ids = /* @__PURE__ */ new Set();
15128
+ for (const r of resources) {
15129
+ if (r.resourceType !== "AWS::ElasticBeanstalk::Environment") continue;
15130
+ const live = liveById.get(r.logicalId);
15131
+ if (!live) continue;
15132
+ const settings = live.OptionSettings;
15133
+ if (!Array.isArray(settings)) continue;
15134
+ for (const s of settings) {
15135
+ if (!s || typeof s !== "object") continue;
15136
+ const e = s;
15137
+ if (!EB_SG_OPTION_KEYS.has(`${String(e.Namespace)}|${String(e.OptionName)}`)) continue;
15138
+ if (typeof e.Value !== "string") continue;
15139
+ for (const el of e.Value.split(",")) {
15140
+ const t = el.trim();
15141
+ if (/^sg-[0-9a-f]+$/i.test(t)) ids.add(t);
15142
+ }
15143
+ }
15144
+ }
15145
+ return [...ids];
15146
+ }
15147
+ async function fetchSgNamesByIds(region, ids) {
15148
+ try {
15149
+ const c = new EC2Client({
15150
+ region,
15151
+ ...READ_RETRY
15152
+ });
15153
+ const out = {};
15154
+ let token;
15155
+ do {
15156
+ const r = await c.send(new DescribeSecurityGroupsCommand({
15157
+ Filters: [{
15158
+ Name: "group-id",
15159
+ Values: [...ids]
15160
+ }],
15161
+ NextToken: token
15162
+ }));
15163
+ for (const g of r.SecurityGroups ?? []) if (g.GroupId && g.GroupName) out[g.GroupId] = g.GroupName;
15164
+ token = r.NextToken;
15165
+ } while (token);
15166
+ return out;
15167
+ } catch {
15168
+ return;
15169
+ }
15170
+ }
15059
15171
  const defaultSgIdsCache = /* @__PURE__ */ new Map();
15060
15172
  async function fetchDefaultSgIds(region) {
15061
15173
  const cached = defaultSgIdsCache.get(region);
@@ -15253,6 +15365,8 @@ function addedFinding(parent, c, read) {
15253
15365
  physicalId: c.identifier,
15254
15366
  constructPath: `${parent.constructPath ?? parent.logicalId} ▸ ${c.label}`,
15255
15367
  resourceType: c.resourceType,
15368
+ parentLogicalId: parent.logicalId,
15369
+ parentResourceType: parent.resourceType,
15256
15370
  path: "",
15257
15371
  actual: read.model,
15258
15372
  note: read.ok ? "created out of band — not in your CloudFormation template" : "created out of band — not in your CloudFormation template; live model unreadable this run",
@@ -16084,6 +16198,7 @@ async function gatherFindings(stackName, region, templateOverride, recoveryTempl
16084
16198
  const oaiCanonicalIds = buildOaiCanonicalIds(desired);
16085
16199
  const siblingStackCache = /* @__PURE__ */ new Map();
16086
16200
  const crossRegionProbe = makeCrossRegionSiblingProbe(desired.accountId, region);
16201
+ const childScanComplete = [];
16087
16202
  for (const r of desired.resources) {
16088
16203
  const enumerate = CHILD_ENUMERATORS[r.resourceType];
16089
16204
  if (!enumerate || !r.physicalId) continue;
@@ -16111,6 +16226,10 @@ async function gatherFindings(stackName, region, templateOverride, recoveryTempl
16111
16226
  const read = await readAddedModel(cc, cfn, c, schemas, oaiCanonicalIds, region, desired.accountId);
16112
16227
  findings.push(addedFinding(r, c, read));
16113
16228
  }
16229
+ childScanComplete.push({
16230
+ logicalId: r.logicalId,
16231
+ resourceType: r.resourceType
16232
+ });
16114
16233
  } catch (e) {
16115
16234
  findings.push({
16116
16235
  tier: "skipped",
@@ -16121,6 +16240,7 @@ async function gatherFindings(stackName, region, templateOverride, recoveryTempl
16121
16240
  });
16122
16241
  }
16123
16242
  }
16243
+ desired.childScanComplete = childScanComplete;
16124
16244
  let kmsAliasTargets = {};
16125
16245
  if (desired.resources.some((r) => usesManagedKmsAlias(r.declared) || typeNeedsManagedKeyResolution(r.resourceType))) {
16126
16246
  const resolved = await fetchManagedAliasTargets(region);
@@ -16200,7 +16320,11 @@ async function gatherFindings(stackName, region, templateOverride, recoveryTempl
16200
16320
  siblingClientVpnEndpointVpcs: buildClientVpnEndpointSiblingVpcs(desired),
16201
16321
  siblingCloudFrontCdPolicyIds: buildCloudFrontStagingDistCdPolicyIds(desired, liveModelMap(reads)),
16202
16322
  siblingRdsSourceModels: buildRdsReplicaSourceModels(desired, liveModelMap(reads)),
16203
- rdsOptionSettingDefaults: await buildRdsOptionSettingDefaults(desired, region)
16323
+ rdsOptionSettingDefaults: await buildRdsOptionSettingDefaults(desired, region),
16324
+ ebSgNamesById: await (async () => {
16325
+ const ids = collectEbSecurityGroupIds(desired.resources, liveModelMap(reads));
16326
+ return ids.length > 0 ? fetchSgNamesByIds(region, ids) : void 0;
16327
+ })()
16204
16328
  };
16205
16329
  const corpusDir = process.env[CORPUS_DIR_ENV];
16206
16330
  for (const r of desired.resources) {
@@ -16280,7 +16404,12 @@ async function regatherTouched(gathered, touched, region) {
16280
16404
  siblingClientVpnEndpointVpcs: buildClientVpnEndpointSiblingVpcs(desired),
16281
16405
  siblingCloudFrontCdPolicyIds: buildCloudFrontStagingDistCdPolicyIds(desired, new Map([...gathered.liveByLogical, ...liveModelMap(reads)])),
16282
16406
  siblingRdsSourceModels: buildRdsReplicaSourceModels(desired, new Map([...gathered.liveByLogical, ...liveModelMap(reads)])),
16283
- rdsOptionSettingDefaults: await buildRdsOptionSettingDefaults(desired, region)
16407
+ rdsOptionSettingDefaults: await buildRdsOptionSettingDefaults(desired, region),
16408
+ ebSgNamesById: await (async () => {
16409
+ const merged = new Map([...gathered.liveByLogical, ...liveModelMap(reads)]);
16410
+ const ids = collectEbSecurityGroupIds(desired.resources, merged);
16411
+ return ids.length > 0 ? fetchSgNamesByIds(region, ids) : void 0;
16412
+ })()
16284
16413
  };
16285
16414
  const fresh = [];
16286
16415
  for (const r of targets) fresh.push(...await classifyRead(cfn, r, reads.get(r.logicalId), schemas, classifyOpts));
@@ -16472,7 +16601,8 @@ const KNOWN_BASELINE_KEYS = new Set([
16472
16601
  "completeResources",
16473
16602
  "recordedPhysicalIds",
16474
16603
  "recordedSourceFingerprints",
16475
- "observedDefaults"
16604
+ "observedDefaults",
16605
+ "enumeratedParents"
16476
16606
  ]);
16477
16607
  const KNOWN_RECORDED_ENTRY_KEYS = new Set([
16478
16608
  "logicalId",
@@ -16534,6 +16664,7 @@ async function loadBaseline(stackName, accountId, region) {
16534
16664
  validateRecordedPhysicalIds(parsed.recordedPhysicalIds, path);
16535
16665
  validateRecordedSourceFingerprints(parsed.recordedSourceFingerprints, path);
16536
16666
  validateObservedDefaults(parsed.observedDefaults, path);
16667
+ validateEnumeratedParents(parsed.enumeratedParents, path);
16537
16668
  return parsed;
16538
16669
  }
16539
16670
  /**
@@ -16647,6 +16778,24 @@ function validateObservedDefaults(value, path) {
16647
16778
  if (unknown.length > 0) throw new Error(`${at}[${i}]: unknown key(s) ${unknown.map((k) => `"${k}"`).join(", ")} — known keys: "logicalId", "resourceType", "path"`);
16648
16779
  });
16649
16780
  }
16781
+ /**
16782
+ * #1737: validate `enumeratedParents` (optional). When present it must be an array of
16783
+ * { logicalId, resourceType } string pairs with no unknown keys — same loud-vs-silent
16784
+ * principle as validateObservedDefaults (a malformed marker would silently disable the
16785
+ * appeared-since-record confirmation this field exists to drive).
16786
+ */
16787
+ function validateEnumeratedParents(value, path) {
16788
+ if (value === void 0) return;
16789
+ const at = `baseline file ${path}: \`enumeratedParents\``;
16790
+ if (!Array.isArray(value)) throw new Error(`${at} must be an array of { logicalId, resourceType }`);
16791
+ value.forEach((entry, i) => {
16792
+ if (typeof entry !== "object" || entry === null || Array.isArray(entry)) throw new Error(`${at}[${i}] must be an object { logicalId, resourceType }`);
16793
+ const obj = entry;
16794
+ for (const k of ["logicalId", "resourceType"]) if (typeof obj[k] !== "string") throw new Error(`${at}[${i}]: "${k}" is required and must be a string`);
16795
+ const unknown = Object.keys(obj).filter((k) => k !== "logicalId" && k !== "resourceType");
16796
+ if (unknown.length > 0) throw new Error(`${at}[${i}]: unknown key(s) ${unknown.map((k) => `"${k}"`).join(", ")} — known keys: "logicalId", "resourceType"`);
16797
+ });
16798
+ }
16650
16799
  /** Deterministic order for `recorded` entries: lexicographic by (logicalId, path).
16651
16800
  * The single point where order is imposed — read/compare logic is order-independent,
16652
16801
  * so this only affects the bytes on disk. Without it the entries inherit findings
@@ -16684,7 +16833,8 @@ async function writeBaselineFile(b) {
16684
16833
  ...b.completeResources ? { completeResources: [...b.completeResources].sort() } : {},
16685
16834
  ...b.recordedPhysicalIds ? { recordedPhysicalIds: sortedPhysicalIds(b.recordedPhysicalIds, b.recorded, b.completeResources ?? []) } : {},
16686
16835
  ...b.recordedSourceFingerprints ? { recordedSourceFingerprints: sortedSourceFingerprints(b.recordedSourceFingerprints, b.recorded) } : {},
16687
- ...b.observedDefaults && b.observedDefaults.length > 0 ? { observedDefaults: [...b.observedDefaults].sort((a, c) => (a.logicalId < c.logicalId ? -1 : a.logicalId > c.logicalId ? 1 : 0) || (a.path < c.path ? -1 : a.path > c.path ? 1 : 0)) } : {}
16836
+ ...b.observedDefaults && b.observedDefaults.length > 0 ? { observedDefaults: [...b.observedDefaults].sort((a, c) => (a.logicalId < c.logicalId ? -1 : a.logicalId > c.logicalId ? 1 : 0) || (a.path < c.path ? -1 : a.path > c.path ? 1 : 0)) } : {},
16837
+ ...b.enumeratedParents && b.enumeratedParents.length > 0 ? { enumeratedParents: [...b.enumeratedParents].sort((a, c) => (a.logicalId < c.logicalId ? -1 : a.logicalId > c.logicalId ? 1 : 0) || (a.resourceType < c.resourceType ? -1 : a.resourceType > c.resourceType ? 1 : 0)) } : {}
16688
16838
  };
16689
16839
  await writeFile(p, JSON.stringify(stable, null, 2) + "\n", "utf8");
16690
16840
  return p;
@@ -16756,12 +16906,37 @@ async function writeBaseline(stackName, region, accountId, findings, rawTemplate
16756
16906
  completeResources,
16757
16907
  ...buildRecordedPhysicalIds(recorded, completeResources, opts.physicalIdByLogical, opts.previous),
16758
16908
  ...buildRecordedSourceFingerprints(recorded, opts.declaredByLogical, opts.previous),
16759
- ...buildObservedDefaults(findings, opts.previous)
16909
+ ...buildObservedDefaults(findings, opts.previous),
16910
+ ...buildEnumeratedParents(opts.enumeratedParents, findings, recorded)
16760
16911
  }),
16761
16912
  count: recorded.length
16762
16913
  };
16763
16914
  }
16764
16915
  /**
16916
+ * #1737: finalize the `enumeratedParents` marker for this record run. Seeds from the
16917
+ * gather's scan-complete parents, then DEMOTES any parent that has an `added` finding
16918
+ * this run whose entry is NOT in the final recorded set — the user (selective picker /
16919
+ * drop flow) or the run itself (a model-read-failed child buildRecorded skips) declined
16920
+ * to endorse a PRESENT child, so marking the parent complete would let that child later
16921
+ * false-confirm as "appeared since record" (the #790 completeness-demotion mirror).
16922
+ * Deterministic sort; `{}` (spread to nothing) when empty so old-shaped baselines stay
16923
+ * byte-identical. Pure + exported for unit tests.
16924
+ */
16925
+ function buildEnumeratedParents(candidates, findings, recorded) {
16926
+ if (!candidates || candidates.length === 0) return {};
16927
+ const recordedKeys = new Set(recorded.map(recordedKey));
16928
+ const blocked = /* @__PURE__ */ new Set();
16929
+ for (const f of findings) {
16930
+ if (f.tier !== "added" || f.parentLogicalId === void 0) continue;
16931
+ if (!recordedKeys.has(recordedKey({
16932
+ logicalId: f.logicalId,
16933
+ path: f.path
16934
+ }))) blocked.add(`${f.parentLogicalId}\0${f.parentResourceType}`);
16935
+ }
16936
+ const out = candidates.filter((p) => !blocked.has(`${p.logicalId}\0${p.resourceType}`)).sort((a, c) => (a.logicalId < c.logicalId ? -1 : a.logicalId > c.logicalId ? 1 : 0) || (a.resourceType < c.resourceType ? -1 : a.resourceType > c.resourceType ? 1 : 0));
16937
+ return out.length > 0 ? { enumeratedParents: out } : {};
16938
+ }
16939
+ /**
16765
16940
  * #1637: build the `observedDefaults` entries for this record run. Seeds from THIS run's
16766
16941
  * `atDefault` findings on the curated OBSERVED_DEFAULT_TRACKED_PATHS, then carries forward
16767
16942
  * the previous baseline's entries for resources this run could NOT observe (a `skipped`
@@ -17253,6 +17428,7 @@ function applyBaseline(findings, baseline, opts = {}) {
17253
17428
  } : f);
17254
17429
  const recorded = baseline.recorded;
17255
17430
  const complete = new Set(baseline.completeResources ?? []);
17431
+ const enumeratedParents = baseline.enumeratedParents ?? [];
17256
17432
  const kept = [];
17257
17433
  const currentLogicalIds = opts.allLogicalIds === void 0 ? void 0 : Array.isArray(opts.allLogicalIds) ? new Set(opts.allLogicalIds) : opts.allLogicalIds;
17258
17434
  const recordedPhysIds = baseline.recordedPhysicalIds ?? {};
@@ -17296,6 +17472,13 @@ function applyBaseline(findings, baseline, opts = {}) {
17296
17472
  });
17297
17473
  continue;
17298
17474
  }
17475
+ if (f.parentLogicalId !== void 0 && enumeratedParents.some((ep) => ep.logicalId === f.parentLogicalId && ep.resourceType === f.parentResourceType)) {
17476
+ kept.push({
17477
+ ...f,
17478
+ note: f.note ? `${f.note}; appeared since record` : "appeared since record"
17479
+ });
17480
+ continue;
17481
+ }
17299
17482
  kept.push({
17300
17483
  ...f,
17301
17484
  unrecorded: true
@@ -19934,6 +20117,16 @@ const writeBudget = async (ctx, ops) => {
19934
20117
  ...budget,
19935
20118
  BudgetLimit: void 0
19936
20119
  } : budget;
20120
+ const stringifySpend = (s) => {
20121
+ if (!s || typeof s !== "object") return void 0;
20122
+ const sp = s;
20123
+ return {
20124
+ ...sp,
20125
+ ...sp.Amount !== void 0 && { Amount: String(sp.Amount) }
20126
+ };
20127
+ };
20128
+ if (newBudget.BudgetLimit) newBudget.BudgetLimit = stringifySpend(newBudget.BudgetLimit);
20129
+ if (newBudget.PlannedBudgetLimits) newBudget.PlannedBudgetLimits = Object.fromEntries(Object.entries(newBudget.PlannedBudgetLimits).map(([k, v]) => [k, stringifySpend(v)]));
19937
20130
  await new BudgetsClient({
19938
20131
  region: ctx.region,
19939
20132
  ...CLIENT_TIMEOUTS
@@ -20318,6 +20511,8 @@ const REVERT_SET_DEFAULT_PATHS = new Set([
20318
20511
  "AWS::EC2::CapacityReservation\0InstanceMatchCriteria",
20319
20512
  "AWS::EC2::CapacityReservation\0EndDateType",
20320
20513
  "AWS::CodeDeploy::DeploymentGroup\0DeploymentConfigName",
20514
+ "AWS::CodeDeploy::DeploymentGroup\0DeploymentStyle",
20515
+ "AWS::CodeDeploy::DeploymentGroup\0LoadBalancerInfo",
20321
20516
  "AWS::DLM::LifecyclePolicy\0RetainInterval",
20322
20517
  "AWS::DLM::LifecyclePolicy\0CreateInterval",
20323
20518
  "AWS::IAM::Role\0MaxSessionDuration",
@@ -20424,7 +20619,8 @@ const REVERT_SET_DEFAULT_VALUES = {
20424
20619
  "AWS::DocDB::DBCluster\0DeletionProtection": false,
20425
20620
  "AWS::EKS::Cluster\0ResourcesVpcConfig.EndpointPrivateAccess": false,
20426
20621
  "AWS::ApiGatewayV2::IntegrationResponse\0TemplateSelectionExpression": "",
20427
- "AWS::ApiGatewayV2::RouteResponse\0ModelSelectionExpression": ""
20622
+ "AWS::ApiGatewayV2::RouteResponse\0ModelSelectionExpression": "",
20623
+ "AWS::CodeDeploy::DeploymentGroup\0LoadBalancerInfo": { TargetGroupInfoList: [] }
20428
20624
  };
20429
20625
  /**
20430
20626
  * A nested undeclared value (a live sub-key inside a declared object, R96/R98) — a dotted
@@ -20454,6 +20650,15 @@ function isNestedUndeclared(f) {
20454
20650
  function isUnrevertableNested(f) {
20455
20651
  return isNestedUndeclared(f) && f.path.includes("[");
20456
20652
  }
20653
+ function elbAttributeBagElementOf(f) {
20654
+ const bag = ELB_ATTRIBUTE_BAGS[f.resourceType];
20655
+ if (!bag || !f.path.startsWith(`${bag}[`) || !f.path.endsWith("]")) return void 0;
20656
+ const key = f.path.slice(bag.length + 1, -1);
20657
+ return key ? {
20658
+ prop: bag,
20659
+ key
20660
+ } : void 0;
20661
+ }
20457
20662
  function isManagedPolicyAttachmentMember(f) {
20458
20663
  return f.tier === "undeclared" && f.resourceType === "AWS::IAM::ManagedPolicy" && /^(Roles|Users|Groups)\[.+\]$/.test(f.path);
20459
20664
  }
@@ -20662,7 +20867,9 @@ function buildRevertPlan(findings, baseline, opts = {}) {
20662
20867
  });
20663
20868
  continue;
20664
20869
  }
20665
- if (isUnrevertableNested(f) && !isManagedPolicyAttachmentMember(f) && !isNestedSdkWritable(f)) {
20870
+ const bagElement = elbAttributeBagElementOf(f);
20871
+ const bagElementRevertible = bagElement !== void 0 && !SDK_WRITERS[f.resourceType] && SDK_PROP_WRITERS[f.resourceType]?.[bagElement.prop] !== void 0 && (f.desired !== void 0 || recorded.some((a) => a.logicalId === f.logicalId && a.path === f.path) || elbAttributeDefaultsFor(f.resourceType, opts.declaredForLogical?.(f.logicalId) ?? {}, {})[bagElement.key] !== void 0);
20872
+ if (isUnrevertableNested(f) && !isManagedPolicyAttachmentMember(f) && !isNestedSdkWritable(f) && !bagElementRevertible) {
20666
20873
  notRevertable.push({
20667
20874
  displayId,
20668
20875
  resourceType: f.resourceType,
@@ -20755,7 +20962,7 @@ function buildRevertPlan(findings, baseline, opts = {}) {
20755
20962
  });
20756
20963
  continue;
20757
20964
  }
20758
- const propScoped = !SDK_WRITERS[f.resourceType] && SDK_PROP_WRITERS[f.resourceType]?.[f.path] !== void 0;
20965
+ const propScoped = !SDK_WRITERS[f.resourceType] && SDK_PROP_WRITERS[f.resourceType]?.[bagElement?.prop ?? f.path] !== void 0;
20759
20966
  const nestedScoped = !SDK_WRITERS[f.resourceType] && !propScoped && isNestedSdkWritable(f);
20760
20967
  if (JSON_STRING_PROPS[f.resourceType]?.has(f.path) && !propScoped && !SDK_WRITERS[f.resourceType]) {
20761
20968
  notRevertable.push({
@@ -20807,7 +21014,7 @@ function buildRevertPlan(findings, baseline, opts = {}) {
20807
21014
  }
20808
21015
  const declaredModel = opts.declaredForLogical?.(f.logicalId);
20809
21016
  const op = revertOp(toRevert, recorded, opts.identity, declaredModel);
20810
- const key = `${f.logicalId} ${kind}${propScoped ? ` ${f.path}` : ""}`;
21017
+ const key = `${f.logicalId} ${kind}${propScoped ? ` ${bagElement?.prop ?? f.path}` : ""}`;
20811
21018
  const item = itemsByLogical.get(key) ?? {
20812
21019
  logicalId: f.logicalId,
20813
21020
  displayId,
@@ -20827,6 +21034,7 @@ function buildRevertPlan(findings, baseline, opts = {}) {
20827
21034
  item.ops.push({
20828
21035
  op: "remove",
20829
21036
  path: siblingPointer,
21037
+ contract: true,
20830
21038
  human: `${sibling} -> remove (incompatible with the restored default)`
20831
21039
  });
20832
21040
  }
@@ -20878,11 +21086,17 @@ function derivedRevertDefaultFor(resourceType, path, declared) {
20878
21086
  if (path === "HealthCheckPort") return elbTargetGroupDerivedHealthCheckPort(declared["Protocol"]);
20879
21087
  }
20880
21088
  if (resourceType === "AWS::RDS::DBInstance" && path === "BackupRetentionPeriod") return rdsReplicaDerivedBackupRetention(declared["SourceDBInstanceIdentifier"]);
21089
+ if (resourceType === "AWS::ECS::Service") {
21090
+ if (path === "DeploymentConfiguration") return ecsDaemonDerivedDeploymentConfiguration(declared["SchedulingStrategy"]);
21091
+ if (path === "DeploymentConfiguration.MaximumPercent") return ecsDaemonDerivedMaximumPercent(declared["SchedulingStrategy"]);
21092
+ if (path === "DeploymentConfiguration.MinimumHealthyPercent") return ecsDaemonDerivedMinimumHealthyPercent(declared["SchedulingStrategy"]);
21093
+ }
20881
21094
  if (resourceType === "AWS::Logs::LogGroup" && path === "RetentionInDays") return logsDeliveryDerivedRetention(declared["LogGroupClass"]);
20882
21095
  }
20883
21096
  const REVERT_COMPANION_REMOVES = {
20884
21097
  "AWS::ElasticLoadBalancingV2::TargetGroup\0HealthCheckProtocol": (value) => value === "TCP" ? ["Matcher", "HealthCheckPath"] : [],
20885
- "AWS::EC2::Volume\0VolumeType": (value) => value === "gp2" || value === "standard" || value === "st1" || value === "sc1" ? ["Iops", "Throughput"] : value === "io1" || value === "io2" ? ["Throughput"] : []
21098
+ "AWS::EC2::Volume\0VolumeType": (value) => value === "gp2" || value === "standard" || value === "st1" || value === "sc1" ? ["Iops", "Throughput"] : value === "io1" || value === "io2" ? ["Throughput"] : [],
21099
+ "AWS::ECS::Service\0DeploymentConfiguration": () => ["DesiredCount"]
20886
21100
  };
20887
21101
  function revertOp(f, recorded, identity, declaredModel) {
20888
21102
  const pointer = toPointer(f.path);
@@ -20895,6 +21109,19 @@ function revertOp(f, recorded, identity, declaredModel) {
20895
21109
  human: `${f.path}${f.attributeKey ? `[${f.attributeKey}]` : ""} -> deployed-template value`
20896
21110
  };
20897
21111
  const wasRecorded = recorded.find((a) => a.logicalId === f.logicalId && a.path === f.path);
21112
+ const bagEl = elbAttributeBagElementOf(f);
21113
+ if (bagEl) {
21114
+ const baselineValue = f.desired !== void 0 ? f.desired : wasRecorded?.value;
21115
+ const value = baselineValue !== void 0 ? baselineValue : elbAttributeDefaultsFor(f.resourceType, declaredModel ?? {}, {})[bagEl.key];
21116
+ if (value !== void 0) return {
21117
+ op: "add",
21118
+ path: toPointer(bagEl.prop),
21119
+ value,
21120
+ prior: f.actual,
21121
+ attributeKey: bagEl.key,
21122
+ human: `${bagEl.prop}[${bagEl.key}] -> ${baselineValue !== void 0 ? "baseline value" : "AWS default (undeclared, not in baseline)"}`
21123
+ };
21124
+ }
20898
21125
  if (f.actual === void 0 && f.desired !== void 0) return {
20899
21126
  op: "add",
20900
21127
  path: pointer,
@@ -21711,6 +21938,7 @@ async function recordStack(p) {
21711
21938
  allLogicalIds: desired.resources.map((r) => r.logicalId),
21712
21939
  previous: existing,
21713
21940
  physicalIdByLogical: physicalIdsByLogical(desired.resources),
21941
+ enumeratedParents: desired.childScanComplete,
21714
21942
  declaredByLogical: declaredKeysByLogical(desired.resources)
21715
21943
  });
21716
21944
  if (!p.json) console.log(style.ok(recordOutcomeMessage(stackName, path, count, refreshedOnly, !!existing)));
@@ -22181,6 +22409,7 @@ async function revertStack(p) {
22181
22409
  if (item.kind === "delete" || !okIds.has(item.logicalId)) continue;
22182
22410
  for (const op of item.ops) {
22183
22411
  if (op.op !== "remove" && op.op !== "add") continue;
22412
+ if (op.contract) continue;
22184
22413
  const dotted = op.path.replace(/^\//, "").replace(/\//g, ".");
22185
22414
  const key = `${item.logicalId}\0${dotted}`;
22186
22415
  if (!preActual.has(key)) continue;