@go-to-k/cdkd 0.8.0 → 0.9.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.
Binary file
package/dist/index.js CHANGED
@@ -5652,6 +5652,29 @@ var JsonPatchGenerator = class {
5652
5652
  }
5653
5653
  };
5654
5654
 
5655
+ // src/provisioning/region-check.ts
5656
+ function assertRegionMatch(clientRegion, expectedRegion, resourceType, logicalId, physicalId) {
5657
+ if (!expectedRegion) {
5658
+ return;
5659
+ }
5660
+ if (!clientRegion) {
5661
+ throw new ProvisioningError(
5662
+ `Refusing to treat NotFound as idempotent delete success for ${logicalId} (${resourceType}): AWS client region is unknown but stack state expects ${expectedRegion}. The resource may exist in ${expectedRegion} and would be silently removed from state if this NotFound were trusted.`,
5663
+ resourceType,
5664
+ logicalId,
5665
+ physicalId
5666
+ );
5667
+ }
5668
+ if (clientRegion !== expectedRegion) {
5669
+ throw new ProvisioningError(
5670
+ `Refusing to treat NotFound as idempotent delete success for ${logicalId} (${resourceType}): AWS client region ${clientRegion} does not match stack state region ${expectedRegion}. The resource likely still exists in ${expectedRegion}; rerun the destroy with the correct region (e.g. --region ${expectedRegion}).`,
5671
+ resourceType,
5672
+ logicalId,
5673
+ physicalId
5674
+ );
5675
+ }
5676
+ }
5677
+
5655
5678
  // src/provisioning/cloud-control-provider.ts
5656
5679
  var JSON_STRING_PROPERTIES = {
5657
5680
  "AWS::Events::Rule": /* @__PURE__ */ new Set(["EventPattern"])
@@ -5827,7 +5850,7 @@ var CloudControlProvider = class {
5827
5850
  /**
5828
5851
  * Delete a resource using Cloud Control API
5829
5852
  */
5830
- async delete(logicalId, physicalId, resourceType, _properties) {
5853
+ async delete(logicalId, physicalId, resourceType, _properties, context) {
5831
5854
  this.logger.debug(
5832
5855
  `Deleting resource ${logicalId} (${resourceType}), physical ID: ${physicalId}`
5833
5856
  );
@@ -5854,6 +5877,14 @@ var CloudControlProvider = class {
5854
5877
  } catch (error) {
5855
5878
  const err = error;
5856
5879
  if (err.name === "ResourceNotFoundException" || err.message?.includes("does not exist") || err.message?.includes("not found") || err.message?.includes("NotFound")) {
5880
+ const clientRegion = await this.cloudControlClient.config.region();
5881
+ assertRegionMatch(
5882
+ clientRegion,
5883
+ context?.expectedRegion,
5884
+ resourceType,
5885
+ logicalId,
5886
+ physicalId
5887
+ );
5857
5888
  this.logger.debug(`Resource ${logicalId} already deleted (not found), treating as success`);
5858
5889
  return;
5859
5890
  }
@@ -6418,7 +6449,7 @@ var CustomResourceProvider = class _CustomResourceProvider {
6418
6449
  /**
6419
6450
  * Delete a custom resource by invoking its Lambda handler
6420
6451
  */
6421
- async delete(logicalId, physicalId, resourceType, properties) {
6452
+ async delete(logicalId, physicalId, resourceType, properties, _context) {
6422
6453
  this.logger.debug(`Deleting custom resource ${logicalId}: ${physicalId} (${resourceType})`);
6423
6454
  if (!properties) {
6424
6455
  this.logger.warn(
@@ -7240,13 +7271,21 @@ var IAMRoleProvider = class {
7240
7271
  * 3. Remove role from all instance profiles
7241
7272
  * 4. Delete the role itself
7242
7273
  */
7243
- async delete(logicalId, physicalId, resourceType, _properties) {
7274
+ async delete(logicalId, physicalId, resourceType, _properties, context) {
7244
7275
  this.logger.debug(`Deleting IAM role ${logicalId}: ${physicalId}`);
7245
7276
  try {
7246
7277
  try {
7247
7278
  await this.iamClient.send(new GetRoleCommand({ RoleName: physicalId }));
7248
7279
  } catch (error) {
7249
7280
  if (error instanceof NoSuchEntityException) {
7281
+ const clientRegion = await this.iamClient.config.region();
7282
+ assertRegionMatch(
7283
+ clientRegion,
7284
+ context?.expectedRegion,
7285
+ resourceType,
7286
+ logicalId,
7287
+ physicalId
7288
+ );
7250
7289
  this.logger.debug(`Role ${physicalId} does not exist, skipping deletion`);
7251
7290
  return;
7252
7291
  }
@@ -8273,7 +8312,9 @@ var DeployEngine = class {
8273
8312
  ` Rollback: Deleting created resource ${op.logicalId} (${op.resourceType})`
8274
8313
  );
8275
8314
  const provider = this.providerRegistry.getProvider(op.resourceType);
8276
- await provider.delete(op.logicalId, op.physicalId, op.resourceType, op.properties);
8315
+ await provider.delete(op.logicalId, op.physicalId, op.resourceType, op.properties, {
8316
+ expectedRegion: this.stackRegion
8317
+ });
8277
8318
  delete stateResources[op.logicalId];
8278
8319
  this.logger.info(` Rollback: ${op.logicalId} deleted successfully`);
8279
8320
  break;
@@ -8415,7 +8456,8 @@ var DeployEngine = class {
8415
8456
  logicalId,
8416
8457
  currentResource.physicalId,
8417
8458
  resourceType,
8418
- currentResource.properties
8459
+ currentResource.properties,
8460
+ { expectedRegion: this.stackRegion }
8419
8461
  );
8420
8462
  this.logger.info(` \u2713 Old resource deleted`);
8421
8463
  } catch (deleteError) {
@@ -8464,7 +8506,8 @@ var DeployEngine = class {
8464
8506
  logicalId,
8465
8507
  currentResource.physicalId,
8466
8508
  resourceType,
8467
- currentProps
8509
+ currentProps,
8510
+ { expectedRegion: this.stackRegion }
8468
8511
  );
8469
8512
  } catch (deleteError) {
8470
8513
  const deleteMsg = deleteError instanceof Error ? deleteError.message : String(deleteError);
@@ -8535,7 +8578,8 @@ var DeployEngine = class {
8535
8578
  logicalId,
8536
8579
  currentResource.physicalId,
8537
8580
  resourceType,
8538
- currentResource.properties
8581
+ currentResource.properties,
8582
+ { expectedRegion: this.stackRegion }
8539
8583
  ),
8540
8584
  logicalId,
8541
8585
  3,