@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.
@@ -7,7 +7,7 @@ import { AttachRolePolicyCommand, CreateRoleCommand, DeleteRoleCommand, DeleteRo
7
7
  import { PublishCommand, SNSClient } from "@aws-sdk/client-sns";
8
8
  import { GetFunctionUrlConfigCommand, InvokeCommand, LambdaClient, UpdateFunctionConfigurationCommand, waitUntilFunctionActiveV2, waitUntilFunctionUpdatedV2 } from "@aws-sdk/client-lambda";
9
9
  import { AssumeRoleCommand, GetCallerIdentityCommand, STSClient } from "@aws-sdk/client-sts";
10
- import { DescribeAvailabilityZonesCommand, DescribeImagesCommand, DescribeLaunchTemplatesCommand, DescribeRouteTablesCommand, DescribeSecurityGroupsCommand, DescribeSubnetsCommand, DescribeVpcsCommand, DescribeVpnGatewaysCommand, EC2Client } from "@aws-sdk/client-ec2";
10
+ import { DescribeAvailabilityZonesCommand, DescribeImagesCommand, DescribeLaunchTemplatesCommand, DescribeRouteTablesCommand, DescribeSecurityGroupsCommand, DescribeSubnetsCommand, DescribeVpcsCommand, DescribeVpnGatewaysCommand, EC2Client, ModifyInstanceAttributeCommand } from "@aws-sdk/client-ec2";
11
11
  import { DescribeTableCommand } from "@aws-sdk/client-dynamodb";
12
12
  import { CloudFormationClient, CreateChangeSetCommand, DeleteStackCommand, DescribeChangeSetCommand, GetTemplateCommand, waitUntilChangeSetCreateComplete } from "@aws-sdk/client-cloudformation";
13
13
  import { GetRestApiCommand } from "@aws-sdk/client-api-gateway";
@@ -7615,6 +7615,36 @@ var IntrinsicFunctionResolver = class {
7615
7615
  }
7616
7616
  };
7617
7617
 
7618
+ //#endregion
7619
+ //#region src/provisioning/ec2-termination-protection.ts
7620
+ /**
7621
+ * Flip `DisableApiTermination` off on an instance. Idempotent — EC2 accepts the
7622
+ * call when the attribute is already false. Non-fatal: a NotFound (already
7623
+ * gone) or any other error is swallowed at debug so the actual delete still
7624
+ * proceeds (it will surface the real failure if the instance truly cannot be
7625
+ * deleted).
7626
+ */
7627
+ async function disableInstanceApiTermination(client, instanceId, logger) {
7628
+ try {
7629
+ await client.send(new ModifyInstanceAttributeCommand({
7630
+ InstanceId: instanceId,
7631
+ DisableApiTermination: { Value: false }
7632
+ }));
7633
+ logger.debug(`Disabled DisableApiTermination on EC2 Instance ${instanceId} before deletion`);
7634
+ } catch (flipError) {
7635
+ logger.debug(`Could not disable DisableApiTermination on ${instanceId}: ${flipError instanceof Error ? flipError.message : String(flipError)}`);
7636
+ }
7637
+ }
7638
+ /**
7639
+ * Does this error message indicate the terminate / delete raced the
7640
+ * `DisableApiTermination` flip-off propagation (so re-flipping + retrying is
7641
+ * the right move)? Matches both the SDK `TerminateInstances` 400 and the Cloud
7642
+ * Control `DeleteResource` wrapper of the same underlying EC2 error.
7643
+ */
7644
+ function isTerminationProtectionPropagationError(message) {
7645
+ return /may not be terminated|disableApiTermination/i.test(message);
7646
+ }
7647
+
7618
7648
  //#endregion
7619
7649
  //#region src/provisioning/json-patch-generator.ts
7620
7650
  /**
@@ -8096,7 +8126,10 @@ var CloudControlProvider = class {
8096
8126
  */
8097
8127
  async delete(logicalId, physicalId, resourceType, _properties, context) {
8098
8128
  this.logger.debug(`Deleting resource ${logicalId} (${resourceType}), physical ID: ${physicalId}`);
8099
- try {
8129
+ const isProtectedEc2Instance = context?.removeProtection === true && resourceType === "AWS::EC2::Instance";
8130
+ if (isProtectedEc2Instance) await disableInstanceApiTermination(getAwsClients().ec2, physicalId, this.logger);
8131
+ const maxAttempts = isProtectedEc2Instance ? 5 : 1;
8132
+ for (let attempt = 1;; attempt++) try {
8100
8133
  const deleteResponse = await this.cloudControlClient.send(new DeleteResourceCommand({
8101
8134
  TypeName: resourceType,
8102
8135
  Identifier: physicalId
@@ -8105,6 +8138,7 @@ var CloudControlProvider = class {
8105
8138
  this.logger.debug(`Delete request submitted for ${logicalId}, token: ${deleteResponse.ProgressEvent.RequestToken}`);
8106
8139
  await this.waitForOperation(deleteResponse.ProgressEvent.RequestToken, logicalId, "DELETE");
8107
8140
  this.logger.debug(`Deleted resource ${logicalId}`);
8141
+ return;
8108
8142
  } catch (error) {
8109
8143
  const err = error;
8110
8144
  if (err.name === "ResourceNotFoundException" || err.message?.includes("does not exist") || err.message?.includes("not found") || err.message?.includes("NotFound")) {
@@ -8112,6 +8146,12 @@ var CloudControlProvider = class {
8112
8146
  this.logger.debug(`Resource ${logicalId} already deleted (not found), treating as success`);
8113
8147
  return;
8114
8148
  }
8149
+ if (isProtectedEc2Instance && isTerminationProtectionPropagationError(err.message ?? "") && attempt < maxAttempts) {
8150
+ this.logger.debug(`Cloud Control delete of ${logicalId} raced the DisableApiTermination flip-off (attempt ${attempt}/${maxAttempts}); re-flipping and retrying`);
8151
+ await disableInstanceApiTermination(getAwsClients().ec2, physicalId, this.logger);
8152
+ await this.sleep(3e3 * attempt);
8153
+ continue;
8154
+ }
8115
8155
  this.handleError(error, "DELETE", resourceType, logicalId, physicalId);
8116
8156
  }
8117
8157
  }
@@ -13706,5 +13746,5 @@ var DeployEngine = class {
13706
13746
  };
13707
13747
 
13708
13748
  //#endregion
13709
- export { findLargeInlineResources as $, LockManager as A, getLiveRenderer as At, runDockerStreaming as B, CloudControlProvider as C, isCdkdError as Ct, DiffCalculator as D, getLogger as Dt, applyRoleArnIfSet as E, ConsoleLogger as Et, WorkGraph as F, withSkipPrefix as Ft, resolveCaptureObservedState as G, getDefaultStateBucketName as H, buildDockerImage as I, withStackName as It, resolveStateBucketWithDefaultAndSource as J, resolveSkipPrefix as K, formatDockerLoginError as L, shouldRetainResource as M, PATTERN_B_RESOURCE_TYPES as Mt, AssetPublisher as N, generateResourceName as Nt, DagBuilder as O, setLogger as Ot, stringifyValue as P, generateResourceNameWithFallback as Pt, MIGRATE_TMP_PREFIX as Q, getDockerCmd as R, findActionableSilentDrops as S, formatError as St, IntrinsicFunctionResolver as T, withErrorHandling as Tt, getLegacyStateBucketName as U, Synthesizer as V, resolveApp as W, CFN_TEMPLATE_BODY_LIMIT as X, warnDeprecatedNoPrefixCliFlag as Y, CFN_TEMPLATE_URL_LIMIT as Z, CDK_PATH_TAG as _, ResourceUpdateNotSupportedError as _t, withRetry as a, CdkdError as at, resolveExplicitPhysicalId as b, StateError as bt, formatResourceLine as c, LocalInvokeBuildError as ct, gray as d, LockError as dt, uploadCfnTemplate as et, green as f, MissingCdkCliError as ft, collectInlinePolicyNamesManagedBySiblings as g, ResourceTimeoutError as gt, IAMRoleProvider as h, ProvisioningError as ht, withResourceDeadline as i, AssetError as it, S3StateBackend as j, PATTERN_B_NAME_PROPERTIES as jt, TemplateParser as k, runStackBuffered as kt, bold as l, LocalMigrateError as lt, yellow as m, PartialFailureError as mt, DEFAULT_RESOURCE_WARN_AFTER_MS as n, clearBucketRegionCache as nt, isRetryableTransientError as o, ConfigError as ot, red as p, NestedStackChildDirectDestroyError as pt, resolveStateBucketWithDefault as q, DeployEngine as r, resolveBucketRegion as rt, IMPLICIT_DELETE_DEPENDENCIES as s, DependencyError as st, DEFAULT_RESOURCE_TIMEOUT_MS as t, AssemblyReader as tt, cyan as u, LocalStartServiceError as ut, matchesCdkPath as v, StackHasActiveImportsError as vt, assertRegionMatch as w, normalizeAwsError as wt, ProviderRegistry as x, SynthesisError as xt, normalizeAwsTagsToCfn as y, StackTerminationProtectionError as yt, runDockerForeground as z };
13710
- //# sourceMappingURL=deploy-engine-ai3rix-L.js.map
13749
+ export { CFN_TEMPLATE_URL_LIMIT as $, DagBuilder as A, setLogger as At, getDockerCmd as B, CloudControlProvider as C, SynthesisError as Ct, IntrinsicFunctionResolver as D, withErrorHandling as Dt, isTerminationProtectionPropagationError as E, normalizeAwsError as Et, AssetPublisher as F, generateResourceName as Ft, getLegacyStateBucketName as G, runDockerStreaming as H, stringifyValue as I, generateResourceNameWithFallback as It, resolveSkipPrefix as J, resolveApp as K, WorkGraph as L, withSkipPrefix as Lt, LockManager as M, getLiveRenderer as Mt, S3StateBackend as N, PATTERN_B_NAME_PROPERTIES as Nt, applyRoleArnIfSet as O, ConsoleLogger as Ot, shouldRetainResource as P, PATTERN_B_RESOURCE_TYPES as Pt, CFN_TEMPLATE_BODY_LIMIT as Q, buildDockerImage as R, withStackName as Rt, findActionableSilentDrops as S, StateError as St, disableInstanceApiTermination as T, isCdkdError as Tt, Synthesizer as U, runDockerForeground as V, getDefaultStateBucketName as W, resolveStateBucketWithDefaultAndSource as X, resolveStateBucketWithDefault as Y, warnDeprecatedNoPrefixCliFlag as Z, CDK_PATH_TAG as _, ProvisioningError as _t, withRetry as a, resolveBucketRegion as at, resolveExplicitPhysicalId as b, StackHasActiveImportsError as bt, formatResourceLine as c, ConfigError as ct, gray as d, LocalMigrateError as dt, MIGRATE_TMP_PREFIX as et, green as f, LocalStartServiceError as ft, collectInlinePolicyNamesManagedBySiblings as g, PartialFailureError as gt, IAMRoleProvider as h, NestedStackChildDirectDestroyError as ht, withResourceDeadline as i, clearBucketRegionCache as it, TemplateParser as j, runStackBuffered as jt, DiffCalculator as k, getLogger as kt, bold as l, DependencyError as lt, yellow as m, MissingCdkCliError as mt, DEFAULT_RESOURCE_WARN_AFTER_MS as n, uploadCfnTemplate as nt, isRetryableTransientError as o, AssetError as ot, red as p, LockError as pt, resolveCaptureObservedState as q, DeployEngine as r, AssemblyReader as rt, IMPLICIT_DELETE_DEPENDENCIES as s, CdkdError as st, DEFAULT_RESOURCE_TIMEOUT_MS as t, findLargeInlineResources as tt, cyan as u, LocalInvokeBuildError as ut, matchesCdkPath as v, ResourceTimeoutError as vt, assertRegionMatch as w, formatError as wt, ProviderRegistry as x, StackTerminationProtectionError as xt, normalizeAwsTagsToCfn as y, ResourceUpdateNotSupportedError as yt, formatDockerLoginError as z };
13750
+ //# sourceMappingURL=deploy-engine-DMggQBl4.js.map