cdk-real-drift 0.12.66 → 0.12.67

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
@@ -496,6 +496,15 @@ from a **changed local `Default`** is applied only if you pass
496
496
  `--parameters <key>=<value>` / `--no-previous-parameters` — `check` prints a
497
497
  stderr note naming each such parameter and both values.
498
498
 
499
+ A second caveat on **server-side transforms** (SAM `AWS::Serverless-2016-10-31`,
500
+ `AWS::LanguageExtensions`, macros): CloudFormation expands these in the cloud at
501
+ deploy time, but `--pre-deploy` compares against your **local, unprocessed** synth
502
+ template. So under `--pre-deploy` every `AWS::Serverless::*` resource is `skipped`
503
+ (its declared props are not compared) and transform-generated resources are
504
+ invisible — `check` prints a per-stack stderr note when it sees a transformed
505
+ template. Normal `check` (against the deployed, already-**processed** template) has
506
+ no such gap and compares transformed stacks fully; prefer it for SAM/macro apps.
507
+
499
508
  ### Ignoring externally-managed properties
500
509
 
501
510
  Some properties are _legitimately_ rewritten by another system, such as Application
package/dist/cli.js CHANGED
@@ -1680,6 +1680,7 @@ function resolve$1(node, ctx, inCondition = false) {
1680
1680
  break;
1681
1681
  }
1682
1682
  }
1683
+ if ("Fn::Transform" in obj) return UNRESOLVED;
1683
1684
  const out = {};
1684
1685
  for (const [kk, vv] of Object.entries(obj)) out[kk] = resolve$1(vv, ctx, inCondition);
1685
1686
  return out;
@@ -3419,7 +3420,6 @@ const VALUE_INDEPENDENT_DEFAULT_TOPLEVEL_PATHS = {
3419
3420
  "AWS::EC2::VPCEndpoint": new Set(["ServiceRegion", "DnsOptions"]),
3420
3421
  "AWS::EC2::VPCPeeringConnection": new Set(["PeerRegion"]),
3421
3422
  "AWS::EC2::VPCCidrBlock": new Set(["Ipv6CidrBlock", "Ipv6CidrBlockNetworkBorderGroup"]),
3422
- "AWS::EC2::TransitGateway": new Set(["AssociationDefaultRouteTableId", "PropagationDefaultRouteTableId"]),
3423
3423
  "AWS::Grafana::Workspace": new Set(["GrafanaVersion"]),
3424
3424
  "AWS::Bedrock::AgentAlias": new Set(["RoutingConfiguration"]),
3425
3425
  "AWS::AppSync::ApiKey": new Set(["Expires"]),
@@ -3427,11 +3427,7 @@ const VALUE_INDEPENDENT_DEFAULT_TOPLEVEL_PATHS = {
3427
3427
  "AWS::StepFunctions::StateMachineVersion": new Set(["StateMachineRevisionId"]),
3428
3428
  "AWS::StepFunctions::StateMachineAlias": new Set(["StateMachineArn"]),
3429
3429
  "AWS::AutoScaling::ScheduledAction": new Set(["StartTime"]),
3430
- "AWS::RedshiftServerless::Workgroup": new Set([
3431
- "ConfigParameters",
3432
- "SecurityGroupIds",
3433
- "SubnetIds"
3434
- ]),
3430
+ "AWS::RedshiftServerless::Workgroup": new Set(["ConfigParameters"]),
3435
3431
  "AWS::CloudFormation::Stack": new Set(["TemplateBody", "Capabilities"])
3436
3432
  };
3437
3433
  function isPhysicalIdSegment(value, physicalId) {
@@ -4593,6 +4589,21 @@ function changedDefaultParamInfo(template, stackParams, stackName) {
4593
4589
  const more = diverged.length > shown.length ? `, …(+${diverged.length - shown.length} more)` : "";
4594
4590
  return `warning: ${stackName}: ${diverged.length} local parameter(s) changed their Default vs the deployed value — the preview resolves them from the NEW local Default, but a plain \`cdk deploy\` KEEPS the deployed value (UsePreviousValue) unless \`--parameters <key>=<value>\` / \`--no-previous-parameters\` is passed: ${shown.join(", ")}${more}`;
4595
4591
  }
4592
+ function transformStackWarning(template, stackName) {
4593
+ const rawTransform = template.Transform;
4594
+ const transforms = (Array.isArray(rawTransform) ? rawTransform : [rawTransform]).filter((t) => typeof t === "string" && t.length > 0).sort();
4595
+ const resources = template.Resources ?? {};
4596
+ const serverless = Object.entries(resources).filter(([, def]) => typeof def?.Type === "string" && def.Type.startsWith("AWS::Serverless::")).map(([logicalId]) => logicalId).sort();
4597
+ if (transforms.length === 0 && serverless.length === 0) return null;
4598
+ const parts = [];
4599
+ if (transforms.length > 0) parts.push(`Transform ${transforms.join(", ")}`);
4600
+ if (serverless.length > 0) {
4601
+ const shown = serverless.slice(0, 10);
4602
+ const more = serverless.length > shown.length ? `, …(+${serverless.length - shown.length} more)` : "";
4603
+ parts.push(`${serverless.length} AWS::Serverless::* resource(s): ${shown.join(", ")}${more}`);
4604
+ }
4605
+ return `warning: ${stackName}: --pre-deploy CANNOT process server-side transforms — CDK's local synth output is UNPROCESSED, so transform-expanded resources are NOT previewed (${parts.join("; ")}). Each AWS::Serverless::* resource is \`skipped\` (its declared props are not compared) and any transform-generated resource is invisible. Run \`check\` WITHOUT --pre-deploy (the deployed, already-processed template) for a full comparison of a transformed stack.`;
4606
+ }
4596
4607
  function partitionForRegion(region) {
4597
4608
  if (region.startsWith("us-gov-")) return {
4598
4609
  partition: "aws-us-gov",
@@ -4767,7 +4778,10 @@ async function listStackResources(client, stackName) {
4767
4778
  }
4768
4779
  async function loadDesired(client, stackName, region, templateOverride, recoveryTemplate) {
4769
4780
  const [tmplRes, stkRes, { physIds, typeOf: deployedTypeOf }] = await Promise.all([
4770
- templateOverride ? Promise.resolve({ TemplateBody: void 0 }) : client.send(new GetTemplateCommand({ StackName: stackName })),
4781
+ templateOverride ? Promise.resolve({ TemplateBody: void 0 }) : client.send(new GetTemplateCommand({
4782
+ StackName: stackName,
4783
+ TemplateStage: "Processed"
4784
+ })),
4771
4785
  client.send(new DescribeStacksCommand({ StackName: stackName })),
4772
4786
  listStackResources(client, stackName)
4773
4787
  ]);
@@ -4796,6 +4810,8 @@ async function loadDesired(client, stackName, region, templateOverride, recovery
4796
4810
  if (noValueInfo) console.error(noValueInfo);
4797
4811
  const changedDefaultInfo = changedDefaultParamInfo(template, stackParams, stackName);
4798
4812
  if (changedDefaultInfo) console.error(changedDefaultInfo);
4813
+ const transformInfo = transformStackWarning(template, stackName);
4814
+ if (transformInfo) console.error(transformInfo);
4799
4815
  }
4800
4816
  const templateResourcesForTypeCheck = template.Resources ?? {};
4801
4817
  const typeChanged = new Set(typeChangedResources(templateResourcesForTypeCheck, deployedTypeOf));
@@ -5486,8 +5502,26 @@ const DEFAULT_SG_LIST_PATHS = {
5486
5502
  "AWS::ElasticLoadBalancingV2::LoadBalancer": "SecurityGroups",
5487
5503
  "AWS::EC2::NetworkInterface": "GroupSet",
5488
5504
  "AWS::Neptune::DBCluster": "VpcSecurityGroupIds",
5489
- "AWS::AmazonMQ::Broker": "SecurityGroups"
5505
+ "AWS::AmazonMQ::Broker": "SecurityGroups",
5506
+ "AWS::RedshiftServerless::Workgroup": "SecurityGroupIds"
5490
5507
  };
5508
+ /** #1269 fold decision for an UNDECLARED default-SUBNET list (RedshiftServerless Workgroup
5509
+ * SubnetIds). Unlike the SG gate (which folds only a SINGLE default SG), a workgroup placed into
5510
+ * the default VPC reads back ALL of that VPC's subnets, so the clean-deploy list has MANY
5511
+ * elements — fold when EVERY element is a known default-VPC subnet; surface if ANY subnet is
5512
+ * outside the default VPC (an out-of-band re-placement, e.g. into a public subnet).
5513
+ * - `true` → FOLD (atDefault): every live subnet is a default-VPC subnet, OR the prefetch is
5514
+ * unavailable (fail OPEN — no ec2:DescribeSubnets / lookup failed / empty).
5515
+ * - `false` → SURFACE (undeclared): at least one live subnet is NOT a default-VPC subnet.
5516
+ * Pure; `defaultSubnetIds` is the resolved set of default-VPC subnet ids (undefined/empty when
5517
+ * unresolved). */
5518
+ function shouldFoldDefaultSubnetList(resourceType, key, liveValue, defaultSubnetIds) {
5519
+ if (DEFAULT_SUBNET_LIST_PATHS[resourceType] !== key) return false;
5520
+ if (!defaultSubnetIds || defaultSubnetIds.size === 0) return true;
5521
+ if (!Array.isArray(liveValue)) return true;
5522
+ return liveValue.every((s) => typeof s === "string" && defaultSubnetIds.has(s));
5523
+ }
5524
+ const DEFAULT_SUBNET_LIST_PATHS = { "AWS::RedshiftServerless::Workgroup": "SubnetIds" };
5491
5525
  /** #889 fold decision for an UNDECLARED default-SG list (ALB SecurityGroups / ENI GroupSet).
5492
5526
  * Returns whether the value-independent fold should still apply for this live value:
5493
5527
  * - `true` → FOLD (atDefault): the live list is a single VPC-default SG id, OR the prefetch is
@@ -6916,6 +6950,29 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
6916
6950
  });
6917
6951
  continue;
6918
6952
  }
6953
+ if (DEFAULT_SUBNET_LIST_PATHS[resourceType] === k && !isTrivialEmpty(v)) {
6954
+ findings.push({
6955
+ tier: shouldFoldDefaultSubnetList(resourceType, k, v, opts.defaultSubnetIds) ? "atDefault" : "undeclared",
6956
+ logicalId,
6957
+ resourceType,
6958
+ path: k,
6959
+ actual: v
6960
+ });
6961
+ continue;
6962
+ }
6963
+ if (resourceType === "AWS::EC2::TransitGateway" && (k === "AssociationDefaultRouteTableId" || k === "PropagationDefaultRouteTableId") && typeof v === "string") {
6964
+ const assoc = live.AssociationDefaultRouteTableId;
6965
+ const prop = live.PropagationDefaultRouteTableId;
6966
+ const bothPresentAndDiffer = typeof assoc === "string" && typeof prop === "string" && assoc !== prop;
6967
+ findings.push({
6968
+ tier: bothPresentAndDiffer ? "undeclared" : "atDefault",
6969
+ logicalId,
6970
+ resourceType,
6971
+ path: k,
6972
+ actual: v
6973
+ });
6974
+ continue;
6975
+ }
6919
6976
  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)) {
6920
6977
  findings.push({
6921
6978
  tier: "atDefault",
@@ -12288,8 +12345,10 @@ const DEFAULT_SG_LIST_TYPES = new Set([
12288
12345
  "AWS::ElasticLoadBalancingV2::LoadBalancer",
12289
12346
  "AWS::EC2::NetworkInterface",
12290
12347
  "AWS::Neptune::DBCluster",
12291
- "AWS::AmazonMQ::Broker"
12348
+ "AWS::AmazonMQ::Broker",
12349
+ "AWS::RedshiftServerless::Workgroup"
12292
12350
  ]);
12351
+ const DEFAULT_SUBNET_LIST_TYPES = new Set(["AWS::RedshiftServerless::Workgroup"]);
12293
12352
  const defaultSgIdsCache = /* @__PURE__ */ new Map();
12294
12353
  async function fetchDefaultSgIds(region) {
12295
12354
  const cached = defaultSgIdsCache.get(region);
@@ -12319,6 +12378,35 @@ async function fetchDefaultSgIds(region) {
12319
12378
  defaultSgIdsCache.set(region, ids);
12320
12379
  return ids;
12321
12380
  }
12381
+ const defaultSubnetIdsCache = /* @__PURE__ */ new Map();
12382
+ async function fetchDefaultVpcSubnetIds(region) {
12383
+ const cached = defaultSubnetIdsCache.get(region);
12384
+ if (cached) return cached;
12385
+ const ids = /* @__PURE__ */ new Set();
12386
+ try {
12387
+ const c = new EC2Client({
12388
+ region,
12389
+ ...READ_RETRY
12390
+ });
12391
+ let token;
12392
+ do {
12393
+ const r = await c.send(new DescribeSubnetsCommand({
12394
+ Filters: [{
12395
+ Name: "default-for-az",
12396
+ Values: ["true"]
12397
+ }],
12398
+ NextToken: token,
12399
+ MaxResults: 1e3
12400
+ }));
12401
+ for (const s of r.Subnets ?? []) if (s.SubnetId) ids.add(s.SubnetId);
12402
+ token = r.NextToken;
12403
+ } while (token);
12404
+ } catch {
12405
+ return ids;
12406
+ }
12407
+ defaultSubnetIdsCache.set(region, ids);
12408
+ return ids;
12409
+ }
12322
12410
  const kmsDeniedWarned = /* @__PURE__ */ new Set();
12323
12411
  const kmsTransientWarned = /* @__PURE__ */ new Set();
12324
12412
  const POOL_SIZE = 6;
@@ -12889,12 +12977,15 @@ async function gatherFindings(stackName, region, templateOverride, recoveryTempl
12889
12977
  }
12890
12978
  let defaultSgIds = /* @__PURE__ */ new Set();
12891
12979
  if (desired.resources.some((r) => DEFAULT_SG_LIST_TYPES.has(r.resourceType))) defaultSgIds = await fetchDefaultSgIds(region);
12980
+ let defaultSubnetIds = /* @__PURE__ */ new Set();
12981
+ if (desired.resources.some((r) => DEFAULT_SUBNET_LIST_TYPES.has(r.resourceType))) defaultSubnetIds = await fetchDefaultVpcSubnetIds(region);
12892
12982
  const classifyOpts = {
12893
12983
  accountId: desired.accountId,
12894
12984
  region,
12895
12985
  kmsAliasTargets,
12896
12986
  stackTags: desired.stackTags ?? {},
12897
12987
  defaultSgIds,
12988
+ defaultSubnetIds,
12898
12989
  oaiCanonicalIds,
12899
12990
  siblingSgRules: buildSiblingSgRules(desired),
12900
12991
  siblingEventBusPolicies: buildSiblingEventBusPolicies(desired),
@@ -12960,12 +13051,15 @@ async function regatherTouched(gathered, touched, region) {
12960
13051
  const oaiCanonicalIds = buildOaiCanonicalIds(desired);
12961
13052
  let defaultSgIds = /* @__PURE__ */ new Set();
12962
13053
  if (targets.some((r) => DEFAULT_SG_LIST_TYPES.has(r.resourceType))) defaultSgIds = await fetchDefaultSgIds(region);
13054
+ let defaultSubnetIds = /* @__PURE__ */ new Set();
13055
+ if (targets.some((r) => DEFAULT_SUBNET_LIST_TYPES.has(r.resourceType))) defaultSubnetIds = await fetchDefaultVpcSubnetIds(region);
12963
13056
  const classifyOpts = {
12964
13057
  accountId: desired.accountId,
12965
13058
  region,
12966
13059
  kmsAliasTargets,
12967
13060
  stackTags: desired.stackTags ?? {},
12968
13061
  defaultSgIds,
13062
+ defaultSubnetIds,
12969
13063
  oaiCanonicalIds,
12970
13064
  siblingSgRules: buildSiblingSgRules(desired),
12971
13065
  siblingEventBusPolicies: buildSiblingEventBusPolicies(desired),