cdk-real-drift 0.9.0 → 0.9.2
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 +11 -2
- package/dist/cli.js +60 -15
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -283,7 +283,7 @@ snapshots its full live model and watches it, `ignore` accepts it, or `revert`
|
|
|
283
283
|
- **AppSync**: data sources, resolvers, functions
|
|
284
284
|
- **CloudWatch Logs**: metric filters, subscription filters
|
|
285
285
|
- **ELBv2**: listeners, listener rules
|
|
286
|
-
- **EC2**: VPC subnets, route table routes
|
|
286
|
+
- **EC2**: VPC subnets, VPC endpoints, route table routes
|
|
287
287
|
- **ECS**: cluster services
|
|
288
288
|
- **KMS**: key aliases
|
|
289
289
|
- **AppConfig**: application environments, configuration profiles
|
|
@@ -643,7 +643,16 @@ If the whole invocation fails before any stack is reached (bad config, an
|
|
|
643
643
|
un-synthesizable app, or a zero-stack app), stdout is still a valid empty array
|
|
644
644
|
`[]` (exit code non-zero, the reason on stderr) — never empty bytes.
|
|
645
645
|
|
|
646
|
-
|
|
646
|
+
Every successfully-checked stack element carries a `"baseline": <bool>` flag —
|
|
647
|
+
`true` when the stack has a committed `.cdkrd` baseline (its undeclared dimension is
|
|
648
|
+
**watched**), `false` when it has never been recorded. Without a baseline the
|
|
649
|
+
classification shifts: appeared-since-record out-of-band values read as `unrecorded`
|
|
650
|
+
and are excluded from `drifted`, so a QUIET never-recorded stack emits the
|
|
651
|
+
byte-identical `"drifted": 0` of a watched-clean one. A consumer summing `drifted`
|
|
652
|
+
uses `baseline` to tell an UNWATCHED stack from a watched-clean one (#1095). It is
|
|
653
|
+
omitted on the `error` / `stackDeleted` shapes (never reconciled against a baseline).
|
|
654
|
+
|
|
655
|
+
Each stack element is `{ "stack": "<name> (<region>)", "drifted": <n>, "baseline": <bool>, "findings": [...] }`
|
|
647
656
|
(`error` added only on a pre-check failure; `stackDeleted: true` only on a deleted
|
|
648
657
|
stack). Each **finding** has a stable shape:
|
|
649
658
|
|
package/dist/cli.js
CHANGED
|
@@ -18,7 +18,7 @@ import { AppSyncClient, ListApiKeysCommand, ListDataSourcesCommand, ListFunction
|
|
|
18
18
|
import { ApiGatewayV2Client, DeleteAccessLogSettingsCommand, DeleteRouteSettingsCommand, GetAuthorizersCommand as GetAuthorizersCommand$1, GetIntegrationsCommand, GetRoutesCommand, GetStagesCommand as GetStagesCommand$1, UpdateStageCommand } from "@aws-sdk/client-apigatewayv2";
|
|
19
19
|
import { CloudWatchLogsClient, DescribeMetricFiltersCommand, DescribeSubscriptionFiltersCommand, PutBearerTokenAuthenticationCommand, PutMetricFilterCommand } from "@aws-sdk/client-cloudwatch-logs";
|
|
20
20
|
import { CognitoIdentityProviderClient, ListGroupsCommand, ListResourceServersCommand, ListUserPoolClientsCommand } from "@aws-sdk/client-cognito-identity-provider";
|
|
21
|
-
import { DescribeAddressesCommand, DescribeClientVpnAuthorizationRulesCommand, DescribeClientVpnEndpointsCommand, DescribeClientVpnTargetNetworksCommand, DescribeLaunchTemplateVersionsCommand, DescribeNetworkAclsCommand, DescribeRouteTablesCommand, DescribeSubnetsCommand, EC2Client, ModifyClientVpnEndpointCommand } from "@aws-sdk/client-ec2";
|
|
21
|
+
import { DescribeAddressesCommand, DescribeClientVpnAuthorizationRulesCommand, DescribeClientVpnEndpointsCommand, DescribeClientVpnTargetNetworksCommand, DescribeLaunchTemplateVersionsCommand, DescribeNetworkAclsCommand, DescribeRouteTablesCommand, DescribeSubnetsCommand, DescribeVpcEndpointsCommand, EC2Client, ModifyClientVpnEndpointCommand } from "@aws-sdk/client-ec2";
|
|
22
22
|
import { DescribeServicesCommand, ECSClient, ListServicesCommand, UpdateServiceCommand } from "@aws-sdk/client-ecs";
|
|
23
23
|
import { DescribeMountTargetsCommand, EFSClient } from "@aws-sdk/client-efs";
|
|
24
24
|
import { DescribeListenersCommand, DescribeRulesCommand, ElasticLoadBalancingV2Client, GetTrustStoreCaCertificatesBundleCommand, ModifyLoadBalancerAttributesCommand, ModifyTargetGroupAttributesCommand } from "@aws-sdk/client-elastic-load-balancing-v2";
|
|
@@ -7444,6 +7444,20 @@ function diffVpcChildren(input) {
|
|
|
7444
7444
|
}
|
|
7445
7445
|
return added;
|
|
7446
7446
|
}
|
|
7447
|
+
function diffVpcEndpointChildren(input) {
|
|
7448
|
+
const declared = new Set(input.declaredEndpointIds);
|
|
7449
|
+
const added = [];
|
|
7450
|
+
for (const e of input.liveEndpoints) {
|
|
7451
|
+
if (declared.has(e.id)) continue;
|
|
7452
|
+
added.push({
|
|
7453
|
+
resourceType: "AWS::EC2::VPCEndpoint",
|
|
7454
|
+
identifier: e.id,
|
|
7455
|
+
label: e.label ?? e.id,
|
|
7456
|
+
live: { Id: e.id }
|
|
7457
|
+
});
|
|
7458
|
+
}
|
|
7459
|
+
return added;
|
|
7460
|
+
}
|
|
7447
7461
|
async function pageSubnets(client, vpcId) {
|
|
7448
7462
|
const out = [];
|
|
7449
7463
|
let next;
|
|
@@ -7460,22 +7474,52 @@ async function pageSubnets(client, vpcId) {
|
|
|
7460
7474
|
} while (next);
|
|
7461
7475
|
return out;
|
|
7462
7476
|
}
|
|
7477
|
+
async function pageVpcEndpoints(client, vpcId) {
|
|
7478
|
+
const out = [];
|
|
7479
|
+
let next;
|
|
7480
|
+
do {
|
|
7481
|
+
const res = await client.send(new DescribeVpcEndpointsCommand({
|
|
7482
|
+
Filters: [{
|
|
7483
|
+
Name: "vpc-id",
|
|
7484
|
+
Values: [vpcId]
|
|
7485
|
+
}],
|
|
7486
|
+
NextToken: next
|
|
7487
|
+
}));
|
|
7488
|
+
out.push(...res.VpcEndpoints ?? []);
|
|
7489
|
+
next = res.NextToken;
|
|
7490
|
+
} while (next);
|
|
7491
|
+
return out;
|
|
7492
|
+
}
|
|
7463
7493
|
async function enumerateVpcChildren(ctx) {
|
|
7464
7494
|
const { parent, desired, region } = ctx;
|
|
7465
7495
|
const vpcId = parent.physicalId;
|
|
7466
7496
|
if (!vpcId) return [];
|
|
7467
7497
|
const declaredSubnetIds = [];
|
|
7468
|
-
|
|
7469
|
-
|
|
7470
|
-
|
|
7471
|
-
|
|
7472
|
-
|
|
7473
|
-
|
|
7474
|
-
|
|
7475
|
-
|
|
7476
|
-
|
|
7477
|
-
}))
|
|
7498
|
+
const declaredEndpointIds = [];
|
|
7499
|
+
for (const r of desired.resources) {
|
|
7500
|
+
if (!parentRefMatches(r.declared.VpcId, vpcId) || !r.physicalId) continue;
|
|
7501
|
+
if (r.resourceType === "AWS::EC2::Subnet") declaredSubnetIds.push(r.physicalId);
|
|
7502
|
+
else if (r.resourceType === "AWS::EC2::VPCEndpoint") declaredEndpointIds.push(r.physicalId);
|
|
7503
|
+
}
|
|
7504
|
+
const client = new EC2Client({
|
|
7505
|
+
region,
|
|
7506
|
+
...READ_RETRY
|
|
7478
7507
|
});
|
|
7508
|
+
const liveSubnets = (await pageSubnets(client, vpcId)).filter((s) => typeof s.SubnetId === "string").map((s) => ({
|
|
7509
|
+
id: s.SubnetId,
|
|
7510
|
+
label: s.CidrBlock ? `${s.CidrBlock}` : s.SubnetId
|
|
7511
|
+
}));
|
|
7512
|
+
const liveEndpoints = (await pageVpcEndpoints(client, vpcId)).filter((e) => typeof e.VpcEndpointId === "string").map((e) => ({
|
|
7513
|
+
id: e.VpcEndpointId,
|
|
7514
|
+
label: e.ServiceName ?? e.VpcEndpointId
|
|
7515
|
+
}));
|
|
7516
|
+
return [...diffVpcChildren({
|
|
7517
|
+
declaredSubnetIds,
|
|
7518
|
+
liveSubnets
|
|
7519
|
+
}), ...diffVpcEndpointChildren({
|
|
7520
|
+
declaredEndpointIds,
|
|
7521
|
+
liveEndpoints
|
|
7522
|
+
})];
|
|
7479
7523
|
}
|
|
7480
7524
|
function diffRouteTableChildren(input) {
|
|
7481
7525
|
const { routeTableId, declaredCidrs, liveRoutes, hasUnresolvedDeclaredRoute } = input;
|
|
@@ -15447,7 +15491,7 @@ function deletedStackReport(label) {
|
|
|
15447
15491
|
stackDeleted: true
|
|
15448
15492
|
};
|
|
15449
15493
|
}
|
|
15450
|
-
function buildStackJson(rawFindings, header) {
|
|
15494
|
+
function buildStackJson(rawFindings, header, hasBaseline) {
|
|
15451
15495
|
const findings = annotateHints(rawFindings);
|
|
15452
15496
|
const isDriftHere = (f) => DRIFT_TIERS.includes(f.tier) && !f.unrecorded;
|
|
15453
15497
|
const drifted = findings.filter(isDriftHere).length;
|
|
@@ -15455,7 +15499,8 @@ function buildStackJson(rawFindings, header) {
|
|
|
15455
15499
|
json: {
|
|
15456
15500
|
stack: header,
|
|
15457
15501
|
drifted,
|
|
15458
|
-
findings
|
|
15502
|
+
findings,
|
|
15503
|
+
baseline: hasBaseline === true
|
|
15459
15504
|
},
|
|
15460
15505
|
code: drifted === 0 ? 0 : 1
|
|
15461
15506
|
};
|
|
@@ -16483,7 +16528,7 @@ async function runCheck(args) {
|
|
|
16483
16528
|
const reportHeader = `${posPrefix}${stackName} (${region})`;
|
|
16484
16529
|
let code;
|
|
16485
16530
|
if (a.json) {
|
|
16486
|
-
const { json, code: jsonCode } = buildStackJson(reconciled, reportHeader);
|
|
16531
|
+
const { json, code: jsonCode } = buildStackJson(reconciled, reportHeader, baseline !== void 0);
|
|
16487
16532
|
jsonReports.push(json);
|
|
16488
16533
|
code = jsonCode;
|
|
16489
16534
|
} else code = report(reconciled, reportHeader, {
|
|
@@ -16512,7 +16557,7 @@ async function runCheck(args) {
|
|
|
16512
16557
|
verbose: a.verbose,
|
|
16513
16558
|
positionPrefix: posPrefix
|
|
16514
16559
|
});
|
|
16515
|
-
else if (!baseline && !hasUnrecorded && !a.
|
|
16560
|
+
else if (!baseline && !hasUnrecorded && !a.showAll && !a.preDeploy) console.error(`note: ${stackName}: no .cdkrd baseline yet — run \`cdkrd record\` to establish one (future out-of-band changes then report as drift).`);
|
|
16516
16561
|
if (code === 1) anyDrift = true;
|
|
16517
16562
|
worst = Math.max(worst, finalCheckExit(code, a.fail));
|
|
16518
16563
|
worst = Math.max(worst, strictCoverageExit(a.strict, gathered.findings, desired.resources));
|