cdk-real-drift 0.12.70 → 0.12.72

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
@@ -3306,7 +3306,6 @@ const EB_OPTION_VALUE_INDEPENDENT = new Set([
3306
3306
  "aws:cloudformation:template:parameter|HooksPkgUrl",
3307
3307
  "aws:cloudformation:template:parameter|InstanceTypeFamily",
3308
3308
  "aws:cloudformation:template:parameter|EnvironmentVariables",
3309
- "aws:ec2:instances|InstanceTypes",
3310
3309
  "aws:ec2:instances|SupportedArchitectures",
3311
3310
  "aws:elasticbeanstalk:application:environment|PYTHONPATH",
3312
3311
  "aws:elasticbeanstalk:healthreporting:system|ConfigDocument",
@@ -3322,6 +3321,14 @@ function isAllEbGeneratedGroups(value) {
3322
3321
  if (typeof value !== "string" || value === "") return false;
3323
3322
  return value.split(",").every((el) => isEbGeneratedGroup(el));
3324
3323
  }
3324
+ const EB_INSTANCE_TYPES_DEFAULT_BY_ARCH = {
3325
+ x86_64: new Set(["t3.micro", "t3.small"]),
3326
+ arm64: new Set(["t4g.micro", "t4g.small"])
3327
+ };
3328
+ function ebInstanceTypesDefaultSet(supportedArchitectures) {
3329
+ const arch = typeof supportedArchitectures === "string" && supportedArchitectures.trim() !== "" ? supportedArchitectures.split(",")[0]?.trim() : "x86_64";
3330
+ return arch === void 0 ? EB_INSTANCE_TYPES_DEFAULT_BY_ARCH.x86_64 : EB_INSTANCE_TYPES_DEFAULT_BY_ARCH[arch];
3331
+ }
3325
3332
  function ebOptionSettingTier(namespace, optionName, value, envType, siblingOption) {
3326
3333
  if (value == null || value === "") return "atDefault";
3327
3334
  const key = `${String(namespace)}|${String(optionName)}`;
@@ -3332,6 +3339,13 @@ function ebOptionSettingTier(namespace, optionName, value, envType, siblingOptio
3332
3339
  if (first !== void 0) return first === value ? "atDefault" : "undeclared";
3333
3340
  return "atDefault";
3334
3341
  }
3342
+ if (key === "aws:ec2:instances|InstanceTypes") {
3343
+ const defaults = ebInstanceTypesDefaultSet(siblingOption?.("aws:ec2:instances", "SupportedArchitectures"));
3344
+ if (defaults === void 0) return "atDefault";
3345
+ const types = String(value).split(",").map((t) => t.trim()).filter((t) => t !== "");
3346
+ if (types.length === 0) return "atDefault";
3347
+ return types.every((t) => defaults.has(t)) ? "atDefault" : "undeclared";
3348
+ }
3335
3349
  if (EB_OPTION_VALUE_INDEPENDENT.has(key)) return "atDefault";
3336
3350
  const derived = EB_OPTION_DERIVED[key];
3337
3351
  if (derived) return derived[envType] === value ? "atDefault" : "undeclared";
@@ -4222,9 +4236,23 @@ const UNORDERED_NESTED_OBJECT_ARRAY_PATHS = {
4222
4236
  "AWS::AutoScaling::AutoScalingGroup": new Set(["MetricsCollection.Metrics", "NotificationConfigurations.NotificationTypes"]),
4223
4237
  "AWS::Lambda::EventSourceMapping": new Set(["SelfManagedEventSource.Endpoints.KafkaBootstrapServers"])
4224
4238
  };
4225
- function sortNestedObjectArrays(value, subPaths) {
4239
+ const NESTED_OBJECT_ARRAY_IDENTITY = {
4240
+ "AWS::Bedrock::Guardrail": {
4241
+ "ContentPolicyConfig.FiltersConfig": "Type",
4242
+ "TopicPolicyConfig.TopicsConfig": "Name",
4243
+ "SensitiveInformationPolicyConfig.PiiEntitiesConfig": "Type",
4244
+ "SensitiveInformationPolicyConfig.RegexesConfig": "Name",
4245
+ "WordPolicyConfig.WordsConfig": "Text"
4246
+ },
4247
+ "AWS::ECS::TaskDefinition": {
4248
+ "ContainerDefinitions.PortMappings": "ContainerPort",
4249
+ "ContainerDefinitions.VolumesFrom": "SourceContainer"
4250
+ },
4251
+ "AWS::Backup::BackupSelection": { "BackupSelection.ListOfTags": "ConditionKey" }
4252
+ };
4253
+ function sortNestedObjectArrays(value, subPaths, identityBySubPath) {
4226
4254
  if (subPaths.length === 0 || value === null || typeof value !== "object") return value;
4227
- if (Array.isArray(value)) return value.map((el) => sortNestedObjectArrays(el, subPaths));
4255
+ if (Array.isArray(value)) return value.map((el) => sortNestedObjectArrays(el, subPaths, identityBySubPath));
4228
4256
  const clone = structuredClone(value);
4229
4257
  for (const sub of subPaths) {
4230
4258
  const segs = sub.split(".");
@@ -4234,7 +4262,7 @@ function sortNestedObjectArrays(value, subPaths) {
4234
4262
  cur = next !== null && typeof next === "object" ? next : void 0;
4235
4263
  }
4236
4264
  const last = segs[segs.length - 1];
4237
- if (cur && Array.isArray(cur[last])) cur[last] = sortUnorderedObjectArray(cur[last]);
4265
+ if (cur && Array.isArray(cur[last])) cur[last] = sortUnorderedObjectArray(cur[last], identityBySubPath?.[sub]);
4238
4266
  }
4239
4267
  return clone;
4240
4268
  }
@@ -5862,7 +5890,6 @@ function cloneDeepWithSymbols(v) {
5862
5890
  }
5863
5891
  const isPolicyStatementArray = (arr) => arr.length > 0 && arr.every((el) => isNestedObject(el) && "Effect" in el);
5864
5892
  const isInlinePolicyArray = (arr) => arr.length > 0 && arr.every((el) => isNestedObject(el) && "PolicyDocument" in el);
5865
- const isIdentitySortedObjectArray = (arr) => arr.length > 0 && identityField(arr) !== void 0;
5866
5893
  function isPolicySubsetOf(sub, sup) {
5867
5894
  for (const [k, v] of Object.entries(sub)) {
5868
5895
  if (!(k in sup)) return false;
@@ -5980,6 +6007,31 @@ function remapSortedIndexToDeclared(path, arrayKey, sortedDeclared, rawDeclared)
5980
6007
  const rawIdx = rawDeclared.findIndex((e) => deepEqual(e, el));
5981
6008
  return rawIdx < 0 ? path : `${arrayKey}.${rawIdx}${m[2]}`;
5982
6009
  }
6010
+ function crossedSortedArrayRevert(v, k, driftPath, resourceType, nestedSubPaths, nestedIdentityBySubPath) {
6011
+ if (!driftPath.startsWith(`${k}.`)) return void 0;
6012
+ const orderSigKeys = ORDER_SIGNIFICANT_ARRAY_KEYS[resourceType];
6013
+ const orderSigPaths = ORDER_SIGNIFICANT_PATHS[resourceType];
6014
+ const rel = driftPath.slice(k.length + 1).split(".");
6015
+ let cur = v;
6016
+ let arrPathRel = "";
6017
+ let parentKey = k;
6018
+ for (const seg of rel) if (Array.isArray(cur)) {
6019
+ const arr = cur;
6020
+ if (!/^\d+$/.test(seg)) return void 0;
6021
+ const fullPath = arrPathRel ? `${k}.${arrPathRel}` : k;
6022
+ const orderSig = (orderSigKeys?.has(parentKey) || orderSigPaths?.has(fullPath)) ?? false;
6023
+ const idField = identityField(arr) ?? nestedIdentityBySubPath[arrPathRel];
6024
+ if (!orderSig && (idField !== void 0 || nestedSubPaths.includes(arrPathRel)) && arr.length >= 2) return {
6025
+ path: fullPath,
6026
+ value: arr
6027
+ };
6028
+ cur = arr[Number(seg)];
6029
+ } else if (cur !== null && typeof cur === "object") {
6030
+ cur = cur[seg];
6031
+ arrPathRel = arrPathRel ? `${arrPathRel}.${seg}` : seg;
6032
+ parentKey = seg;
6033
+ } else return;
6034
+ }
5983
6035
  const S3_NOTIF_FILTER_RULE_NAMES = {
5984
6036
  prefix: "prefix",
5985
6037
  suffix: "suffix",
@@ -6744,6 +6796,8 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
6744
6796
  const nestedUnordered = UNORDERED_NESTED_OBJECT_ARRAY_PATHS[resourceType];
6745
6797
  const orderSigPathsForType = ORDER_SIGNIFICANT_PATHS[resourceType];
6746
6798
  const nestedSubPaths = [...new Set([...nestedUnordered ?? [], ...schema.unorderedObjectArrayPaths ?? []].filter((p) => p.startsWith(`${k}.`) && !orderSigPathsForType?.has(p)).map((p) => p.slice(k.length + 1)))];
6799
+ const nestedIdentityBySubPath = {};
6800
+ for (const [fullPath, idf] of Object.entries(NESTED_OBJECT_ARRAY_IDENTITY[resourceType] ?? {})) if (fullPath.startsWith(`${k}.`)) nestedIdentityBySubPath[fullPath.slice(k.length + 1)] = idf;
6747
6801
  let declaredVal = v;
6748
6802
  let liveVal = live[k];
6749
6803
  let declaredRemapSource;
@@ -6796,14 +6850,14 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
6796
6850
  declaredVal = declaredSorted;
6797
6851
  liveVal = liveAligned;
6798
6852
  } else if (unorderedObjArray) {
6799
- const declaredNestedSorted = nestedSubPaths.length > 0 ? sortNestedObjectArrays(v, nestedSubPaths) : v;
6853
+ const declaredNestedSorted = nestedSubPaths.length > 0 ? sortNestedObjectArrays(v, nestedSubPaths, nestedIdentityBySubPath) : v;
6800
6854
  const idField = UNORDERED_OBJECT_ARRAY_IDENTITY[resourceType]?.[k];
6801
6855
  declaredVal = sortUnorderedObjectArray(declaredNestedSorted, idField);
6802
- liveVal = sortUnorderedObjectArray(nestedSubPaths.length > 0 ? sortNestedObjectArrays(live[k], nestedSubPaths) : live[k], idField);
6856
+ liveVal = sortUnorderedObjectArray(nestedSubPaths.length > 0 ? sortNestedObjectArrays(live[k], nestedSubPaths, nestedIdentityBySubPath) : live[k], idField);
6803
6857
  if (Array.isArray(declaredNestedSorted)) declaredRemapSource = declaredNestedSorted;
6804
6858
  } else if (nestedSubPaths.length > 0) {
6805
- declaredVal = sortNestedObjectArrays(v, nestedSubPaths);
6806
- liveVal = sortNestedObjectArrays(live[k], nestedSubPaths);
6859
+ declaredVal = sortNestedObjectArrays(v, nestedSubPaths, nestedIdentityBySubPath);
6860
+ liveVal = sortNestedObjectArrays(live[k], nestedSubPaths, nestedIdentityBySubPath);
6807
6861
  }
6808
6862
  for (const d of calculateResourceDrift({ [k]: declaredVal }, { [k]: liveVal })) {
6809
6863
  if (d.stateValue === UNRESOLVED || hasUnresolved(d.stateValue)) continue;
@@ -6894,17 +6948,14 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
6894
6948
  const transformExpr = schema.propertyTransforms?.[d.path] ?? schema.propertyTransforms?.[d.path.replace(/\.\d+(?=\.|$)/g, ".*")];
6895
6949
  if (transformExpr !== void 0 && matchesPropertyTransform(transformExpr, d.stateValue, resolveParentObject(declared, d.path), declared, d.awsValue, d.path.split(".").at(-1) ?? d.path)) continue;
6896
6950
  if (schema.propertyTransforms !== void 0 && transformExpr === void 0 && matchesAncestorPropertyTransform(schema.propertyTransforms, d.path, declared, live)) continue;
6897
- const identitySortedWhole = !unorderedObjArray && Array.isArray(v) && isIdentitySortedObjectArray(v) && d.path.startsWith(`${k}.`);
6951
+ const crossedSorted = unorderedObjArray ? void 0 : crossedSortedArrayRevert(v, k, d.path, resourceType, nestedSubPaths, nestedIdentityBySubPath);
6898
6952
  const unorderedExtra = unorderedObjArray && Array.isArray(declaredVal) && declaredRemapSource ? {
6899
6953
  path: remapSortedIndexToDeclared(d.path, k, declaredVal, declaredRemapSource),
6900
6954
  wholeArrayRevert: {
6901
6955
  path: k,
6902
6956
  value: v
6903
6957
  }
6904
- } : identitySortedWhole ? { wholeArrayRevert: {
6905
- path: k,
6906
- value: v
6907
- } } : {};
6958
+ } : crossedSorted ? { wholeArrayRevert: crossedSorted } : {};
6908
6959
  pushDeclaredFinding(findings, {
6909
6960
  logicalId,
6910
6961
  resourceType,