cdk-real-drift 0.23.6 → 0.24.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/dist/cli.js CHANGED
@@ -14,11 +14,12 @@ import { DescribeAddressesCommand, DescribeClientVpnAuthorizationRulesCommand, D
14
14
  import { DescribeServicesCommand, ECSClient, ListAccountSettingsCommand, ListServicesCommand, UpdateServiceCommand } from "@aws-sdk/client-ecs";
15
15
  import { DescribeCertificatesCommand, DescribeDBClustersCommand, DescribeDBInstancesCommand, DescribeOptionGroupOptionsCommand, RDSClient } from "@aws-sdk/client-rds";
16
16
  import { DatabaseMigrationServiceClient, DescribeEndpointsCommand, DescribeOrderableReplicationInstancesCommand, DescribeReplicationInstancesCommand, DescribeReplicationSubnetGroupsCommand, DescribeReplicationTasksCommand, ListTagsForResourceCommand } from "@aws-sdk/client-database-migration-service";
17
- import { DescribeParametersCommand, GetParametersCommand, GetServiceSettingCommand, SSMClient } from "@aws-sdk/client-ssm";
17
+ import { DescribeMaintenanceWindowTargetsCommand, DescribeMaintenanceWindowTasksCommand, DescribeParametersCommand, GetParametersCommand, GetServiceSettingCommand, SSMClient } from "@aws-sdk/client-ssm";
18
18
  import jsonata from "jsonata";
19
19
  import { KMSClient, ListAliasesCommand, ListGrantsCommand, RevokeGrantCommand } from "@aws-sdk/client-kms";
20
20
  import { APIGatewayClient, GetAuthorizersCommand, GetGatewayResponsesCommand, GetModelsCommand, GetRequestValidatorsCommand, GetResourcesCommand, GetStagesCommand, UpdateIntegrationCommand, UpdateIntegrationResponseCommand, UpdateMethodResponseCommand, UpdateRestApiCommand } from "@aws-sdk/client-api-gateway";
21
21
  import { AppConfigClient, ListConfigurationProfilesCommand, ListEnvironmentsCommand } from "@aws-sdk/client-appconfig";
22
+ import { ApplicationAutoScalingClient, DescribeScalingPoliciesCommand } from "@aws-sdk/client-application-auto-scaling";
22
23
  import { AppSyncClient, DeleteApiKeyCommand, ListApiKeysCommand, ListDataSourcesCommand, ListFunctionsCommand, ListResolversCommand, ListTypesCommand } from "@aws-sdk/client-appsync";
23
24
  import { ApiGatewayV2Client, DeleteAccessLogSettingsCommand, DeleteRouteSettingsCommand, GetAuthorizersCommand as GetAuthorizersCommand$1, GetIntegrationsCommand, GetRoutesCommand, GetStagesCommand as GetStagesCommand$1, UpdateStageCommand } from "@aws-sdk/client-apigatewayv2";
24
25
  import { AutoScalingClient, DescribeLifecycleHooksCommand, DescribeScheduledActionsCommand } from "@aws-sdk/client-auto-scaling";
@@ -28,7 +29,8 @@ import { DescribeMountTargetsCommand, EFSClient } from "@aws-sdk/client-efs";
28
29
  import { DescribeListenerCertificatesCommand, DescribeListenersCommand, DescribeRulesCommand, ElasticLoadBalancingV2Client, GetTrustStoreCaCertificatesBundleCommand, ModifyLoadBalancerAttributesCommand, ModifyTargetGroupAttributesCommand } from "@aws-sdk/client-elastic-load-balancing-v2";
29
30
  import { DescribeEventBusCommand, EventBridgeClient, ListRulesCommand, PutPermissionCommand } from "@aws-sdk/client-eventbridge";
30
31
  import { GetClassifierCommand, GetConnectionCommand, GetJobCommand, GetSecurityConfigurationCommand, GetTableCommand, GetTablesCommand, GetTagsCommand, GetWorkflowCommand, GlueClient, UpdateClassifierCommand, UpdateConnectionCommand, UpdateJobCommand, UpdateTableCommand, UpdateWorkflowCommand } from "@aws-sdk/client-glue";
31
- import { GetFunctionCommand, GetPolicyCommand, LambdaClient, ListAliasesCommand as ListAliasesCommand$1, ListEventSourceMappingsCommand, ListFunctionUrlConfigsCommand, ListVersionsByFunctionCommand } from "@aws-sdk/client-lambda";
32
+ import { GuardDutyClient, ListFiltersCommand, ListIPSetsCommand, ListPublishingDestinationsCommand, ListThreatEntitySetsCommand, ListThreatIntelSetsCommand, ListTrustedEntitySetsCommand } from "@aws-sdk/client-guardduty";
33
+ import { AddPermissionCommand, GetFunctionCommand, GetPolicyCommand, LambdaClient, ListAliasesCommand as ListAliasesCommand$1, ListEventSourceMappingsCommand, ListFunctionUrlConfigsCommand, ListVersionsByFunctionCommand, RemovePermissionCommand } from "@aws-sdk/client-lambda";
32
34
  import { DescribeDomainConfigCommand, DescribeDomainsCommand, ListDomainNamesCommand, OpenSearchClient, UpdateDomainConfigCommand } from "@aws-sdk/client-opensearch";
33
35
  import { ChangeResourceRecordSetsCommand, ListHostedZonesByNameCommand, ListResourceRecordSetsCommand, Route53Client } from "@aws-sdk/client-route-53";
34
36
  import { DeleteBucketPolicyCommand, GetBucketPolicyCommand, GetObjectCommand, PutBucketPolicyCommand, S3Client } from "@aws-sdk/client-s3";
@@ -4055,16 +4057,39 @@ const CASE_INSENSITIVE_PATHS = {
4055
4057
  "AWS::Batch::ComputeEnvironment": new Set(["Type"]),
4056
4058
  "AWS::Batch::JobDefinition": new Set(["Type"]),
4057
4059
  "AWS::EMRServerless::Application": new Set(["Type"]),
4058
- "AWS::RDS::DBInstance": new Set(["DBInstanceIdentifier"]),
4059
- "AWS::RDS::DBCluster": new Set(["DBClusterIdentifier"]),
4060
+ "AWS::RDS::DBInstance": new Set([
4061
+ "DBInstanceIdentifier",
4062
+ "DBParameterGroupName",
4063
+ "DBSubnetGroupName",
4064
+ "OptionGroupName",
4065
+ "DBClusterIdentifier"
4066
+ ]),
4067
+ "AWS::RDS::DBCluster": new Set([
4068
+ "DBClusterIdentifier",
4069
+ "DBClusterParameterGroupName",
4070
+ "DBSubnetGroupName"
4071
+ ]),
4060
4072
  "AWS::ElastiCache::SubnetGroup": new Set(["CacheSubnetGroupName"]),
4061
- "AWS::ElastiCache::ReplicationGroup": new Set(["ReplicationGroupId"]),
4062
- "AWS::ElastiCache::CacheCluster": new Set(["ClusterName"]),
4063
- "AWS::DocDB::DBCluster": new Set(["DBClusterIdentifier"]),
4064
- "AWS::DocDB::DBInstance": new Set(["DBInstanceIdentifier"]),
4073
+ "AWS::ElastiCache::ReplicationGroup": new Set(["ReplicationGroupId", "CacheSubnetGroupName"]),
4074
+ "AWS::ElastiCache::CacheCluster": new Set(["ClusterName", "CacheSubnetGroupName"]),
4075
+ "AWS::DocDB::DBCluster": new Set([
4076
+ "DBClusterIdentifier",
4077
+ "DBSubnetGroupName",
4078
+ "DBClusterParameterGroupName"
4079
+ ]),
4080
+ "AWS::DocDB::DBInstance": new Set(["DBInstanceIdentifier", "DBClusterIdentifier"]),
4065
4081
  "AWS::DocDB::DBSubnetGroup": new Set(["DBSubnetGroupName"]),
4066
- "AWS::Neptune::DBCluster": new Set(["DBClusterIdentifier"]),
4067
- "AWS::Neptune::DBInstance": new Set(["DBInstanceIdentifier"]),
4082
+ "AWS::Neptune::DBCluster": new Set([
4083
+ "DBClusterIdentifier",
4084
+ "DBSubnetGroupName",
4085
+ "DBClusterParameterGroupName"
4086
+ ]),
4087
+ "AWS::Neptune::DBInstance": new Set([
4088
+ "DBInstanceIdentifier",
4089
+ "DBClusterIdentifier",
4090
+ "DBParameterGroupName",
4091
+ "DBSubnetGroupName"
4092
+ ]),
4068
4093
  "AWS::Neptune::DBSubnetGroup": new Set(["DBSubnetGroupName"]),
4069
4094
  "AWS::RDS::DBParameterGroup": new Set(["DBParameterGroupName"]),
4070
4095
  "AWS::RDS::DBClusterParameterGroup": new Set(["DBClusterParameterGroupName"]),
@@ -4074,8 +4099,12 @@ const CASE_INSENSITIVE_PATHS = {
4074
4099
  "AWS::Neptune::DBClusterParameterGroup": new Set(["Name"]),
4075
4100
  "AWS::DocDB::DBClusterParameterGroup": new Set(["Name"]),
4076
4101
  "AWS::Redshift::ClusterParameterGroup": new Set(["ParameterGroupName"]),
4077
- "AWS::Redshift::Cluster": new Set(["ClusterIdentifier"]),
4078
- "AWS::DMS::ReplicationInstance": new Set(["ReplicationInstanceIdentifier"]),
4102
+ "AWS::Redshift::Cluster": new Set([
4103
+ "ClusterIdentifier",
4104
+ "ClusterParameterGroupName",
4105
+ "ClusterSubnetGroupName"
4106
+ ]),
4107
+ "AWS::DMS::ReplicationInstance": new Set(["ReplicationInstanceIdentifier", "ReplicationSubnetGroupIdentifier"]),
4079
4108
  "AWS::DMS::ReplicationSubnetGroup": new Set(["ReplicationSubnetGroupIdentifier"]),
4080
4109
  "AWS::DAX::ParameterGroup": new Set(["ParameterGroupName"]),
4081
4110
  "AWS::DAX::SubnetGroup": new Set(["SubnetGroupName"]),
@@ -4565,6 +4594,7 @@ function alignNameValueSubset(declared, live, spec) {
4565
4594
  return live.filter((e) => !dm.has(e[spec.nameField]));
4566
4595
  }
4567
4596
  const UNORDERED_ARRAY_PROPS = {
4597
+ "AWS::Route53::CidrCollection": new Set(["Locations.*.CidrList"]),
4568
4598
  "AWS::CloudFront::Distribution": new Set(["DistributionConfig.Restrictions.GeoRestriction.Locations"]),
4569
4599
  "AWS::Cognito::UserPool": new Set(["EnabledMfas"]),
4570
4600
  "AWS::ECS::Cluster": new Set(["CapacityProviders"]),
@@ -5478,6 +5508,23 @@ function isLogGroupArnWildcardMatch(desired, actual) {
5478
5508
  return stripLogGroupWildcard(desired) === stripLogGroupWildcard(actual);
5479
5509
  }
5480
5510
 
5511
+ //#endregion
5512
+ //#region src/normalize/derived-defaults.ts
5513
+ function route53HealthCheckDerivedPort(hcType) {
5514
+ return hcType === "HTTP" || hcType === "HTTP_STR_MATCH" ? 80 : hcType === "HTTPS" || hcType === "HTTPS_STR_MATCH" ? 443 : void 0;
5515
+ }
5516
+ function elbTargetGroupDerivedHealthCheckProtocol(protocol, targetType) {
5517
+ if (protocol === "GENEVE") return "TCP";
5518
+ if (protocol === "HTTPS") return "HTTPS";
5519
+ if ((protocol === "TCP" || protocol === "TLS" || protocol === "UDP" || protocol === "TCP_UDP") && targetType !== "alb") return "TCP";
5520
+ }
5521
+ function elbTargetGroupDerivedHealthCheckPort(protocol) {
5522
+ return protocol === "GENEVE" ? "80" : void 0;
5523
+ }
5524
+ function rdsReplicaDerivedBackupRetention(sourceDbInstanceIdentifier) {
5525
+ return sourceDbInstanceIdentifier !== void 0 ? 0 : void 0;
5526
+ }
5527
+
5481
5528
  //#endregion
5482
5529
  //#region src/read/kms-aliases.ts
5483
5530
  const cache$1 = /* @__PURE__ */ new Map();
@@ -7164,11 +7211,14 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
7164
7211
  HealthCheckTimeoutSeconds: 6,
7165
7212
  Matcher: { HttpCode: "200-399" }
7166
7213
  } : {},
7167
- ...protocol === "GENEVE" ? {
7168
- HealthCheckProtocol: "TCP",
7169
- HealthCheckPort: "80"
7170
- } : {},
7171
- ...protocol === "HTTPS" ? { HealthCheckProtocol: "HTTPS" } : {},
7214
+ ...(() => {
7215
+ const hcProto = elbTargetGroupDerivedHealthCheckProtocol(protocol, targetType);
7216
+ const hcPort = elbTargetGroupDerivedHealthCheckPort(protocol);
7217
+ return {
7218
+ ...hcProto !== void 0 ? { HealthCheckProtocol: hcProto } : {},
7219
+ ...hcPort !== void 0 ? { HealthCheckPort: hcPort } : {}
7220
+ };
7221
+ })(),
7172
7222
  ...protocolVersion === "GRPC" ? { Matcher: { GrpcCode: "12" } } : {}
7173
7223
  };
7174
7224
  }
@@ -7262,7 +7312,6 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
7262
7312
  const proto = declared["Protocol"];
7263
7313
  if (typeof proto === "string" && (proto === "TCP" || proto === "TLS" || proto === "UDP" || proto === "TCP_UDP") && declared["TargetType"] !== "alb") knownDef = {
7264
7314
  ...knownDef,
7265
- HealthCheckProtocol: "TCP",
7266
7315
  HealthCheckTimeoutSeconds: 10
7267
7316
  };
7268
7317
  }
@@ -7335,7 +7384,7 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
7335
7384
  if (resourceType === "AWS::RDS::DBInstance" && rdsReplicaSourceId !== void 0) {
7336
7385
  knownDef = {
7337
7386
  ...knownDef,
7338
- BackupRetentionPeriod: 0
7387
+ BackupRetentionPeriod: rdsReplicaDerivedBackupRetention(rdsReplicaSourceId) ?? 0
7339
7388
  };
7340
7389
  const src = opts.siblingRdsSourceModels?.[rdsReplicaSourceId];
7341
7390
  if (src) {
@@ -7343,7 +7392,9 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
7343
7392
  for (const k of [
7344
7393
  "Engine",
7345
7394
  "AllocatedStorage",
7346
- "MasterUsername"
7395
+ "MasterUsername",
7396
+ "DBParameterGroupName",
7397
+ "DBSubnetGroupName"
7347
7398
  ]) if (src[k] !== void 0) inherit[k] = src[k];
7348
7399
  knownDef = {
7349
7400
  ...knownDef,
@@ -7353,7 +7404,7 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
7353
7404
  }
7354
7405
  if (resourceType === "AWS::Route53::HealthCheck") {
7355
7406
  const hcType = declared["HealthCheckConfig"]?.["Type"];
7356
- const defaultPort = hcType === "HTTP" || hcType === "HTTP_STR_MATCH" ? 80 : hcType === "HTTPS" || hcType === "HTTPS_STR_MATCH" ? 443 : void 0;
7407
+ const defaultPort = route53HealthCheckDerivedPort(hcType);
7357
7408
  if (defaultPort !== void 0) knownDefPaths = {
7358
7409
  ...knownDefPaths,
7359
7410
  "HealthCheckConfig.Port": defaultPort
@@ -8393,7 +8444,10 @@ const CHILD_ENUMERATORS = {
8393
8444
  "AWS::Route53::HostedZone": enumerateRoute53HostedZoneChildren,
8394
8445
  "AWS::AutoScaling::AutoScalingGroup": enumerateAutoScalingGroupChildren,
8395
8446
  "AWS::Glue::Database": enumerateGlueDatabaseChildren,
8396
- "AWS::EC2::TransitGateway": enumerateTransitGatewayChildren
8447
+ "AWS::EC2::TransitGateway": enumerateTransitGatewayChildren,
8448
+ "AWS::GuardDuty::Detector": enumerateGuardDutyDetectorChildren,
8449
+ "AWS::SSM::MaintenanceWindow": enumerateMaintenanceWindowChildren,
8450
+ "AWS::ApplicationAutoScaling::ScalableTarget": enumerateScalableTargetChildren
8397
8451
  };
8398
8452
  function normalizeApiPath(p) {
8399
8453
  let out = p.startsWith("/") ? p : `/${p}`;
@@ -11545,6 +11599,314 @@ async function enumerateTransitGatewayChildren(ctx) {
11545
11599
  liveRouteTables
11546
11600
  })];
11547
11601
  }
11602
+ function diffGuardDutyDetectorChildren(input) {
11603
+ const d = input.detectorId;
11604
+ const added = [];
11605
+ const declaredFilters = new Set(input.declaredFilterNames);
11606
+ for (const name of input.liveFilterNames) {
11607
+ if (declaredFilters.has(name)) continue;
11608
+ added.push({
11609
+ resourceType: "AWS::GuardDuty::Filter",
11610
+ identifier: `${d}|${name}`,
11611
+ label: name,
11612
+ live: {
11613
+ DetectorId: d,
11614
+ Name: name
11615
+ },
11616
+ siblingLookupId: name
11617
+ });
11618
+ }
11619
+ const childFirstSet = (resourceType, declaredIds, liveIds) => {
11620
+ const declared = new Set(declaredIds);
11621
+ for (const id of liveIds) {
11622
+ if (declared.has(id)) continue;
11623
+ added.push({
11624
+ resourceType,
11625
+ identifier: `${id}|${d}`,
11626
+ label: id,
11627
+ live: {
11628
+ DetectorId: d,
11629
+ Id: id
11630
+ },
11631
+ siblingLookupId: id
11632
+ });
11633
+ }
11634
+ };
11635
+ childFirstSet("AWS::GuardDuty::IPSet", input.declaredIpSetIds, input.liveIpSetIds);
11636
+ childFirstSet("AWS::GuardDuty::ThreatIntelSet", input.declaredThreatIntelSetIds, input.liveThreatIntelSetIds);
11637
+ childFirstSet("AWS::GuardDuty::ThreatEntitySet", input.declaredThreatEntitySetIds, input.liveThreatEntitySetIds);
11638
+ childFirstSet("AWS::GuardDuty::TrustedEntitySet", input.declaredTrustedEntitySetIds, input.liveTrustedEntitySetIds);
11639
+ const declaredDests = new Set(input.declaredPublishingDestinationIds);
11640
+ for (const dest of input.livePublishingDestinations) {
11641
+ if (declaredDests.has(dest.id)) continue;
11642
+ added.push({
11643
+ resourceType: "AWS::GuardDuty::PublishingDestination",
11644
+ identifier: `${d}|${dest.id}`,
11645
+ label: dest.destinationType ? `${dest.id} (${dest.destinationType})` : dest.id,
11646
+ live: {
11647
+ DetectorId: d,
11648
+ Id: dest.id
11649
+ },
11650
+ siblingLookupId: dest.id
11651
+ });
11652
+ }
11653
+ return added;
11654
+ }
11655
+ async function pageGuardDutyIds(send) {
11656
+ const out = [];
11657
+ let token;
11658
+ do {
11659
+ const r = await send(token);
11660
+ out.push(...r.ids ?? []);
11661
+ token = r.nextToken;
11662
+ } while (token);
11663
+ return out;
11664
+ }
11665
+ async function enumerateGuardDutyDetectorChildren(ctx) {
11666
+ const { parent, desired, region } = ctx;
11667
+ const detectorId = parent.physicalId;
11668
+ if (!detectorId) return [];
11669
+ const declaredOf = (type, nameProp) => {
11670
+ const out = [];
11671
+ for (const r of desired.resources) {
11672
+ if (r.resourceType !== type) continue;
11673
+ const det = r.declared.DetectorId;
11674
+ if (typeof det === "string" && det.length > 0 && !parentRefMatches(det, detectorId)) continue;
11675
+ const name = nameProp && typeof r.declared[nameProp] === "string" ? r.declared[nameProp] : r.physicalId;
11676
+ if (name) out.push(name);
11677
+ }
11678
+ return out;
11679
+ };
11680
+ const client = new GuardDutyClient({
11681
+ region,
11682
+ ...READ_RETRY
11683
+ });
11684
+ const liveFilterNames = await pageGuardDutyIds(async (t) => {
11685
+ const r = await client.send(new ListFiltersCommand({
11686
+ DetectorId: detectorId,
11687
+ NextToken: t
11688
+ }));
11689
+ return {
11690
+ ids: r.FilterNames,
11691
+ nextToken: r.NextToken
11692
+ };
11693
+ });
11694
+ const liveIpSetIds = await pageGuardDutyIds(async (t) => {
11695
+ const r = await client.send(new ListIPSetsCommand({
11696
+ DetectorId: detectorId,
11697
+ NextToken: t
11698
+ }));
11699
+ return {
11700
+ ids: r.IpSetIds,
11701
+ nextToken: r.NextToken
11702
+ };
11703
+ });
11704
+ const liveThreatIntelSetIds = await pageGuardDutyIds(async (t) => {
11705
+ const r = await client.send(new ListThreatIntelSetsCommand({
11706
+ DetectorId: detectorId,
11707
+ NextToken: t
11708
+ }));
11709
+ return {
11710
+ ids: r.ThreatIntelSetIds,
11711
+ nextToken: r.NextToken
11712
+ };
11713
+ });
11714
+ const liveThreatEntitySetIds = await pageGuardDutyIds(async (t) => {
11715
+ const r = await client.send(new ListThreatEntitySetsCommand({
11716
+ DetectorId: detectorId,
11717
+ NextToken: t
11718
+ }));
11719
+ return {
11720
+ ids: r.ThreatEntitySetIds,
11721
+ nextToken: r.NextToken
11722
+ };
11723
+ });
11724
+ const liveTrustedEntitySetIds = await pageGuardDutyIds(async (t) => {
11725
+ const r = await client.send(new ListTrustedEntitySetsCommand({
11726
+ DetectorId: detectorId,
11727
+ NextToken: t
11728
+ }));
11729
+ return {
11730
+ ids: r.TrustedEntitySetIds,
11731
+ nextToken: r.NextToken
11732
+ };
11733
+ });
11734
+ const liveDests = [];
11735
+ let destToken;
11736
+ do {
11737
+ const r = await client.send(new ListPublishingDestinationsCommand({
11738
+ DetectorId: detectorId,
11739
+ NextToken: destToken
11740
+ }));
11741
+ liveDests.push(...r.Destinations ?? []);
11742
+ destToken = r.NextToken;
11743
+ } while (destToken);
11744
+ return diffGuardDutyDetectorChildren({
11745
+ detectorId,
11746
+ declaredFilterNames: declaredOf("AWS::GuardDuty::Filter", "Name"),
11747
+ declaredIpSetIds: declaredOf("AWS::GuardDuty::IPSet"),
11748
+ declaredThreatIntelSetIds: declaredOf("AWS::GuardDuty::ThreatIntelSet"),
11749
+ declaredThreatEntitySetIds: declaredOf("AWS::GuardDuty::ThreatEntitySet"),
11750
+ declaredTrustedEntitySetIds: declaredOf("AWS::GuardDuty::TrustedEntitySet"),
11751
+ declaredPublishingDestinationIds: declaredOf("AWS::GuardDuty::PublishingDestination"),
11752
+ liveFilterNames,
11753
+ liveIpSetIds,
11754
+ liveThreatIntelSetIds,
11755
+ liveThreatEntitySetIds,
11756
+ liveTrustedEntitySetIds,
11757
+ livePublishingDestinations: liveDests.filter((x) => typeof x.DestinationId === "string").map((x) => ({
11758
+ id: x.DestinationId,
11759
+ destinationType: x.DestinationType
11760
+ }))
11761
+ });
11762
+ }
11763
+ function diffMaintenanceWindowChildren(input) {
11764
+ const w = input.windowId;
11765
+ const added = [];
11766
+ const declaredTargets = new Set(input.declaredTargetIds);
11767
+ for (const t of input.liveTargets) {
11768
+ if (declaredTargets.has(t.id)) continue;
11769
+ added.push({
11770
+ resourceType: "AWS::SSM::MaintenanceWindowTarget",
11771
+ identifier: `${w}|${t.id}`,
11772
+ label: t.label ?? t.id,
11773
+ live: {
11774
+ WindowId: w,
11775
+ Id: t.id
11776
+ },
11777
+ siblingLookupId: t.id
11778
+ });
11779
+ }
11780
+ const declaredTasks = new Set(input.declaredTaskIds);
11781
+ for (const t of input.liveTasks) {
11782
+ if (declaredTasks.has(t.id)) continue;
11783
+ added.push({
11784
+ resourceType: "AWS::SSM::MaintenanceWindowTask",
11785
+ identifier: `${w}|${t.id}`,
11786
+ label: t.label ?? t.id,
11787
+ live: {
11788
+ WindowId: w,
11789
+ Id: t.id
11790
+ },
11791
+ siblingLookupId: t.id
11792
+ });
11793
+ }
11794
+ return added;
11795
+ }
11796
+ async function enumerateMaintenanceWindowChildren(ctx) {
11797
+ const { parent, desired, region } = ctx;
11798
+ const windowId = parent.physicalId;
11799
+ if (!windowId) return [];
11800
+ const declaredIdsOf = (type) => {
11801
+ const out = [];
11802
+ for (const r of desired.resources) {
11803
+ if (r.resourceType !== type || !parentRefMatches(r.declared.WindowId, windowId)) continue;
11804
+ if (r.physicalId) out.push(r.physicalId);
11805
+ }
11806
+ return out;
11807
+ };
11808
+ const client = new SSMClient({
11809
+ region,
11810
+ ...READ_RETRY
11811
+ });
11812
+ const liveTargets = [];
11813
+ let targetToken;
11814
+ do {
11815
+ const r = await client.send(new DescribeMaintenanceWindowTargetsCommand({
11816
+ WindowId: windowId,
11817
+ NextToken: targetToken
11818
+ }));
11819
+ liveTargets.push(...r.Targets ?? []);
11820
+ targetToken = r.NextToken;
11821
+ } while (targetToken);
11822
+ const liveTasks = [];
11823
+ let taskToken;
11824
+ do {
11825
+ const r = await client.send(new DescribeMaintenanceWindowTasksCommand({
11826
+ WindowId: windowId,
11827
+ NextToken: taskToken
11828
+ }));
11829
+ liveTasks.push(...r.Tasks ?? []);
11830
+ taskToken = r.NextToken;
11831
+ } while (taskToken);
11832
+ return diffMaintenanceWindowChildren({
11833
+ windowId,
11834
+ declaredTargetIds: declaredIdsOf("AWS::SSM::MaintenanceWindowTarget"),
11835
+ declaredTaskIds: declaredIdsOf("AWS::SSM::MaintenanceWindowTask"),
11836
+ liveTargets: liveTargets.filter((t) => typeof t.WindowTargetId === "string").map((t) => ({
11837
+ id: t.WindowTargetId,
11838
+ label: t.Name ?? t.WindowTargetId
11839
+ })),
11840
+ liveTasks: liveTasks.filter((t) => typeof t.WindowTaskId === "string").map((t) => ({
11841
+ id: t.WindowTaskId,
11842
+ label: t.TaskArn ? `${t.WindowTaskId} (${t.Type ?? "?"} ${t.TaskArn})` : t.WindowTaskId
11843
+ }))
11844
+ });
11845
+ }
11846
+ function diffScalableTargetChildren(input) {
11847
+ const declaredArns = new Set(input.declaredPolicyArns);
11848
+ const declaredNames = new Set(input.declaredPolicyNames);
11849
+ const added = [];
11850
+ for (const p of input.livePolicies) {
11851
+ if (declaredArns.has(p.arn)) continue;
11852
+ if (p.name !== void 0 && declaredNames.has(p.name)) continue;
11853
+ added.push({
11854
+ resourceType: "AWS::ApplicationAutoScaling::ScalingPolicy",
11855
+ identifier: `${p.arn}|${input.scalableDimension}`,
11856
+ label: p.name ?? p.arn,
11857
+ live: {
11858
+ PolicyName: p.name,
11859
+ ScalingTargetId: `${input.resourceId}|${input.scalableDimension}|${input.serviceNamespace}`
11860
+ },
11861
+ siblingLookupId: p.arn
11862
+ });
11863
+ }
11864
+ return added;
11865
+ }
11866
+ async function enumerateScalableTargetChildren(ctx) {
11867
+ const { parent, desired, region } = ctx;
11868
+ const ns = parent.declared.ServiceNamespace;
11869
+ const resourceId = parent.declared.ResourceId;
11870
+ const dimension = parent.declared.ScalableDimension;
11871
+ if (typeof ns !== "string" || typeof resourceId !== "string" || typeof dimension !== "string") return [];
11872
+ const declaredPolicyArns = [];
11873
+ const declaredPolicyNames = [];
11874
+ for (const r of desired.resources) {
11875
+ if (r.resourceType !== "AWS::ApplicationAutoScaling::ScalingPolicy") continue;
11876
+ const viaTargetId = r.declared.ScalingTargetId !== void 0 && parentRefMatches(r.declared.ScalingTargetId, parent.physicalId);
11877
+ const viaPair = r.declared.ResourceId === resourceId && r.declared.ScalableDimension === dimension;
11878
+ if (!viaTargetId && !viaPair) continue;
11879
+ if (r.physicalId) declaredPolicyArns.push(r.physicalId);
11880
+ if (typeof r.declared.PolicyName === "string") declaredPolicyNames.push(r.declared.PolicyName);
11881
+ }
11882
+ const client = new ApplicationAutoScalingClient({
11883
+ region,
11884
+ ...READ_RETRY
11885
+ });
11886
+ const livePolicies = [];
11887
+ let token;
11888
+ do {
11889
+ const r = await client.send(new DescribeScalingPoliciesCommand({
11890
+ ServiceNamespace: ns,
11891
+ ResourceId: resourceId,
11892
+ ScalableDimension: dimension,
11893
+ NextToken: token
11894
+ }));
11895
+ livePolicies.push(...r.ScalingPolicies ?? []);
11896
+ token = r.NextToken;
11897
+ } while (token);
11898
+ return diffScalableTargetChildren({
11899
+ serviceNamespace: ns,
11900
+ resourceId,
11901
+ scalableDimension: dimension,
11902
+ declaredPolicyArns,
11903
+ declaredPolicyNames,
11904
+ livePolicies: livePolicies.filter((p) => typeof p.PolicyARN === "string").map((p) => ({
11905
+ arn: p.PolicyARN,
11906
+ name: p.PolicyName
11907
+ }))
11908
+ });
11909
+ }
11548
11910
 
11549
11911
  //#endregion
11550
11912
  //#region src/read/pem.ts
@@ -15635,8 +15997,8 @@ async function regatherTouched(gathered, touched, region) {
15635
15997
  clusterEchoModel: buildClusterEchoModels(desired),
15636
15998
  scalableTargetBands: buildScalableTargetBands(desired),
15637
15999
  siblingClientVpnEndpointVpcs: buildClientVpnEndpointSiblingVpcs(desired),
15638
- siblingCloudFrontCdPolicyIds: buildCloudFrontStagingDistCdPolicyIds(desired, liveModelMap(reads)),
15639
- siblingRdsSourceModels: buildRdsReplicaSourceModels(desired, liveModelMap(reads)),
16000
+ siblingCloudFrontCdPolicyIds: buildCloudFrontStagingDistCdPolicyIds(desired, new Map([...gathered.liveByLogical, ...liveModelMap(reads)])),
16001
+ siblingRdsSourceModels: buildRdsReplicaSourceModels(desired, new Map([...gathered.liveByLogical, ...liveModelMap(reads)])),
15640
16002
  rdsOptionSettingDefaults: await buildRdsOptionSettingDefaults(desired, region)
15641
16003
  };
15642
16004
  const fresh = [];
@@ -19299,7 +19661,59 @@ const writeBudget = async (ctx, ops) => {
19299
19661
  NewBudget: newBudget
19300
19662
  }));
19301
19663
  };
19664
+ const LAMBDA_PERMISSION_PROJECTED_CONDITIONS = {
19665
+ ArnLike: new Set(["AWS:SourceArn"]),
19666
+ StringEquals: new Set([
19667
+ "AWS:SourceAccount",
19668
+ "aws:PrincipalOrgID",
19669
+ "lambda:FunctionUrlAuthType"
19670
+ ])
19671
+ };
19672
+ const writeLambdaPermission = async (ctx, ops) => {
19673
+ const fn = str(ctx.declared["FunctionName"]);
19674
+ if (!fn) throw new Error("cannot resolve FunctionName for Lambda Permission revert");
19675
+ const sid = str(ctx.physicalId);
19676
+ if (!sid) throw new Error("cannot resolve the Lambda Permission StatementId for revert");
19677
+ const c = new LambdaClient({
19678
+ region: ctx.region,
19679
+ ...CLIENT_TIMEOUTS
19680
+ });
19681
+ let liveStmt;
19682
+ try {
19683
+ const raw = (await c.send(new GetPolicyCommand({ FunctionName: fn }))).Policy;
19684
+ liveStmt = (JSON.parse(raw ?? "{}").Statement ?? []).find((s) => s["Sid"] === sid);
19685
+ } catch (e) {
19686
+ if (e.name !== "ResourceNotFoundException") throw e;
19687
+ }
19688
+ const liveCond = liveStmt?.["Condition"];
19689
+ if (liveCond !== void 0 && liveCond !== null && typeof liveCond === "object") for (const [condOp, kv] of Object.entries(liveCond)) {
19690
+ const projected = LAMBDA_PERMISSION_PROJECTED_CONDITIONS[condOp];
19691
+ const keys = kv !== null && typeof kv === "object" ? Object.keys(kv) : [];
19692
+ const unprojected = projected ? keys.filter((k) => !projected.has(k)) : keys;
19693
+ if (unprojected.length > 0) throw new Error(`Lambda Permission ${sid} carries a condition the reader does not project (${condOp}: ${unprojected.join(", ")}) — a rebuild would silently drop it; update the permission manually`);
19694
+ }
19695
+ const desired = await desiredModel("AWS::Lambda::Permission", ctx, ops);
19696
+ const action = str(desired["Action"]);
19697
+ const principal = str(desired["Principal"]);
19698
+ if (!action || !principal) throw new Error("cannot resolve Action/Principal for Lambda Permission revert");
19699
+ if (liveStmt) await c.send(new RemovePermissionCommand({
19700
+ FunctionName: fn,
19701
+ StatementId: sid
19702
+ }));
19703
+ await c.send(new AddPermissionCommand({
19704
+ FunctionName: fn,
19705
+ StatementId: sid,
19706
+ Action: action,
19707
+ Principal: principal,
19708
+ SourceArn: str(desired["SourceArn"]),
19709
+ SourceAccount: str(desired["SourceAccount"]),
19710
+ PrincipalOrgID: str(desired["PrincipalOrgID"]),
19711
+ FunctionUrlAuthType: str(desired["FunctionUrlAuthType"])
19712
+ }));
19713
+ };
19714
+ const SDK_REBUILD_WRITER_TYPES = new Set(["AWS::Lambda::Permission"]);
19302
19715
  const SDK_WRITERS = {
19716
+ "AWS::Lambda::Permission": writeLambdaPermission,
19303
19717
  "AWS::Budgets::Budget": writeBudget,
19304
19718
  "AWS::ApiGatewayV2::Stage": writeApiGatewayV2Stage,
19305
19719
  "AWS::ElasticBeanstalk::Application": writeElasticBeanstalkApplication,
@@ -19689,6 +20103,7 @@ const REVERT_SET_DEFAULT_PATHS = new Set([
19689
20103
  "AWS::RDS::DBInstance\0MonitoringInterval",
19690
20104
  "AWS::RDS::DBInstance\0CopyTagsToSnapshot",
19691
20105
  "AWS::RDS::DBInstance\0CACertificateIdentifier",
20106
+ "AWS::EC2::Volume\0VolumeType",
19692
20107
  "AWS::RDS::DBCluster\0AutoMinorVersionUpgrade",
19693
20108
  "AWS::Neptune::DBInstance\0AutoMinorVersionUpgrade",
19694
20109
  "AWS::ElastiCache::CacheCluster\0AutoMinorVersionUpgrade",
@@ -20010,7 +20425,7 @@ function buildRevertPlan(findings, baseline, opts = {}) {
20010
20425
  continue;
20011
20426
  }
20012
20427
  const schema = opts.schemas?.get(f.resourceType);
20013
- if (schema && isUnderCreateOnly(f.path, schema.createOnlyPaths)) {
20428
+ if (schema && isUnderCreateOnly(f.path, schema.createOnlyPaths) && !SDK_REBUILD_WRITER_TYPES.has(f.resourceType)) {
20014
20429
  notRevertable.push({
20015
20430
  displayId,
20016
20431
  resourceType: f.resourceType,
@@ -20087,7 +20502,8 @@ function buildRevertPlan(findings, baseline, opts = {}) {
20087
20502
  desired: [...f.desired, ...sib]
20088
20503
  };
20089
20504
  }
20090
- const op = revertOp(toRevert, recorded, opts.identity);
20505
+ const declaredModel = opts.declaredForLogical?.(f.logicalId);
20506
+ const op = revertOp(toRevert, recorded, opts.identity, declaredModel);
20091
20507
  const key = `${f.logicalId} ${kind}${propScoped ? ` ${f.path}` : ""}`;
20092
20508
  const item = itemsByLogical.get(key) ?? {
20093
20509
  logicalId: f.logicalId,
@@ -20098,6 +20514,20 @@ function buildRevertPlan(findings, baseline, opts = {}) {
20098
20514
  ops: []
20099
20515
  };
20100
20516
  item.ops.push(op);
20517
+ if (kind === "cc" && op.op === "add") {
20518
+ const live = opts.liveByLogical?.get(f.logicalId);
20519
+ for (const sibling of REVERT_COMPANION_REMOVES[`${f.resourceType}\0${f.path}`]?.(op.value) ?? []) {
20520
+ if (declaredModel?.[sibling] !== void 0) continue;
20521
+ if (!live || live[sibling] === void 0) continue;
20522
+ const siblingPointer = `/${sibling}`;
20523
+ if (item.ops.some((o) => o.path === siblingPointer)) continue;
20524
+ item.ops.push({
20525
+ op: "remove",
20526
+ path: siblingPointer,
20527
+ human: `${sibling} -> remove (incompatible with the restored default)`
20528
+ });
20529
+ }
20530
+ }
20101
20531
  itemsByLogical.set(key, item);
20102
20532
  }
20103
20533
  if (opts.liveByLogical) for (const item of itemsByLogical.values()) {
@@ -20137,7 +20567,20 @@ function contextArnDefaultFor(resourceType, path, identity) {
20137
20567
  const substitute = (t) => t.replace("{partition}", partition).replace("{region}", region).replace("{accountId}", accountId);
20138
20568
  return Array.isArray(template) ? template.map(substitute) : substitute(template);
20139
20569
  }
20140
- function revertOp(f, recorded, identity) {
20570
+ function derivedRevertDefaultFor(resourceType, path, declared) {
20571
+ if (!declared) return void 0;
20572
+ if (resourceType === "AWS::Route53::HealthCheck" && path === "HealthCheckConfig.Port") return route53HealthCheckDerivedPort(declared["HealthCheckConfig"]?.["Type"]);
20573
+ if (resourceType === "AWS::ElasticLoadBalancingV2::TargetGroup") {
20574
+ if (path === "HealthCheckProtocol") return elbTargetGroupDerivedHealthCheckProtocol(declared["Protocol"], declared["TargetType"]);
20575
+ if (path === "HealthCheckPort") return elbTargetGroupDerivedHealthCheckPort(declared["Protocol"]);
20576
+ }
20577
+ if (resourceType === "AWS::RDS::DBInstance" && path === "BackupRetentionPeriod") return rdsReplicaDerivedBackupRetention(declared["SourceDBInstanceIdentifier"]);
20578
+ }
20579
+ const REVERT_COMPANION_REMOVES = {
20580
+ "AWS::ElasticLoadBalancingV2::TargetGroup\0HealthCheckProtocol": (value) => value === "TCP" ? ["Matcher", "HealthCheckPath"] : [],
20581
+ "AWS::EC2::Volume\0VolumeType": (value) => value === "gp2" || value === "standard" || value === "st1" || value === "sc1" ? ["Iops", "Throughput"] : value === "io1" || value === "io2" ? ["Throughput"] : []
20582
+ };
20583
+ function revertOp(f, recorded, identity, declaredModel) {
20141
20584
  const pointer = toPointer(f.path);
20142
20585
  if (f.tier === "declared") return {
20143
20586
  op: "add",
@@ -20161,6 +20604,14 @@ function revertOp(f, recorded, identity) {
20161
20604
  prior: f.actual,
20162
20605
  human: `${f.path} -> baseline value`
20163
20606
  };
20607
+ const derivedDefault = derivedRevertDefaultFor(f.resourceType, f.path, declaredModel);
20608
+ if (derivedDefault !== void 0) return {
20609
+ op: "add",
20610
+ path: pointer,
20611
+ value: derivedDefault,
20612
+ prior: f.actual,
20613
+ human: `${f.path} -> AWS default (derived from declared inputs)`
20614
+ };
20164
20615
  const setDefaultKey = `${f.resourceType}\0${f.path}`;
20165
20616
  const knownDefault = KNOWN_DEFAULTS[f.resourceType]?.[f.path] ?? REVERT_SET_DEFAULT_VALUES[setDefaultKey] ?? contextArnDefaultFor(f.resourceType, f.path, identity);
20166
20617
  if (knownDefault !== void 0 && REVERT_SET_DEFAULT_PATHS.has(setDefaultKey)) return {
@@ -21200,7 +21651,8 @@ async function revertStack(p) {
21200
21651
  identity: {
21201
21652
  accountId: gathered.desired.accountId,
21202
21653
  region
21203
- }
21654
+ },
21655
+ declaredForLogical
21204
21656
  });
21205
21657
  if (plan.items.length === 0 && plan.notRevertable.length === 0) {
21206
21658
  out(style.clean(`${stackName} (${region}): no drift to revert.`));