cdk-real-drift 0.25.4 → 0.26.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/README.md CHANGED
@@ -902,7 +902,8 @@ covers them. **If you never run `revert`, cdkrd needs no write permissions at al
902
902
  `lambda:GetPolicy`, `budgets:ViewBudget`, `ec2:DescribeAddresses`,
903
903
  `ec2:DescribeLaunchTemplateVersions`, `ec2:DescribeNetworkAcls`,
904
904
  `route53:ListResourceRecordSets`, `route53:ListHostedZonesByName` (resolves a
905
- RecordSet declared via `HostedZoneName` instead of `HostedZoneId` to its zone
905
+ RecordSet — or a RecordSetGroup, which is read member-by-member via the same
906
+ listing — declared via `HostedZoneName` instead of `HostedZoneId` to its zone
906
907
  id),
907
908
  `ses:DescribeReceiptRuleSet`, `ses:DescribeReceiptRule`, `ses:ListReceiptFilters`
908
909
  (the SES inbound receipt-rule family — `ReceiptRuleSet` / `ReceiptRule` /
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;
@@ -4067,6 +4073,7 @@ const JSON_STRING_PROPS = { "AWS::Config::ConfigRule": new Set(["InputParameters
4067
4073
  const JSON_STRING_DEFAULT_FILLS = { "AWS::CE::CostCategory": { Rules: { Type: "REGULAR" } } };
4068
4074
  const CASE_INSENSITIVE_PATHS = {
4069
4075
  "AWS::Route53::RecordSet": new Set(["Name", "AliasTarget.DNSName"]),
4076
+ "AWS::Route53::RecordSetGroup": new Set(["RecordSets.*.Name", "RecordSets.*.AliasTarget.DNSName"]),
4070
4077
  "AWS::Batch::ComputeEnvironment": new Set(["Type"]),
4071
4078
  "AWS::Batch::JobDefinition": new Set(["Type"]),
4072
4079
  "AWS::EMRServerless::Application": new Set(["Type"]),
@@ -4075,12 +4082,14 @@ const CASE_INSENSITIVE_PATHS = {
4075
4082
  "DBParameterGroupName",
4076
4083
  "DBSubnetGroupName",
4077
4084
  "OptionGroupName",
4078
- "DBClusterIdentifier"
4085
+ "DBClusterIdentifier",
4086
+ "Engine"
4079
4087
  ]),
4080
4088
  "AWS::RDS::DBCluster": new Set([
4081
4089
  "DBClusterIdentifier",
4082
4090
  "DBClusterParameterGroupName",
4083
- "DBSubnetGroupName"
4091
+ "DBSubnetGroupName",
4092
+ "Engine"
4084
4093
  ]),
4085
4094
  "AWS::ElastiCache::SubnetGroup": new Set(["CacheSubnetGroupName"]),
4086
4095
  "AWS::ElastiCache::ReplicationGroup": new Set([
@@ -4114,9 +4123,9 @@ const CASE_INSENSITIVE_PATHS = {
4114
4123
  "DBSubnetGroupName"
4115
4124
  ]),
4116
4125
  "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"]),
4126
+ "AWS::RDS::DBParameterGroup": new Set(["DBParameterGroupName", "Family"]),
4127
+ "AWS::RDS::DBClusterParameterGroup": new Set(["DBClusterParameterGroupName", "Family"]),
4128
+ "AWS::RDS::OptionGroup": new Set(["OptionGroupName", "EngineName"]),
4120
4129
  "AWS::RDS::DBSubnetGroup": new Set(["DBSubnetGroupName"]),
4121
4130
  "AWS::Neptune::DBParameterGroup": new Set(["Name"]),
4122
4131
  "AWS::Neptune::DBClusterParameterGroup": new Set(["Name"]),
@@ -4640,6 +4649,7 @@ const UNORDERED_ARRAY_PROPS = {
4640
4649
  ]),
4641
4650
  "AWS::WAFv2::IPSet": new Set(["Addresses"]),
4642
4651
  "AWS::Route53::RecordSet": new Set(["ResourceRecords"]),
4652
+ "AWS::Route53::RecordSetGroup": new Set(["RecordSets.*.ResourceRecords"]),
4643
4653
  "AWS::CodeDeploy::DeploymentGroup": new Set(["AutoRollbackConfiguration.Events"]),
4644
4654
  "AWS::RDS::DBInstance": new Set(["EnableCloudwatchLogsExports"]),
4645
4655
  "AWS::RDS::DBCluster": new Set(["EnableCloudwatchLogsExports"]),
@@ -5557,6 +5567,30 @@ function logsDeliveryDerivedRetention(logGroupClass) {
5557
5567
  function rdsReplicaDerivedBackupRetention(sourceDbInstanceIdentifier) {
5558
5568
  return sourceDbInstanceIdentifier !== void 0 ? 0 : void 0;
5559
5569
  }
5570
+ function ecsDaemonDerivedMaximumPercent(schedulingStrategy) {
5571
+ return schedulingStrategy === "DAEMON" ? 100 : void 0;
5572
+ }
5573
+ function ecsDaemonDerivedMinimumHealthyPercent(schedulingStrategy) {
5574
+ return schedulingStrategy === "DAEMON" ? 0 : void 0;
5575
+ }
5576
+ function ecsDaemonDerivedDeploymentConfiguration(schedulingStrategy) {
5577
+ if (schedulingStrategy !== "DAEMON") return void 0;
5578
+ return {
5579
+ BakeTimeInMinutes: 0,
5580
+ Strategy: "ROLLING",
5581
+ DeploymentCircuitBreaker: {
5582
+ ThresholdConfiguration: {
5583
+ Type: "BOUNDED_PERCENT",
5584
+ Value: 50
5585
+ },
5586
+ Enable: false,
5587
+ ResetOnHealthyTask: true,
5588
+ Rollback: false
5589
+ },
5590
+ MaximumPercent: 100,
5591
+ MinimumHealthyPercent: 0
5592
+ };
5593
+ }
5560
5594
 
5561
5595
  //#endregion
5562
5596
  //#region src/read/kms-aliases.ts
@@ -6449,12 +6483,12 @@ const IAM_ATTACHMENT_SUBSET = { "AWS::IAM::ManagedPolicy": new Set([
6449
6483
  "Users",
6450
6484
  "Groups"
6451
6485
  ]) };
6452
- const ebOptionSettingsEntryTier = (entry, liveArray) => {
6486
+ const ebOptionSettingsEntryTier = (entry, liveArray, ebSgNamesById) => {
6453
6487
  const arr = Array.isArray(liveArray) ? liveArray : [];
6454
6488
  const envEntry = arr.find((e) => e && e.OptionName === "EnvironmentType");
6455
6489
  const envType = typeof envEntry?.Value === "string" ? envEntry.Value : "LoadBalanced";
6456
6490
  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);
6491
+ return ebOptionSettingTier(entry.Namespace, entry.OptionName, entry.Value, envType, siblingOption, ebSgNamesById);
6458
6492
  };
6459
6493
  const ebOptionSettingsSubsetSpec = {
6460
6494
  re: /(^|\.)OptionSettings$/,
@@ -7362,6 +7396,26 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
7362
7396
  StorageType: storageDefault
7363
7397
  };
7364
7398
  }
7399
+ if (resourceType === "AWS::ECS::Service") {
7400
+ const daemonMax = ecsDaemonDerivedMaximumPercent(declared["SchedulingStrategy"]);
7401
+ const daemonMin = ecsDaemonDerivedMinimumHealthyPercent(declared["SchedulingStrategy"]);
7402
+ if (daemonMax !== void 0 && daemonMin !== void 0) {
7403
+ const dcPin = knownDef["DeploymentConfiguration"];
7404
+ if (dcPin && typeof dcPin === "object") knownDef = {
7405
+ ...knownDef,
7406
+ DeploymentConfiguration: {
7407
+ ...dcPin,
7408
+ MaximumPercent: daemonMax,
7409
+ MinimumHealthyPercent: daemonMin
7410
+ }
7411
+ };
7412
+ knownDefPaths = {
7413
+ ...knownDefPaths,
7414
+ "DeploymentConfiguration.MaximumPercent": daemonMax,
7415
+ "DeploymentConfiguration.MinimumHealthyPercent": daemonMin
7416
+ };
7417
+ }
7418
+ }
7365
7419
  if (resourceType === "AWS::CE::AnomalySubscription") {
7366
7420
  const threshold = declared["Threshold"];
7367
7421
  if (typeof threshold === "number" && Number.isFinite(threshold)) {
@@ -7921,7 +7975,7 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
7921
7975
  const r = lo;
7922
7976
  const key = ckSubsetSpec.keyFields.map((f) => String(r[f])).join("|");
7923
7977
  findings.push({
7924
- tier: ckSubsetSpec.entryTier?.(r, d.awsValue) ?? "undeclared",
7978
+ tier: ckSubsetSpec.entryTier?.(r, d.awsValue, opts.ebSgNamesById) ?? "undeclared",
7925
7979
  logicalId,
7926
7980
  resourceType,
7927
7981
  path: `${d.path}[${key}]`,
@@ -8148,7 +8202,7 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
8148
8202
  continue;
8149
8203
  }
8150
8204
  }
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)) {
8205
+ 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
8206
  findings.push({
8153
8207
  tier: "atDefault",
8154
8208
  logicalId,
@@ -11410,27 +11464,41 @@ function route53ZoneRefMatches(declared, hostedZoneId, zoneApex) {
11410
11464
  if (hzName === UNRESOLVED || hasUnresolved(hzName)) return true;
11411
11465
  return typeof hzName === "string" && zoneApex !== void 0 && canonRoute53Name(hzName) === canonRoute53Name(zoneApex);
11412
11466
  }
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;
11467
+ function collectDeclaredRoute53Records(resources, hostedZoneId, zoneApex) {
11418
11468
  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;
11469
+ const pushDeclared = (rec) => {
11470
+ const name = typeof rec.Name === "string" ? rec.Name : void 0;
11471
+ const type = typeof rec.Type === "string" ? rec.Type : void 0;
11424
11472
  if (name && type) declaredRecords.push({
11425
11473
  name,
11426
11474
  type,
11427
- setIdentifier: typeof r.declared.SetIdentifier === "string" ? r.declared.SetIdentifier : void 0
11475
+ setIdentifier: typeof rec.SetIdentifier === "string" ? rec.SetIdentifier : void 0
11428
11476
  });
11477
+ };
11478
+ for (const r of resources) if (r.resourceType === "AWS::Route53::RecordSet") {
11479
+ if (!route53ZoneRefMatches(r.declared, hostedZoneId, zoneApex)) continue;
11480
+ pushDeclared(r.declared);
11481
+ } else if (r.resourceType === "AWS::Route53::RecordSetGroup") {
11482
+ const groupMatches = route53ZoneRefMatches(r.declared, hostedZoneId, zoneApex);
11483
+ const sets = Array.isArray(r.declared.RecordSets) ? r.declared.RecordSets : [];
11484
+ for (const rs of sets) {
11485
+ if (!rs || typeof rs !== "object") continue;
11486
+ const rec = rs;
11487
+ if (!groupMatches && !route53ZoneRefMatches(rec, hostedZoneId, zoneApex)) continue;
11488
+ pushDeclared(rec);
11489
+ }
11429
11490
  }
11491
+ return declaredRecords;
11492
+ }
11493
+ async function enumerateRoute53HostedZoneChildren(ctx) {
11494
+ const { parent, desired, region } = ctx;
11495
+ const hostedZoneId = parent.physicalId;
11496
+ if (!hostedZoneId) return [];
11497
+ const zoneApex = typeof parent.declared.Name === "string" ? parent.declared.Name : void 0;
11430
11498
  return diffRoute53HostedZoneChildren({
11431
11499
  hostedZoneId,
11432
11500
  zoneApex,
11433
- declaredRecords,
11501
+ declaredRecords: collectDeclaredRoute53Records(desired.resources, hostedZoneId, zoneApex),
11434
11502
  liveRecords: (await pageResourceRecordSets(new Route53Client({
11435
11503
  region,
11436
11504
  ...READ_RETRY
@@ -13098,10 +13166,13 @@ const readRoute53RecordSet = async ({ physicalId, declared, region }) => {
13098
13166
  startId = r.NextRecordIdentifier;
13099
13167
  }
13100
13168
  if (!rec) throw new ResourceGoneError(`Route53 RecordSet ${name} ${type} absent from zone ${hostedZoneId}`);
13169
+ return projectRoute53RecordModel(rec, declared, byName ? { HostedZoneName: zoneName } : { HostedZoneId: hostedZoneId });
13170
+ };
13171
+ function projectRoute53RecordModel(rec, declared, zoneField) {
13101
13172
  const model = {
13102
13173
  Name: alignTrailingDot(rec.Name === void 0 ? void 0 : unescapeRoute53Name(rec.Name), declared.Name),
13103
13174
  Type: rec.Type,
13104
- ...byName ? { HostedZoneName: zoneName } : { HostedZoneId: hostedZoneId }
13175
+ ...zoneField
13105
13176
  };
13106
13177
  if (rec.TTL !== void 0) model.TTL = String(rec.TTL);
13107
13178
  const records = rec.ResourceRecords?.map((rr) => rr.Value).filter((v) => !!v);
@@ -13142,6 +13213,39 @@ const readRoute53RecordSet = async ({ physicalId, declared, region }) => {
13142
13213
  ...cidr.LocationName !== void 0 && { LocationName: cidr.LocationName }
13143
13214
  };
13144
13215
  return model;
13216
+ }
13217
+ const readRoute53RecordSetGroup = async ({ declared, region }) => {
13218
+ const c = new Route53Client({
13219
+ region,
13220
+ ...READ_RETRY
13221
+ });
13222
+ const declaredZoneId = str$1(declared.HostedZoneId);
13223
+ const zoneName = str$1(declared.HostedZoneName);
13224
+ const byName = !declaredZoneId && !!zoneName;
13225
+ const hostedZoneId = declaredZoneId ?? (zoneName ? await resolveHostedZoneIdByName(c, zoneName) : void 0);
13226
+ const declSets = Array.isArray(declared.RecordSets) ? declared.RecordSets : void 0;
13227
+ if (!hostedZoneId || !declSets) return void 0;
13228
+ const live = await pageResourceRecordSets(c, hostedZoneId);
13229
+ const canon = (s) => unescapeRoute53Name(s).replace(/\.$/, "").toLowerCase();
13230
+ const projected = [];
13231
+ for (const d of declSets) {
13232
+ if (!d || typeof d !== "object") continue;
13233
+ const name = str$1(d.Name);
13234
+ const type = str$1(d.Type);
13235
+ if (!name || !type) continue;
13236
+ const declSetId = str$1(d.SetIdentifier);
13237
+ const rec = live.find((x) => x.Type === type && !!x.Name && canon(x.Name) === canon(name) && (x.SetIdentifier ?? void 0) === declSetId);
13238
+ if (!rec) continue;
13239
+ projected.push(projectRoute53RecordModel(rec, d, {
13240
+ ...str$1(d.HostedZoneId) !== void 0 && { HostedZoneId: d.HostedZoneId },
13241
+ ...str$1(d.HostedZoneName) !== void 0 && { HostedZoneName: d.HostedZoneName }
13242
+ }));
13243
+ }
13244
+ return {
13245
+ ...declaredZoneId !== void 0 && { HostedZoneId: declaredZoneId },
13246
+ ...byName && { HostedZoneName: zoneName },
13247
+ RecordSets: projected
13248
+ };
13145
13249
  };
13146
13250
  const readGlueTable = async ({ physicalId, declared, region }) => {
13147
13251
  const idParts = physicalId.split("|");
@@ -14047,6 +14151,7 @@ const SDK_OVERRIDES = {
14047
14151
  "AWS::MediaConvert::Queue": readMediaConvertQueue,
14048
14152
  "AWS::MediaConvert::JobTemplate": readMediaConvertJobTemplate,
14049
14153
  "AWS::Route53::RecordSet": readRoute53RecordSet,
14154
+ "AWS::Route53::RecordSetGroup": readRoute53RecordSetGroup,
14050
14155
  "AWS::Glue::Table": readGlueTable,
14051
14156
  "AWS::Glue::Classifier": readGlueClassifier,
14052
14157
  "AWS::Glue::Workflow": readGlueWorkflow,
@@ -15056,6 +15161,52 @@ const DEFAULT_SG_LIST_TYPES = new Set([
15056
15161
  "AWS::EC2::VPCEndpoint"
15057
15162
  ]);
15058
15163
  const DEFAULT_SUBNET_LIST_TYPES = new Set(["AWS::RedshiftServerless::Workgroup"]);
15164
+ const EB_SG_OPTION_KEYS = new Set(["aws:elb:loadbalancer|SecurityGroups", "aws:autoscaling:launchconfiguration|SecurityGroups"]);
15165
+ function collectEbSecurityGroupIds(resources, liveById) {
15166
+ const ids = /* @__PURE__ */ new Set();
15167
+ for (const r of resources) {
15168
+ if (r.resourceType !== "AWS::ElasticBeanstalk::Environment") continue;
15169
+ const live = liveById.get(r.logicalId);
15170
+ if (!live) continue;
15171
+ const settings = live.OptionSettings;
15172
+ if (!Array.isArray(settings)) continue;
15173
+ for (const s of settings) {
15174
+ if (!s || typeof s !== "object") continue;
15175
+ const e = s;
15176
+ if (!EB_SG_OPTION_KEYS.has(`${String(e.Namespace)}|${String(e.OptionName)}`)) continue;
15177
+ if (typeof e.Value !== "string") continue;
15178
+ for (const el of e.Value.split(",")) {
15179
+ const t = el.trim();
15180
+ if (/^sg-[0-9a-f]+$/i.test(t)) ids.add(t);
15181
+ }
15182
+ }
15183
+ }
15184
+ return [...ids];
15185
+ }
15186
+ async function fetchSgNamesByIds(region, ids) {
15187
+ try {
15188
+ const c = new EC2Client({
15189
+ region,
15190
+ ...READ_RETRY
15191
+ });
15192
+ const out = {};
15193
+ let token;
15194
+ do {
15195
+ const r = await c.send(new DescribeSecurityGroupsCommand({
15196
+ Filters: [{
15197
+ Name: "group-id",
15198
+ Values: [...ids]
15199
+ }],
15200
+ NextToken: token
15201
+ }));
15202
+ for (const g of r.SecurityGroups ?? []) if (g.GroupId && g.GroupName) out[g.GroupId] = g.GroupName;
15203
+ token = r.NextToken;
15204
+ } while (token);
15205
+ return out;
15206
+ } catch {
15207
+ return;
15208
+ }
15209
+ }
15059
15210
  const defaultSgIdsCache = /* @__PURE__ */ new Map();
15060
15211
  async function fetchDefaultSgIds(region) {
15061
15212
  const cached = defaultSgIdsCache.get(region);
@@ -16208,7 +16359,11 @@ async function gatherFindings(stackName, region, templateOverride, recoveryTempl
16208
16359
  siblingClientVpnEndpointVpcs: buildClientVpnEndpointSiblingVpcs(desired),
16209
16360
  siblingCloudFrontCdPolicyIds: buildCloudFrontStagingDistCdPolicyIds(desired, liveModelMap(reads)),
16210
16361
  siblingRdsSourceModels: buildRdsReplicaSourceModels(desired, liveModelMap(reads)),
16211
- rdsOptionSettingDefaults: await buildRdsOptionSettingDefaults(desired, region)
16362
+ rdsOptionSettingDefaults: await buildRdsOptionSettingDefaults(desired, region),
16363
+ ebSgNamesById: await (async () => {
16364
+ const ids = collectEbSecurityGroupIds(desired.resources, liveModelMap(reads));
16365
+ return ids.length > 0 ? fetchSgNamesByIds(region, ids) : void 0;
16366
+ })()
16212
16367
  };
16213
16368
  const corpusDir = process.env[CORPUS_DIR_ENV];
16214
16369
  for (const r of desired.resources) {
@@ -16288,7 +16443,12 @@ async function regatherTouched(gathered, touched, region) {
16288
16443
  siblingClientVpnEndpointVpcs: buildClientVpnEndpointSiblingVpcs(desired),
16289
16444
  siblingCloudFrontCdPolicyIds: buildCloudFrontStagingDistCdPolicyIds(desired, new Map([...gathered.liveByLogical, ...liveModelMap(reads)])),
16290
16445
  siblingRdsSourceModels: buildRdsReplicaSourceModels(desired, new Map([...gathered.liveByLogical, ...liveModelMap(reads)])),
16291
- rdsOptionSettingDefaults: await buildRdsOptionSettingDefaults(desired, region)
16446
+ rdsOptionSettingDefaults: await buildRdsOptionSettingDefaults(desired, region),
16447
+ ebSgNamesById: await (async () => {
16448
+ const merged = new Map([...gathered.liveByLogical, ...liveModelMap(reads)]);
16449
+ const ids = collectEbSecurityGroupIds(desired.resources, merged);
16450
+ return ids.length > 0 ? fetchSgNamesByIds(region, ids) : void 0;
16451
+ })()
16292
16452
  };
16293
16453
  const fresh = [];
16294
16454
  for (const r of targets) fresh.push(...await classifyRead(cfn, r, reads.get(r.logicalId), schemas, classifyOpts));
@@ -18858,12 +19018,10 @@ const RR_ROUTING_FIELDS = [
18858
19018
  "GeoProximityLocation",
18859
19019
  "CidrRoutingConfig"
18860
19020
  ];
18861
- const writeRoute53RecordSet = async (ctx, ops) => {
18862
- const m = await desiredModel("AWS::Route53::RecordSet", ctx, ops);
18863
- const zone = str(m.HostedZoneId) ?? str(ctx.declared["HostedZoneId"]);
18864
- const name = str(m.Name) ?? str(ctx.declared["Name"]);
18865
- const type = str(m.Type) ?? str(ctx.declared["Type"]);
18866
- if (!zone || !name || !type) throw new Error("cannot resolve Route53 record target for revert");
19021
+ function buildRoute53RrSet(m) {
19022
+ const name = str(m.Name);
19023
+ const type = str(m.Type);
19024
+ if (!name || !type) return void 0;
18867
19025
  const rrset = {
18868
19026
  Name: name,
18869
19027
  Type: type
@@ -18872,6 +19030,17 @@ const writeRoute53RecordSet = async (ctx, ops) => {
18872
19030
  if (Array.isArray(m.ResourceRecords)) rrset.ResourceRecords = m.ResourceRecords.map((v) => ({ Value: v }));
18873
19031
  if (m.AliasTarget !== void 0) rrset.AliasTarget = m.AliasTarget;
18874
19032
  for (const k of RR_ROUTING_FIELDS) if (m[k] !== void 0) rrset[k] = m[k];
19033
+ return rrset;
19034
+ }
19035
+ const writeRoute53RecordSet = async (ctx, ops) => {
19036
+ const m = await desiredModel("AWS::Route53::RecordSet", ctx, ops);
19037
+ const zone = str(m.HostedZoneId) ?? str(ctx.declared["HostedZoneId"]);
19038
+ const rrset = buildRoute53RrSet({
19039
+ ...m,
19040
+ Name: str(m.Name) ?? str(ctx.declared["Name"]),
19041
+ Type: str(m.Type) ?? str(ctx.declared["Type"])
19042
+ });
19043
+ if (!zone || !rrset) throw new Error("cannot resolve Route53 record target for revert");
18875
19044
  await new Route53Client({
18876
19045
  region: ctx.region,
18877
19046
  ...CLIENT_TIMEOUTS
@@ -18883,6 +19052,37 @@ const writeRoute53RecordSet = async (ctx, ops) => {
18883
19052
  }] }
18884
19053
  }));
18885
19054
  };
19055
+ const writeRoute53RecordSetGroup = async (ctx, ops) => {
19056
+ const m = await desiredModel("AWS::Route53::RecordSetGroup", ctx, ops);
19057
+ let zone = str(m.HostedZoneId) ?? str(ctx.declared["HostedZoneId"]);
19058
+ if (!zone) {
19059
+ const zoneName = str(m.HostedZoneName) ?? str(ctx.declared["HostedZoneName"]);
19060
+ if (zoneName) zone = await resolveHostedZoneIdByName(new Route53Client({
19061
+ region: ctx.region,
19062
+ ...CLIENT_TIMEOUTS
19063
+ }), zoneName);
19064
+ }
19065
+ const sets = Array.isArray(m.RecordSets) ? m.RecordSets : [];
19066
+ if (!zone || sets.length === 0) throw new Error("cannot resolve Route53 record-set-group target for revert");
19067
+ const wholeArray = ops.some((o) => o.path === "/RecordSets");
19068
+ const touched = /* @__PURE__ */ new Set();
19069
+ for (const o of ops) {
19070
+ const i = /^\/RecordSets\/(\d+)(\/|$)/.exec(o.path)?.[1];
19071
+ if (i !== void 0) touched.add(Number(i));
19072
+ }
19073
+ const changes = (wholeArray ? sets : [...touched].map((i) => sets[i]).filter((s) => !!s)).map((member) => buildRoute53RrSet(member)).filter((r) => r !== void 0).map((rrset) => ({
19074
+ Action: "UPSERT",
19075
+ ResourceRecordSet: rrset
19076
+ }));
19077
+ if (changes.length === 0) throw new Error("Route53 record-set-group revert: no member resolved from the revert ops");
19078
+ await new Route53Client({
19079
+ region: ctx.region,
19080
+ ...CLIENT_TIMEOUTS
19081
+ }).send(new ChangeResourceRecordSetsCommand({
19082
+ HostedZoneId: zone,
19083
+ ChangeBatch: { Changes: changes }
19084
+ }));
19085
+ };
18886
19086
  const configInputParametersString = (v) => {
18887
19087
  let model = v;
18888
19088
  if (typeof v === "string") try {
@@ -19996,6 +20196,16 @@ const writeBudget = async (ctx, ops) => {
19996
20196
  ...budget,
19997
20197
  BudgetLimit: void 0
19998
20198
  } : budget;
20199
+ const stringifySpend = (s) => {
20200
+ if (!s || typeof s !== "object") return void 0;
20201
+ const sp = s;
20202
+ return {
20203
+ ...sp,
20204
+ ...sp.Amount !== void 0 && { Amount: String(sp.Amount) }
20205
+ };
20206
+ };
20207
+ if (newBudget.BudgetLimit) newBudget.BudgetLimit = stringifySpend(newBudget.BudgetLimit);
20208
+ if (newBudget.PlannedBudgetLimits) newBudget.PlannedBudgetLimits = Object.fromEntries(Object.entries(newBudget.PlannedBudgetLimits).map(([k, v]) => [k, stringifySpend(v)]));
19999
20209
  await new BudgetsClient({
20000
20210
  region: ctx.region,
20001
20211
  ...CLIENT_TIMEOUTS
@@ -20083,6 +20293,7 @@ const SDK_WRITERS = {
20083
20293
  "AWS::DLM::LifecyclePolicy": writeDlmLifecyclePolicy,
20084
20294
  "AWS::Logs::MetricFilter": writeMetricFilter,
20085
20295
  "AWS::Route53::RecordSet": writeRoute53RecordSet,
20296
+ "AWS::Route53::RecordSetGroup": writeRoute53RecordSetGroup,
20086
20297
  "AWS::DocDB::DBCluster": writeDocDbCluster,
20087
20298
  "AWS::DocDB::DBInstance": writeDocDbInstance,
20088
20299
  "AWS::ServiceDiscovery::HttpNamespace": writeServiceDiscoveryHttpNamespace,
@@ -20519,6 +20730,15 @@ function isNestedUndeclared(f) {
20519
20730
  function isUnrevertableNested(f) {
20520
20731
  return isNestedUndeclared(f) && f.path.includes("[");
20521
20732
  }
20733
+ function elbAttributeBagElementOf(f) {
20734
+ const bag = ELB_ATTRIBUTE_BAGS[f.resourceType];
20735
+ if (!bag || !f.path.startsWith(`${bag}[`) || !f.path.endsWith("]")) return void 0;
20736
+ const key = f.path.slice(bag.length + 1, -1);
20737
+ return key ? {
20738
+ prop: bag,
20739
+ key
20740
+ } : void 0;
20741
+ }
20522
20742
  function isManagedPolicyAttachmentMember(f) {
20523
20743
  return f.tier === "undeclared" && f.resourceType === "AWS::IAM::ManagedPolicy" && /^(Roles|Users|Groups)\[.+\]$/.test(f.path);
20524
20744
  }
@@ -20727,7 +20947,9 @@ function buildRevertPlan(findings, baseline, opts = {}) {
20727
20947
  });
20728
20948
  continue;
20729
20949
  }
20730
- if (isUnrevertableNested(f) && !isManagedPolicyAttachmentMember(f) && !isNestedSdkWritable(f)) {
20950
+ const bagElement = elbAttributeBagElementOf(f);
20951
+ 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);
20952
+ if (isUnrevertableNested(f) && !isManagedPolicyAttachmentMember(f) && !isNestedSdkWritable(f) && !bagElementRevertible) {
20731
20953
  notRevertable.push({
20732
20954
  displayId,
20733
20955
  resourceType: f.resourceType,
@@ -20820,7 +21042,7 @@ function buildRevertPlan(findings, baseline, opts = {}) {
20820
21042
  });
20821
21043
  continue;
20822
21044
  }
20823
- const propScoped = !SDK_WRITERS[f.resourceType] && SDK_PROP_WRITERS[f.resourceType]?.[f.path] !== void 0;
21045
+ const propScoped = !SDK_WRITERS[f.resourceType] && SDK_PROP_WRITERS[f.resourceType]?.[bagElement?.prop ?? f.path] !== void 0;
20824
21046
  const nestedScoped = !SDK_WRITERS[f.resourceType] && !propScoped && isNestedSdkWritable(f);
20825
21047
  if (JSON_STRING_PROPS[f.resourceType]?.has(f.path) && !propScoped && !SDK_WRITERS[f.resourceType]) {
20826
21048
  notRevertable.push({
@@ -20872,7 +21094,7 @@ function buildRevertPlan(findings, baseline, opts = {}) {
20872
21094
  }
20873
21095
  const declaredModel = opts.declaredForLogical?.(f.logicalId);
20874
21096
  const op = revertOp(toRevert, recorded, opts.identity, declaredModel);
20875
- const key = `${f.logicalId} ${kind}${propScoped ? ` ${f.path}` : ""}`;
21097
+ const key = `${f.logicalId} ${kind}${propScoped ? ` ${bagElement?.prop ?? f.path}` : ""}`;
20876
21098
  const item = itemsByLogical.get(key) ?? {
20877
21099
  logicalId: f.logicalId,
20878
21100
  displayId,
@@ -20892,6 +21114,7 @@ function buildRevertPlan(findings, baseline, opts = {}) {
20892
21114
  item.ops.push({
20893
21115
  op: "remove",
20894
21116
  path: siblingPointer,
21117
+ contract: true,
20895
21118
  human: `${sibling} -> remove (incompatible with the restored default)`
20896
21119
  });
20897
21120
  }
@@ -20943,11 +21166,17 @@ function derivedRevertDefaultFor(resourceType, path, declared) {
20943
21166
  if (path === "HealthCheckPort") return elbTargetGroupDerivedHealthCheckPort(declared["Protocol"]);
20944
21167
  }
20945
21168
  if (resourceType === "AWS::RDS::DBInstance" && path === "BackupRetentionPeriod") return rdsReplicaDerivedBackupRetention(declared["SourceDBInstanceIdentifier"]);
21169
+ if (resourceType === "AWS::ECS::Service") {
21170
+ if (path === "DeploymentConfiguration") return ecsDaemonDerivedDeploymentConfiguration(declared["SchedulingStrategy"]);
21171
+ if (path === "DeploymentConfiguration.MaximumPercent") return ecsDaemonDerivedMaximumPercent(declared["SchedulingStrategy"]);
21172
+ if (path === "DeploymentConfiguration.MinimumHealthyPercent") return ecsDaemonDerivedMinimumHealthyPercent(declared["SchedulingStrategy"]);
21173
+ }
20946
21174
  if (resourceType === "AWS::Logs::LogGroup" && path === "RetentionInDays") return logsDeliveryDerivedRetention(declared["LogGroupClass"]);
20947
21175
  }
20948
21176
  const REVERT_COMPANION_REMOVES = {
20949
21177
  "AWS::ElasticLoadBalancingV2::TargetGroup\0HealthCheckProtocol": (value) => value === "TCP" ? ["Matcher", "HealthCheckPath"] : [],
20950
- "AWS::EC2::Volume\0VolumeType": (value) => value === "gp2" || value === "standard" || value === "st1" || value === "sc1" ? ["Iops", "Throughput"] : value === "io1" || value === "io2" ? ["Throughput"] : []
21178
+ "AWS::EC2::Volume\0VolumeType": (value) => value === "gp2" || value === "standard" || value === "st1" || value === "sc1" ? ["Iops", "Throughput"] : value === "io1" || value === "io2" ? ["Throughput"] : [],
21179
+ "AWS::ECS::Service\0DeploymentConfiguration": () => ["DesiredCount"]
20951
21180
  };
20952
21181
  function revertOp(f, recorded, identity, declaredModel) {
20953
21182
  const pointer = toPointer(f.path);
@@ -20960,6 +21189,19 @@ function revertOp(f, recorded, identity, declaredModel) {
20960
21189
  human: `${f.path}${f.attributeKey ? `[${f.attributeKey}]` : ""} -> deployed-template value`
20961
21190
  };
20962
21191
  const wasRecorded = recorded.find((a) => a.logicalId === f.logicalId && a.path === f.path);
21192
+ const bagEl = elbAttributeBagElementOf(f);
21193
+ if (bagEl) {
21194
+ const baselineValue = f.desired !== void 0 ? f.desired : wasRecorded?.value;
21195
+ const value = baselineValue !== void 0 ? baselineValue : elbAttributeDefaultsFor(f.resourceType, declaredModel ?? {}, {})[bagEl.key];
21196
+ if (value !== void 0) return {
21197
+ op: "add",
21198
+ path: toPointer(bagEl.prop),
21199
+ value,
21200
+ prior: f.actual,
21201
+ attributeKey: bagEl.key,
21202
+ human: `${bagEl.prop}[${bagEl.key}] -> ${baselineValue !== void 0 ? "baseline value" : "AWS default (undeclared, not in baseline)"}`
21203
+ };
21204
+ }
20963
21205
  if (f.actual === void 0 && f.desired !== void 0) return {
20964
21206
  op: "add",
20965
21207
  path: pointer,
@@ -22247,6 +22489,7 @@ async function revertStack(p) {
22247
22489
  if (item.kind === "delete" || !okIds.has(item.logicalId)) continue;
22248
22490
  for (const op of item.ops) {
22249
22491
  if (op.op !== "remove" && op.op !== "add") continue;
22492
+ if (op.contract) continue;
22250
22493
  const dotted = op.path.replace(/^\//, "").replace(/\//g, ".");
22251
22494
  const key = `${item.logicalId}\0${dotted}`;
22252
22495
  if (!preActual.has(key)) continue;