@go-to-k/cdkd 0.207.4 → 0.207.6

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
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { a as setAwsClients, i as resetAwsClients, r as getAwsClients, t as AwsClients } from "./aws-clients-DWUnLza1.js";
3
- import { $ as findLargeInlineResources, A as LockManager, At as getLiveRenderer, B as runDockerStreaming, C as CloudControlProvider, D as DiffCalculator, Dt as getLogger, E as applyRoleArnIfSet, F as WorkGraph, Ft as withSkipPrefix, G as resolveCaptureObservedState, H as getDefaultStateBucketName, I as buildDockerImage, It as withStackName, J as resolveStateBucketWithDefaultAndSource, K as resolveSkipPrefix, L as formatDockerLoginError, M as shouldRetainResource, Mt as PATTERN_B_RESOURCE_TYPES, N as AssetPublisher, Nt as generateResourceName, O as DagBuilder, P as stringifyValue, Pt as generateResourceNameWithFallback, Q as MIGRATE_TMP_PREFIX, R as getDockerCmd, S as findActionableSilentDrops, T as IntrinsicFunctionResolver, Tt as withErrorHandling, U as getLegacyStateBucketName, V as Synthesizer, W as resolveApp, X as CFN_TEMPLATE_BODY_LIMIT, Y as warnDeprecatedNoPrefixCliFlag, Z as CFN_TEMPLATE_URL_LIMIT, _ as CDK_PATH_TAG, _t as ResourceUpdateNotSupportedError, a as withRetry, at as CdkdError, b as resolveExplicitPhysicalId, c as formatResourceLine, ct as LocalInvokeBuildError$1, d as gray, et as uploadCfnTemplate, f as green, ft as MissingCdkCliError, g as collectInlinePolicyNamesManagedBySiblings, gt as ResourceTimeoutError, h as IAMRoleProvider, ht as ProvisioningError, i as withResourceDeadline, j as S3StateBackend, jt as PATTERN_B_NAME_PROPERTIES, k as TemplateParser, kt as runStackBuffered, l as bold, lt as LocalMigrateError, m as yellow, mt as PartialFailureError, n as DEFAULT_RESOURCE_WARN_AFTER_MS, o as isRetryableTransientError, p as red, pt as NestedStackChildDirectDestroyError, q as resolveStateBucketWithDefault, r as DeployEngine, rt as resolveBucketRegion, s as IMPLICIT_DELETE_DEPENDENCIES, t as DEFAULT_RESOURCE_TIMEOUT_MS, tt as AssemblyReader, u as cyan, ut as LocalStartServiceError, v as matchesCdkPath, vt as StackHasActiveImportsError, w as assertRegionMatch, wt as normalizeAwsError, x as ProviderRegistry, y as normalizeAwsTagsToCfn, yt as StackTerminationProtectionError, z as runDockerForeground } from "./deploy-engine-ai3rix-L.js";
3
+ import { $ as CFN_TEMPLATE_URL_LIMIT, A as DagBuilder, B as getDockerCmd, C as CloudControlProvider, D as IntrinsicFunctionResolver, Dt as withErrorHandling, E as isTerminationProtectionPropagationError, Et as normalizeAwsError, F as AssetPublisher, Ft as generateResourceName, G as getLegacyStateBucketName, H as runDockerStreaming, I as stringifyValue, It as generateResourceNameWithFallback, J as resolveSkipPrefix, K as resolveApp, L as WorkGraph, Lt as withSkipPrefix, M as LockManager, Mt as getLiveRenderer, N as S3StateBackend, Nt as PATTERN_B_NAME_PROPERTIES, O as applyRoleArnIfSet, P as shouldRetainResource, Pt as PATTERN_B_RESOURCE_TYPES, Q as CFN_TEMPLATE_BODY_LIMIT, R as buildDockerImage, Rt as withStackName, S as findActionableSilentDrops, T as disableInstanceApiTermination, U as Synthesizer, V as runDockerForeground, W as getDefaultStateBucketName, X as resolveStateBucketWithDefaultAndSource, Y as resolveStateBucketWithDefault, Z as warnDeprecatedNoPrefixCliFlag, _ as CDK_PATH_TAG, _t as ProvisioningError, a as withRetry, at as resolveBucketRegion, b as resolveExplicitPhysicalId, bt as StackHasActiveImportsError, c as formatResourceLine, d as gray, dt as LocalMigrateError, et as MIGRATE_TMP_PREFIX, f as green, ft as LocalStartServiceError, g as collectInlinePolicyNamesManagedBySiblings, gt as PartialFailureError, h as IAMRoleProvider, ht as NestedStackChildDirectDestroyError, i as withResourceDeadline, j as TemplateParser, jt as runStackBuffered, k as DiffCalculator, kt as getLogger, l as bold, m as yellow, mt as MissingCdkCliError, n as DEFAULT_RESOURCE_WARN_AFTER_MS, nt as uploadCfnTemplate, o as isRetryableTransientError, p as red, q as resolveCaptureObservedState, r as DeployEngine, rt as AssemblyReader, s as IMPLICIT_DELETE_DEPENDENCIES, st as CdkdError, t as DEFAULT_RESOURCE_TIMEOUT_MS, tt as findLargeInlineResources, u as cyan, ut as LocalInvokeBuildError$1, v as matchesCdkPath, vt as ResourceTimeoutError, w as assertRegionMatch, x as ProviderRegistry, xt as StackTerminationProtectionError, y as normalizeAwsTagsToCfn, yt as ResourceUpdateNotSupportedError, z as formatDockerLoginError } from "./deploy-engine-DMggQBl4.js";
4
4
  import { AsyncLocalStorage } from "node:async_hooks";
5
5
  import { randomBytes, randomUUID } from "node:crypto";
6
6
  import { CopyObjectCommand, CreateBucketCommand, DeleteBucketAnalyticsConfigurationCommand, DeleteBucketCommand, DeleteBucketCorsCommand, DeleteBucketIntelligentTieringConfigurationCommand, DeleteBucketInventoryConfigurationCommand, DeleteBucketLifecycleCommand, DeleteBucketMetricsConfigurationCommand, DeleteBucketPolicyCommand, DeleteBucketReplicationCommand, DeleteBucketTaggingCommand, DeleteBucketWebsiteCommand, DeleteObjectsCommand, GetBucketAccelerateConfigurationCommand, GetBucketCorsCommand, GetBucketEncryptionCommand, GetBucketLifecycleConfigurationCommand, GetBucketLocationCommand, GetBucketLoggingCommand, GetBucketNotificationConfigurationCommand, GetBucketPolicyCommand, GetBucketReplicationCommand, GetBucketTaggingCommand, GetBucketVersioningCommand, GetBucketWebsiteCommand, GetObjectCommand, GetObjectLockConfigurationCommand, GetPublicAccessBlockCommand, HeadBucketCommand, ListBucketAnalyticsConfigurationsCommand, ListBucketIntelligentTieringConfigurationsCommand, ListBucketInventoryConfigurationsCommand, ListBucketMetricsConfigurationsCommand, ListBucketsCommand, ListDirectoryBucketsCommand, ListObjectVersionsCommand, ListObjectsV2Command, NoSuchBucket, PutBucketAccelerateConfigurationCommand, PutBucketAnalyticsConfigurationCommand, PutBucketCorsCommand, PutBucketEncryptionCommand, PutBucketIntelligentTieringConfigurationCommand, PutBucketInventoryConfigurationCommand, PutBucketLifecycleConfigurationCommand, PutBucketLoggingCommand, PutBucketMetricsConfigurationCommand, PutBucketNotificationConfigurationCommand, PutBucketOwnershipControlsCommand, PutBucketPolicyCommand, PutBucketReplicationCommand, PutBucketTaggingCommand, PutBucketVersioningCommand, PutBucketWebsiteCommand, PutObjectCommand, PutObjectLockConfigurationCommand, PutPublicAccessBlockCommand, S3Client, S3ServiceException } from "@aws-sdk/client-s3";
@@ -9,7 +9,7 @@ import { CreateQueueCommand, DeleteQueueCommand, GetQueueAttributesCommand, GetQ
9
9
  import { CreateTopicCommand, DeleteTopicCommand, GetSubscriptionAttributesCommand, GetTopicAttributesCommand, ListTagsForResourceCommand, ListTopicsCommand, NotFoundException, SNSClient, SetTopicAttributesCommand, SubscribeCommand, TagResourceCommand, UnsubscribeCommand, UntagResourceCommand } from "@aws-sdk/client-sns";
10
10
  import { AddPermissionCommand, CreateEventSourceMappingCommand, CreateFunctionCommand, CreateFunctionUrlConfigCommand, DeleteEventSourceMappingCommand, DeleteFunctionCommand, DeleteFunctionConcurrencyCommand, DeleteFunctionUrlConfigCommand, DeleteLayerVersionCommand, GetEventSourceMappingCommand, GetFunctionCommand, GetFunctionConcurrencyCommand, GetFunctionRecursionConfigCommand, GetFunctionUrlConfigCommand, GetLayerVersionByArnCommand, GetPolicyCommand as GetPolicyCommand$1, LambdaClient, ListFunctionsCommand, ListLayersCommand, ListTagsCommand, PublishLayerVersionCommand, PutFunctionConcurrencyCommand, PutFunctionRecursionConfigCommand, RemovePermissionCommand, ResourceNotFoundException, TagResourceCommand as TagResourceCommand$1, UntagResourceCommand as UntagResourceCommand$1, UpdateEventSourceMappingCommand, UpdateFunctionCodeCommand, UpdateFunctionConfigurationCommand, UpdateFunctionUrlConfigCommand, waitUntilFunctionUpdatedV2 } from "@aws-sdk/client-lambda";
11
11
  import { AssumeRoleCommand, GetCallerIdentityCommand, STSClient } from "@aws-sdk/client-sts";
12
- import { AssociateRouteTableCommand, AttachInternetGatewayCommand, AuthorizeSecurityGroupEgressCommand, AuthorizeSecurityGroupIngressCommand, CreateInternetGatewayCommand, CreateNatGatewayCommand, CreateNetworkAclCommand, CreateNetworkAclEntryCommand, CreateRouteCommand, CreateRouteTableCommand, CreateSecurityGroupCommand, CreateSubnetCommand, CreateTagsCommand, CreateVpcCommand, DeleteInternetGatewayCommand, DeleteNatGatewayCommand, DeleteNetworkAclCommand, DeleteNetworkAclEntryCommand, DeleteNetworkInterfaceCommand, DeleteRouteCommand, DeleteRouteTableCommand, DeleteSecurityGroupCommand, DeleteSubnetCommand, DeleteTagsCommand, DeleteVpcCommand, DescribeAvailabilityZonesCommand, DescribeInstanceAttributeCommand, DescribeInstancesCommand, DescribeInternetGatewaysCommand, DescribeNatGatewaysCommand, DescribeNetworkAclsCommand, DescribeNetworkInterfacesCommand, DescribeRouteTablesCommand, DescribeSecurityGroupsCommand, DescribeSubnetsCommand, DescribeVolumesCommand, DescribeVpcAttributeCommand, DescribeVpcsCommand, DetachInternetGatewayCommand, DisassociateRouteTableCommand, EC2Client, ModifyInstanceAttributeCommand, ModifySubnetAttributeCommand, ModifyVpcAttributeCommand, ReplaceNetworkAclAssociationCommand, RevokeSecurityGroupEgressCommand, RevokeSecurityGroupIngressCommand, RunInstancesCommand, TerminateInstancesCommand, waitUntilInstanceRunning, waitUntilInstanceTerminated, waitUntilNatGatewayAvailable, waitUntilNatGatewayDeleted } from "@aws-sdk/client-ec2";
12
+ import { AssociateRouteTableCommand, AttachInternetGatewayCommand, AuthorizeSecurityGroupEgressCommand, AuthorizeSecurityGroupIngressCommand, CreateInternetGatewayCommand, CreateNatGatewayCommand, CreateNetworkAclCommand, CreateNetworkAclEntryCommand, CreateRouteCommand, CreateRouteTableCommand, CreateSecurityGroupCommand, CreateSubnetCommand, CreateTagsCommand, CreateVpcCommand, DeleteInternetGatewayCommand, DeleteNatGatewayCommand, DeleteNetworkAclCommand, DeleteNetworkAclEntryCommand, DeleteNetworkInterfaceCommand, DeleteRouteCommand, DeleteRouteTableCommand, DeleteSecurityGroupCommand, DeleteSubnetCommand, DeleteTagsCommand, DeleteVpcCommand, DescribeAvailabilityZonesCommand, DescribeInstanceAttributeCommand, DescribeInstancesCommand, DescribeInternetGatewaysCommand, DescribeNatGatewaysCommand, DescribeNetworkAclsCommand, DescribeNetworkInterfacesCommand, DescribeRouteTablesCommand, DescribeSecurityGroupsCommand, DescribeSubnetsCommand, DescribeVolumesCommand, DescribeVpcAttributeCommand, DescribeVpcsCommand, DetachInternetGatewayCommand, DisassociateRouteTableCommand, EC2Client, ModifySubnetAttributeCommand, ModifyVpcAttributeCommand, ReplaceNetworkAclAssociationCommand, RevokeSecurityGroupEgressCommand, RevokeSecurityGroupIngressCommand, RunInstancesCommand, TerminateInstancesCommand, waitUntilInstanceRunning, waitUntilInstanceTerminated, waitUntilNatGatewayAvailable, waitUntilNatGatewayDeleted } from "@aws-sdk/client-ec2";
13
13
  import { CreateTableCommand, DeleteTableCommand, DescribeContinuousBackupsCommand, DescribeContributorInsightsCommand, DescribeKinesisStreamingDestinationCommand, DescribeTableCommand, DescribeTimeToLiveCommand, DynamoDBClient, ListTablesCommand, ListTagsOfResourceCommand, ResourceNotFoundException as ResourceNotFoundException$1, TagResourceCommand as TagResourceCommand$2, UntagResourceCommand as UntagResourceCommand$2, UpdateContinuousBackupsCommand, UpdateTableCommand, UpdateTimeToLiveCommand } from "@aws-sdk/client-dynamodb";
14
14
  import { CloudFormationClient, CreateChangeSetCommand, DeleteChangeSetCommand, DeleteStackCommand, DescribeChangeSetCommand, DescribeStackEventsCommand, DescribeStackResourcesCommand, DescribeStacksCommand, DescribeTypeCommand, ExecuteChangeSetCommand, GetTemplateCommand, UpdateStackCommand, waitUntilChangeSetCreateComplete, waitUntilStackDeleteComplete, waitUntilStackImportComplete, waitUntilStackUpdateComplete } from "@aws-sdk/client-cloudformation";
15
15
  import { APIGatewayClient, CreateAuthorizerCommand, CreateDeploymentCommand, CreateResourceCommand, CreateStageCommand, DeleteAuthorizerCommand, DeleteDeploymentCommand, DeleteMethodCommand, DeleteResourceCommand, DeleteStageCommand, GetAccountCommand, GetAuthorizerCommand, GetDeploymentCommand, GetMethodCommand, GetResourceCommand, GetStageCommand, NotFoundException as NotFoundException$1, PutIntegrationCommand, PutIntegrationResponseCommand, PutMethodCommand, PutMethodResponseCommand, TagResourceCommand as TagResourceCommand$3, UntagResourceCommand as UntagResourceCommand$3, UpdateAccountCommand, UpdateAuthorizerCommand, UpdateMethodCommand, UpdateStageCommand } from "@aws-sdk/client-api-gateway";
@@ -11888,6 +11888,33 @@ var SSMParameterProvider = class {
11888
11888
  this.ssmClient = awsClients.ssm;
11889
11889
  }
11890
11890
  /**
11891
+ * Normalize a CFn `AWS::SSM::Parameter.Tags` value into the SDK `Tag[]`
11892
+ * shape. Unlike most CFn resources (whose `Tags` is a `{Key,Value}[]` list),
11893
+ * `AWS::SSM::Parameter.Tags` is a key->value **map** (`{ "Env": "prod" }`) —
11894
+ * CDK synthesizes the map form, so `properties['Tags'].map(...)` throws
11895
+ * `Tags.map is not a function`. Accept the map (canonical) AND the list
11896
+ * (defensive, in case a hand-authored / escape-hatched template supplies it),
11897
+ * coerce each value to a string (SSM tag values must be strings), and drop
11898
+ * `aws:`-prefixed reserved keys (AWS rejects user attempts to set them).
11899
+ */
11900
+ cfnTagsToSdkTags(raw) {
11901
+ if (raw === void 0 || raw === null) return [];
11902
+ const coerce = (v) => typeof v === "string" ? v : typeof v === "number" || typeof v === "boolean" ? String(v) : "";
11903
+ let entries;
11904
+ if (Array.isArray(raw)) entries = raw.map((t) => [t?.["Key"], t?.["Value"]]);
11905
+ else if (typeof raw === "object") entries = Object.entries(raw);
11906
+ else entries = [];
11907
+ const out = [];
11908
+ for (const [key, value] of entries) {
11909
+ if (typeof key !== "string" || key.length === 0 || key.startsWith("aws:")) continue;
11910
+ out.push({
11911
+ Key: key,
11912
+ Value: coerce(value)
11913
+ });
11914
+ }
11915
+ return out;
11916
+ }
11917
+ /**
11891
11918
  * Create an SSM parameter
11892
11919
  */
11893
11920
  async create(logicalId, resourceType, properties) {
@@ -11913,17 +11940,12 @@ var SSMParameterProvider = class {
11913
11940
  if (properties["DataType"]) putParams.DataType = properties["DataType"];
11914
11941
  await this.ssmClient.send(new PutParameterCommand(putParams));
11915
11942
  try {
11916
- if (properties["Tags"]) {
11917
- const ssmTags = properties["Tags"].map((t) => ({
11918
- Key: t.Key,
11919
- Value: t.Value
11920
- }));
11921
- await this.ssmClient.send(new AddTagsToResourceCommand({
11922
- ResourceType: "Parameter",
11923
- ResourceId: name,
11924
- Tags: ssmTags
11925
- }));
11926
- }
11943
+ const ssmTags = this.cfnTagsToSdkTags(properties["Tags"]);
11944
+ if (ssmTags.length > 0) await this.ssmClient.send(new AddTagsToResourceCommand({
11945
+ ResourceType: "Parameter",
11946
+ ResourceId: name,
11947
+ Tags: ssmTags
11948
+ }));
11927
11949
  } catch (innerError) {
11928
11950
  try {
11929
11951
  await this.ssmClient.send(new DeleteParameterCommand({ Name: name }));
@@ -11967,25 +11989,21 @@ var SSMParameterProvider = class {
11967
11989
  if (properties["Policies"] !== void 0) putParams.Policies = properties["Policies"];
11968
11990
  if (properties["DataType"] !== void 0) putParams.DataType = properties["DataType"];
11969
11991
  await this.ssmClient.send(new PutParameterCommand(putParams));
11970
- const newTags = properties["Tags"];
11971
- const oldTags = previousProperties["Tags"];
11972
- if (JSON.stringify(newTags) !== JSON.stringify(oldTags)) {
11973
- if (oldTags && oldTags.length > 0) await this.ssmClient.send(new RemoveTagsFromResourceCommand({
11992
+ const newTags = this.cfnTagsToSdkTags(properties["Tags"]);
11993
+ const oldTags = this.cfnTagsToSdkTags(previousProperties["Tags"]);
11994
+ const tagKey = (t) => t.Key;
11995
+ const sortedJson = (tags) => JSON.stringify([...tags].sort((a, b) => tagKey(a).localeCompare(tagKey(b))));
11996
+ if (sortedJson(newTags) !== sortedJson(oldTags)) {
11997
+ if (oldTags.length > 0) await this.ssmClient.send(new RemoveTagsFromResourceCommand({
11974
11998
  ResourceType: "Parameter",
11975
11999
  ResourceId: physicalId,
11976
12000
  TagKeys: oldTags.map((t) => t.Key)
11977
12001
  }));
11978
- if (newTags && newTags.length > 0) {
11979
- const ssmTags = newTags.map((t) => ({
11980
- Key: t.Key,
11981
- Value: t.Value
11982
- }));
11983
- await this.ssmClient.send(new AddTagsToResourceCommand({
11984
- ResourceType: "Parameter",
11985
- ResourceId: physicalId,
11986
- Tags: ssmTags
11987
- }));
11988
- }
12002
+ if (newTags.length > 0) await this.ssmClient.send(new AddTagsToResourceCommand({
12003
+ ResourceType: "Parameter",
12004
+ ResourceId: physicalId,
12005
+ Tags: newTags
12006
+ }));
11989
12007
  this.logger.debug(`Updated tags for SSM parameter ${physicalId}`);
11990
12008
  }
11991
12009
  this.logger.debug(`Successfully updated SSM parameter ${logicalId}`);
@@ -12096,10 +12114,11 @@ var SSMParameterProvider = class {
12096
12114
  } catch {}
12097
12115
  if (!policiesEmitted) result["Policies"] = [];
12098
12116
  try {
12099
- result["Tags"] = normalizeAwsTagsToCfn((await this.ssmClient.send(new ListTagsForResourceCommand$2({
12117
+ const tagArr = normalizeAwsTagsToCfn((await this.ssmClient.send(new ListTagsForResourceCommand$2({
12100
12118
  ResourceType: "Parameter",
12101
12119
  ResourceId: physicalId
12102
12120
  }))).TagList);
12121
+ result["Tags"] = Object.fromEntries(tagArr.map((t) => [t.Key, t.Value]));
12103
12122
  } catch {}
12104
12123
  return result;
12105
12124
  }
@@ -13815,16 +13834,10 @@ var EC2Provider = class {
13815
13834
  }
13816
13835
  async deleteInstance(logicalId, physicalId, resourceType, context) {
13817
13836
  this.logger.debug(`Terminating EC2 Instance ${logicalId}: ${physicalId}`);
13818
- if (context?.removeProtection === true) try {
13819
- await this.ec2Client.send(new ModifyInstanceAttributeCommand({
13820
- InstanceId: physicalId,
13821
- DisableApiTermination: { Value: false }
13822
- }));
13823
- this.logger.debug(`Disabled DisableApiTermination on EC2 Instance ${logicalId} before termination`);
13824
- } catch (flipError) {
13825
- if (!this.isNotFoundError(flipError)) this.logger.debug(`Could not disable DisableApiTermination on ${physicalId}: ${flipError instanceof Error ? flipError.message : String(flipError)}`);
13826
- }
13827
- try {
13837
+ const removeProtection = context?.removeProtection === true;
13838
+ if (removeProtection) await disableInstanceApiTermination(this.ec2Client, physicalId, this.logger);
13839
+ const maxTerminateAttempts = removeProtection ? 5 : 1;
13840
+ for (let attempt = 1;; attempt++) try {
13828
13841
  await this.ec2Client.send(new TerminateInstancesCommand({ InstanceIds: [physicalId] }));
13829
13842
  this.logger.debug(`Terminate requested for EC2 Instance ${logicalId}, waiting...`);
13830
13843
  await waitUntilInstanceTerminated({
@@ -13832,14 +13845,22 @@ var EC2Provider = class {
13832
13845
  maxWaitTime: 300
13833
13846
  }, { InstanceIds: [physicalId] });
13834
13847
  this.logger.debug(`EC2 Instance ${logicalId} terminated: ${physicalId}`);
13848
+ return;
13835
13849
  } catch (error) {
13836
13850
  if (this.isNotFoundError(error)) {
13837
13851
  assertRegionMatch(await this.ec2Client.config.region(), context?.expectedRegion, resourceType, logicalId, physicalId);
13838
13852
  this.logger.debug(`EC2 Instance ${physicalId} already terminated (not found), treating as success`);
13839
13853
  return;
13840
13854
  }
13855
+ const msg = error instanceof Error ? error.message : String(error);
13856
+ if (removeProtection && isTerminationProtectionPropagationError(msg) && attempt < maxTerminateAttempts) {
13857
+ this.logger.debug(`Terminate of EC2 Instance ${logicalId} raced the DisableApiTermination flip-off (attempt ${attempt}/${maxTerminateAttempts}); re-flipping and retrying`);
13858
+ await disableInstanceApiTermination(this.ec2Client, physicalId, this.logger);
13859
+ await this.sleep(3e3 * attempt);
13860
+ continue;
13861
+ }
13841
13862
  const cause = error instanceof Error ? error : void 0;
13842
- throw new ProvisioningError(`Failed to terminate EC2 Instance ${logicalId}: ${error instanceof Error ? error.message : String(error)}`, resourceType, logicalId, physicalId, cause);
13863
+ throw new ProvisioningError(`Failed to terminate EC2 Instance ${logicalId}: ${msg}`, resourceType, logicalId, physicalId, cause);
13843
13864
  }
13844
13865
  }
13845
13866
  async getInstanceAttribute(physicalId, attributeName) {
@@ -52657,6 +52678,31 @@ function createMigrateCommand() {
52657
52678
  return new Command("migrate").description("Adopt a plain (non-CDK) CloudFormation stack into a cdkd-managed CDK app. Generates new CDK code via upstream `cdk migrate`, builds a logical-ID mapping between the source CFn template and the synth template, writes cdkd state, and (optionally) retires the source CFn stack. AWS resources are never modified.").argument("[stack]", "Source CFn stack name. Alias for --from-cfn-stack.").addOption(new Option("--from-cfn-stack <name>", "Source CloudFormation stack name to adopt. Required (or pass positionally).")).addOption(new Option("--output-dir <dir>", "Directory to write the generated CDK app to. Defaults to <cwd>/<CfnStackName>.")).addOption(new Option("--language <choice>", "Generated code language. v1: typescript only.").choices(["typescript"]).default("typescript")).addOption(new Option("--region <region>", "AWS region. Defaults to AWS_REGION env / profile.")).addOption(new Option("--account <id>", "AWS account ID. Auto-detected via STS when omitted.")).addOption(new Option("--retire-cfn-stack", "After cdkd state is written, inject DeletionPolicy=Retain on every resource in the source CFn stack and DeleteStack. AWS resources stay; the CFn stack record is gone. Off by default.").default(false)).addOption(new Option("--filter <key=value>", "Pass-through to `cdk migrate --filter` for resource subsetting. Repeatable.").argParser((value, previous) => [...previous ?? [], value]).default([])).addOption(new Option("--skip-install", "Skip `npm install` after codegen.").default(false)).addOption(new Option("--skip-synth", "Skip `cdk synth` (does NOT write cdkd state). Mutually exclusive with --retire-cfn-stack.").default(false)).addOption(new Option("--dry-run", "Print the import plan without writing state or retiring the CFn stack. Mutually exclusive with --retire-cfn-stack.").default(false)).addOption(new Option("-y, --yes", "Auto-confirm the import + retirement prompts.").default(false)).addOption(new Option("--cdk-bin <path>", "Override the `cdk` binary path.")).addOption(new Option("--resource-mapping <file>", `Path to a JSON file of {sourceLogicalId: synthLogicalId} overrides. Same shape as the auto-written ${RESOURCE_MAPPING_FILENAME}.`)).addOption(new Option("--state-bucket <name>", "cdkd state bucket. Defaults to cdkd-state-<accountId>.")).addOption(new Option("--state-prefix <prefix>", "cdkd state prefix inside the bucket.").default("cdkd")).addOption(new Option("--profile <name>", "AWS profile name.")).addOption(new Option("--role-arn <arn>", "IAM role to assume before any AWS call.")).addOption(new Option("--verbose", "Enable debug-level logging.").default(false)).action(withErrorHandling(migrateCommandAction));
52658
52679
  }
52659
52680
 
52681
+ //#endregion
52682
+ //#region src/cli/pipe-close-handler.ts
52683
+ /**
52684
+ * Exit cleanly when a downstream consumer closes our stdout/stderr early.
52685
+ *
52686
+ * Piping a cdkd command into a reader that stops reading — `cdkd state list |
52687
+ * grep -q foo`, `... | head`, `... | less` then `q` — closes the pipe while
52688
+ * cdkd is still writing. Node then emits an unhandled `'error'` (EPIPE) on the
52689
+ * stream and the process dies with a stack trace + non-zero exit. That is
52690
+ * normal Unix behavior for the *consumer* to stop reading, so the CLI must
52691
+ * treat it as success, not a crash. (Surfaced by the `remove-protection` integ,
52692
+ * whose `cdkd state list | grep -q` assertion crashed cdkd on EPIPE and the
52693
+ * test misread the non-zero exit as a stripped-state failure.)
52694
+ *
52695
+ * Installed once before any command runs so it covers every subcommand's
52696
+ * output, including long / streamed listings. Non-EPIPE stream errors are
52697
+ * re-thrown unchanged (they are real faults, not a closed pipe).
52698
+ */
52699
+ function installPipeCloseHandler(streams = [process.stdout, process.stderr], exit = process.exit) {
52700
+ for (const stream of streams) stream.on("error", (err) => {
52701
+ if (err.code !== "EPIPE") throw err;
52702
+ exit(0);
52703
+ });
52704
+ }
52705
+
52660
52706
  //#endregion
52661
52707
  //#region src/cli/index.ts
52662
52708
  const SUBCOMMANDS = new Set([
@@ -52698,8 +52744,9 @@ function reorderArgs(argv) {
52698
52744
  * Main CLI program
52699
52745
  */
52700
52746
  async function main() {
52747
+ installPipeCloseHandler();
52701
52748
  const program = new Command();
52702
- program.name("cdkd").description("CDK Direct - Deploy AWS CDK apps directly via SDK/Cloud Control API").version("0.207.4");
52749
+ program.name("cdkd").description("CDK Direct - Deploy AWS CDK apps directly via SDK/Cloud Control API").version("0.207.6");
52703
52750
  program.addCommand(createBootstrapCommand());
52704
52751
  program.addCommand(createSynthCommand());
52705
52752
  program.addCommand(createListCommand());