cdk-real-drift 0.2.75 → 0.2.77
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 +82 -16
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -19,13 +19,13 @@ import { DescribeMountTargetsCommand, EFSClient } from "@aws-sdk/client-efs";
|
|
|
19
19
|
import { DescribeListenersCommand, DescribeRulesCommand, ElasticLoadBalancingV2Client, GetTrustStoreCaCertificatesBundleCommand, ModifyLoadBalancerAttributesCommand, ModifyTargetGroupAttributesCommand } from "@aws-sdk/client-elastic-load-balancing-v2";
|
|
20
20
|
import { DescribeEventBusCommand, EventBridgeClient, ListRulesCommand, PutPermissionCommand } from "@aws-sdk/client-eventbridge";
|
|
21
21
|
import { GetPolicyCommand, LambdaClient, ListAliasesCommand as ListAliasesCommand$1, ListEventSourceMappingsCommand, ListFunctionUrlConfigsCommand, ListVersionsByFunctionCommand } from "@aws-sdk/client-lambda";
|
|
22
|
-
import { DescribeDBInstancesCommand, RDSClient } from "@aws-sdk/client-rds";
|
|
22
|
+
import { DescribeDBClustersCommand, DescribeDBInstancesCommand, RDSClient } from "@aws-sdk/client-rds";
|
|
23
23
|
import { GetTopicAttributesCommand, ListSubscriptionsByTopicCommand, SNSClient, SetTopicAttributesCommand } from "@aws-sdk/client-sns";
|
|
24
24
|
import { BudgetsClient, DescribeBudgetCommand } from "@aws-sdk/client-budgets";
|
|
25
25
|
import { DescribeConfigurationSettingsCommand, ElasticBeanstalkClient, UpdateApplicationCommand, UpdateEnvironmentCommand } from "@aws-sdk/client-elastic-beanstalk";
|
|
26
26
|
import { CognitoSyncClient, GetCognitoEventsCommand, SetCognitoEventsCommand } from "@aws-sdk/client-cognito-sync";
|
|
27
27
|
import { BatchGetProjectsCommand, BatchGetReportGroupsCommand, CodeBuildClient, UpdateReportGroupCommand } from "@aws-sdk/client-codebuild";
|
|
28
|
-
import { DescribeDBClustersCommand, DescribeDBInstancesCommand as DescribeDBInstancesCommand$1, DocDBClient, ModifyDBClusterCommand, ModifyDBInstanceCommand } from "@aws-sdk/client-docdb";
|
|
28
|
+
import { DescribeDBClustersCommand as DescribeDBClustersCommand$1, DescribeDBInstancesCommand as DescribeDBInstancesCommand$1, DocDBClient, ModifyDBClusterCommand, ModifyDBInstanceCommand } from "@aws-sdk/client-docdb";
|
|
29
29
|
import { DAXClient, DescribeClustersCommand, DescribeParameterGroupsCommand, DescribeParametersCommand, DescribeSubnetGroupsCommand, UpdateClusterCommand, UpdateParameterGroupCommand } from "@aws-sdk/client-dax";
|
|
30
30
|
import { GetClassifierCommand, GetConnectionCommand, GetJobCommand, GetTableCommand, GetWorkflowCommand, GlueClient, UpdateClassifierCommand, UpdateConnectionCommand, UpdateJobCommand, UpdateTableCommand, UpdateWorkflowCommand } from "@aws-sdk/client-glue";
|
|
31
31
|
import { ChangeResourceRecordSetsCommand, ListResourceRecordSetsCommand, Route53Client } from "@aws-sdk/client-route-53";
|
|
@@ -816,6 +816,29 @@ var QuietIoHost = class extends NonInteractiveIoHost {
|
|
|
816
816
|
}
|
|
817
817
|
};
|
|
818
818
|
|
|
819
|
+
//#endregion
|
|
820
|
+
//#region src/synth/missing-context.ts
|
|
821
|
+
/** Unique, sorted missing-context keys (dedup by key). Empty array when nothing is missing. */
|
|
822
|
+
function missingContextKeys(missing) {
|
|
823
|
+
if (!missing || missing.length === 0) return [];
|
|
824
|
+
return [...new Set(missing.map((m) => m.key))].sort();
|
|
825
|
+
}
|
|
826
|
+
/**
|
|
827
|
+
* Build the stderr message body (no `warning:`/`error:` prefix — the caller adds it) for an
|
|
828
|
+
* assembly synthesized with unresolved context lookups. Returns `null` when `keys` is empty
|
|
829
|
+
* (a clean assembly — behavior unchanged). Under `preDeploy` the wording escalates to an
|
|
830
|
+
* explicit REFUSAL: the placeholders are the declared source there, so proceeding on
|
|
831
|
+
* fabricated values (false drift, a bad `--fail`, a revert that writes dummies back) is worse
|
|
832
|
+
* than stopping — the user must supply the context or deploy so the lookups resolve.
|
|
833
|
+
*/
|
|
834
|
+
function missingContextWarning(keys, opts = {}) {
|
|
835
|
+
if (keys.length === 0) return null;
|
|
836
|
+
const lead = `the CDK app synthesized with ${keys.length} unresolved context lookup(s): ${keys.join(", ")}`;
|
|
837
|
+
const why = "CDK filled these with placeholder dummy values (e.g. vpc-12345), so the synthesized template does not reflect real infrastructure.";
|
|
838
|
+
if (opts.preDeploy) return `${lead}\n${why}\n(--pre-deploy) refusing: those placeholders are the DECLARED source, so every check would report fabricated declared drift and a revert would write the dummy values back to AWS. Provide the context (commit cdk.context.json, pass -c key=value, or deploy so the lookups resolve) and re-run.`;
|
|
839
|
+
return `${lead}\n${why}`;
|
|
840
|
+
}
|
|
841
|
+
|
|
819
842
|
//#endregion
|
|
820
843
|
//#region src/synth/synth.ts
|
|
821
844
|
const CONCRETE_REGION = /^[a-z]{2}(-[a-z]+)+-\d+$/;
|
|
@@ -847,6 +870,12 @@ async function synthApp(app, opts = {}) {
|
|
|
847
870
|
}
|
|
848
871
|
const cached = await toolkit.synth(source);
|
|
849
872
|
try {
|
|
873
|
+
const missingKeys = missingContextKeys(cached.cloudAssembly.manifest.missing);
|
|
874
|
+
if (missingKeys.length > 0) {
|
|
875
|
+
const msg = missingContextWarning(missingKeys, { preDeploy: opts.preDeploy });
|
|
876
|
+
if (opts.preDeploy) throw new Error(msg ?? "unresolved CDK context lookups");
|
|
877
|
+
console.error(`warning: ${msg}`);
|
|
878
|
+
}
|
|
850
879
|
return cached.cloudAssembly.stacksRecursively.map((s) => ({
|
|
851
880
|
stackName: s.stackName,
|
|
852
881
|
region: CONCRETE_REGION.test(s.environment.region) ? s.environment.region : void 0,
|
|
@@ -1383,6 +1412,20 @@ const KNOWN_DEFAULTS = {
|
|
|
1383
1412
|
BucketKeyEnabled: true,
|
|
1384
1413
|
ServerSideEncryptionByDefault: { SSEAlgorithm: "AES256" }
|
|
1385
1414
|
}] } },
|
|
1415
|
+
"AWS::S3::AccessPoint": { PublicAccessBlockConfiguration: {
|
|
1416
|
+
RestrictPublicBuckets: true,
|
|
1417
|
+
BlockPublicPolicy: true,
|
|
1418
|
+
BlockPublicAcls: true,
|
|
1419
|
+
IgnorePublicAcls: true
|
|
1420
|
+
} },
|
|
1421
|
+
"AWS::ImageBuilder::InfrastructureConfiguration": { TerminateInstanceOnFailure: true },
|
|
1422
|
+
"AWS::ImageBuilder::ImagePipeline": {
|
|
1423
|
+
EnhancedImageMetadataEnabled: true,
|
|
1424
|
+
ImageTestsConfiguration: {
|
|
1425
|
+
ImageTestsEnabled: true,
|
|
1426
|
+
TimeoutMinutes: 720
|
|
1427
|
+
}
|
|
1428
|
+
},
|
|
1386
1429
|
"AWS::S3Tables::TableBucket": {
|
|
1387
1430
|
StorageClassConfiguration: { StorageClass: "STANDARD" },
|
|
1388
1431
|
MetricsConfiguration: { Status: "Disabled" },
|
|
@@ -2323,7 +2366,8 @@ const CONTEXT_ARN_DEFAULTS = {
|
|
|
2323
2366
|
"AWS::ResourceExplorer2::View": { Scope: "arn:{partition}:iam::{accountId}:root" },
|
|
2324
2367
|
"AWS::KinesisVideo::Stream": { KmsKeyId: "arn:{partition}:kms:{region}:{accountId}:alias/aws/kinesisvideo" },
|
|
2325
2368
|
"AWS::AutoScaling::AutoScalingGroup": { ServiceLinkedRoleARN: "arn:{partition}:iam::{accountId}:role/aws-service-role/autoscaling.amazonaws.com/AWSServiceRoleForAutoScaling" },
|
|
2326
|
-
"AWS::LakeFormation::Tag": { CatalogId: "{accountId}" }
|
|
2369
|
+
"AWS::LakeFormation::Tag": { CatalogId: "{accountId}" },
|
|
2370
|
+
"AWS::S3::AccessPoint": { BucketAccountId: "{accountId}" }
|
|
2327
2371
|
};
|
|
2328
2372
|
const ENGINE_DEFAULTS = {
|
|
2329
2373
|
"AWS::RDS::DBInstance": {
|
|
@@ -2788,7 +2832,10 @@ const CASE_INSENSITIVE_PATHS = {
|
|
|
2788
2832
|
"AWS::RDS::DBCluster": new Set(["DBClusterIdentifier"]),
|
|
2789
2833
|
"AWS::DMS::Endpoint": new Set(["EndpointType"]),
|
|
2790
2834
|
"AWS::WAFv2::LoggingConfiguration": new Set(["RedactedFields.*.SingleHeader.Name"]),
|
|
2791
|
-
"AWS::ElasticLoadBalancing::LoadBalancer": new Set(["Listeners.*.Protocol", "Listeners.*.InstanceProtocol"])
|
|
2835
|
+
"AWS::ElasticLoadBalancing::LoadBalancer": new Set(["Listeners.*.Protocol", "Listeners.*.InstanceProtocol"]),
|
|
2836
|
+
"AWS::EC2::SecurityGroup": new Set(["SecurityGroupIngress.*.IpProtocol", "SecurityGroupEgress.*.IpProtocol"]),
|
|
2837
|
+
"AWS::EC2::SecurityGroupIngress": new Set(["IpProtocol"]),
|
|
2838
|
+
"AWS::EC2::SecurityGroupEgress": new Set(["IpProtocol"])
|
|
2792
2839
|
};
|
|
2793
2840
|
function isCaseInsensitiveScalarEqual(a, b) {
|
|
2794
2841
|
return typeof a === "string" && typeof b === "string" && a.toLowerCase() === b.toLowerCase();
|
|
@@ -6820,9 +6867,10 @@ async function enumerateEfsFileSystemChildren(ctx) {
|
|
|
6820
6867
|
}
|
|
6821
6868
|
function diffRdsClusterChildren(input) {
|
|
6822
6869
|
const declared = new Set(input.declaredInstanceIds);
|
|
6870
|
+
const clusterMembers = new Set(input.clusterMemberIds);
|
|
6823
6871
|
const added = [];
|
|
6824
6872
|
for (const i of input.liveInstances) {
|
|
6825
|
-
if (declared.has(i.id)) continue;
|
|
6873
|
+
if (declared.has(i.id) || clusterMembers.has(i.id)) continue;
|
|
6826
6874
|
added.push({
|
|
6827
6875
|
resourceType: "AWS::RDS::DBInstance",
|
|
6828
6876
|
identifier: i.id,
|
|
@@ -6848,21 +6896,27 @@ async function pageDbInstances(client, clusterId) {
|
|
|
6848
6896
|
} while (marker);
|
|
6849
6897
|
return out;
|
|
6850
6898
|
}
|
|
6899
|
+
async function describeClusterMemberIds(client, clusterId) {
|
|
6900
|
+
return (((await client.send(new DescribeDBClustersCommand({ DBClusterIdentifier: clusterId }))).DBClusters?.[0])?.DBClusterMembers ?? []).map((m) => m.DBInstanceIdentifier).filter((id) => typeof id === "string");
|
|
6901
|
+
}
|
|
6851
6902
|
async function enumerateRdsClusterChildren(ctx) {
|
|
6852
6903
|
const { parent, desired, region } = ctx;
|
|
6853
6904
|
const clusterId = parent.physicalId;
|
|
6854
6905
|
if (!clusterId) return [];
|
|
6855
6906
|
const declaredInstanceIds = [];
|
|
6856
6907
|
for (const r of desired.resources) if (r.resourceType === "AWS::RDS::DBInstance" && r.declared.DBClusterIdentifier === clusterId && r.physicalId) declaredInstanceIds.push(r.physicalId);
|
|
6908
|
+
const client = new RDSClient({
|
|
6909
|
+
region,
|
|
6910
|
+
...READ_RETRY
|
|
6911
|
+
});
|
|
6912
|
+
const [instances, clusterMemberIds] = await Promise.all([pageDbInstances(client, clusterId), describeClusterMemberIds(client, clusterId)]);
|
|
6857
6913
|
return diffRdsClusterChildren({
|
|
6858
6914
|
declaredInstanceIds,
|
|
6859
|
-
liveInstances: (
|
|
6860
|
-
region,
|
|
6861
|
-
...READ_RETRY
|
|
6862
|
-
}), clusterId)).filter((i) => typeof i.DBInstanceIdentifier === "string").map((i) => ({
|
|
6915
|
+
liveInstances: instances.filter((i) => typeof i.DBInstanceIdentifier === "string").map((i) => ({
|
|
6863
6916
|
id: i.DBInstanceIdentifier,
|
|
6864
6917
|
label: i.DBInstanceIdentifier
|
|
6865
|
-
}))
|
|
6918
|
+
})),
|
|
6919
|
+
clusterMemberIds
|
|
6866
6920
|
});
|
|
6867
6921
|
}
|
|
6868
6922
|
|
|
@@ -7944,7 +7998,7 @@ const readDocDbCluster = async ({ physicalId, declared, region }) => {
|
|
|
7944
7998
|
const cl = (await new DocDBClient({
|
|
7945
7999
|
region,
|
|
7946
8000
|
...READ_RETRY
|
|
7947
|
-
}).send(new DescribeDBClustersCommand({ DBClusterIdentifier: id }))).DBClusters?.[0];
|
|
8001
|
+
}).send(new DescribeDBClustersCommand$1({ DBClusterIdentifier: id }))).DBClusters?.[0];
|
|
7948
8002
|
if (!cl) return void 0;
|
|
7949
8003
|
const model = {};
|
|
7950
8004
|
if (cl.DBClusterIdentifier !== void 0) model.DBClusterIdentifier = cl.DBClusterIdentifier;
|
|
@@ -9360,8 +9414,11 @@ async function loadBaseline(stackName, accountId, region) {
|
|
|
9360
9414
|
throw new Error(`baseline file ${path} is not valid JSON (corrupt or partially written)`);
|
|
9361
9415
|
}
|
|
9362
9416
|
if (parsed === null || typeof parsed !== "object") throw new Error(`baseline file ${path} is malformed: root is not an object`);
|
|
9417
|
+
if (parsed.stackName && parsed.stackName !== stackName) throw new Error(`baseline file ${path} was captured for stack ${parsed.stackName}, but it was loaded as stack ${stackName} (the file was likely copied or renamed to the wrong path, or a case-insensitive filesystem collided two stacks onto one file). Baselines are per-stack — run \`cdkrd record\` to write this stack's own baseline file, or restore the correct file from git.`);
|
|
9418
|
+
if (parsed.region && parsed.region !== region) throw new Error(`baseline file ${path} was captured in region ${parsed.region}, but the current region is ${region} (the file was likely copied or renamed to the wrong region path). Baselines are per-region — run \`cdkrd record\` to write this region's own baseline file, or restore the correct file from git.`);
|
|
9363
9419
|
if (parsed.recorded === void 0 && parsed.accepted !== void 0) parsed.recorded = parsed.accepted;
|
|
9364
9420
|
delete parsed.accepted;
|
|
9421
|
+
if (parsed.schemaVersion !== void 0 && typeof parsed.schemaVersion !== "number") throw new Error(`baseline file ${path} has a non-numeric schemaVersion (${JSON.stringify(parsed.schemaVersion)}); it is malformed (corrupt or hand-edited)`);
|
|
9365
9422
|
if (typeof parsed.schemaVersion === "number" && parsed.schemaVersion > 2) throw new Error(`baseline file ${path} was written by a newer cdkrd (schemaVersion ${parsed.schemaVersion}); upgrade cdkrd`);
|
|
9366
9423
|
if (!Array.isArray(parsed.recorded)) throw new Error(`baseline file ${path} is malformed: \`recorded\` is missing or not an array`);
|
|
9367
9424
|
parsed.recorded.forEach((entry, i) => validateRecordedEntry(entry, i, path));
|
|
@@ -12342,6 +12399,7 @@ function revertSelectMessage(stackName) {
|
|
|
12342
12399
|
async function recordStack(p) {
|
|
12343
12400
|
const { stackName, region, desired, findings, yes, interactive, preselectedKeys, expandNested } = p;
|
|
12344
12401
|
const existing = await loadBaseline(stackName, desired.accountId, region);
|
|
12402
|
+
if (existing) checkBaselineAccount(existing, desired.accountId, stackName);
|
|
12345
12403
|
if (!yes && existing) console.error(`note: ${stackName}: will overwrite the existing baseline file on confirm (nothing written yet; it is git-tracked — review the diff afterwards). Pass --yes to silence.`);
|
|
12346
12404
|
let recorded = carryForwardUnreadable(buildRecorded(findings), existing, findings);
|
|
12347
12405
|
let refreshedOnly = false;
|
|
@@ -13902,11 +13960,19 @@ async function runCheck(args) {
|
|
|
13902
13960
|
emitEmptyJsonOnError();
|
|
13903
13961
|
return 2;
|
|
13904
13962
|
}
|
|
13905
|
-
|
|
13906
|
-
|
|
13907
|
-
|
|
13908
|
-
|
|
13909
|
-
|
|
13963
|
+
let synthed;
|
|
13964
|
+
try {
|
|
13965
|
+
synthed = await synthApp(app, {
|
|
13966
|
+
region: a.region,
|
|
13967
|
+
profile: a.profile,
|
|
13968
|
+
context: a.context,
|
|
13969
|
+
preDeploy: true
|
|
13970
|
+
});
|
|
13971
|
+
} catch (e) {
|
|
13972
|
+
console.error(`error: ${e.message}`);
|
|
13973
|
+
emitEmptyJsonOnError();
|
|
13974
|
+
return 2;
|
|
13975
|
+
}
|
|
13910
13976
|
synthTemplates = new Map(synthed.map((s) => [synthKey(s.stackName, s.region ?? a.region), s.template]));
|
|
13911
13977
|
console.error("(--pre-deploy) comparing live state against the LOCAL synth template");
|
|
13912
13978
|
}
|