@go-to-k/cdkd 0.15.0 → 0.16.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
@@ -1016,7 +1016,7 @@ async function resolveStateBucketWithDefaultAndSource(cliBucket, region) {
1016
1016
  logger.warn(
1017
1017
  `Using legacy state bucket name '${legacyName}'. The default has changed to '${newName}'. To migrate, run:
1018
1018
 
1019
- cdkd state migrate-bucket --region ${region}
1019
+ cdkd state migrate --region ${region}
1020
1020
 
1021
1021
  (add --remove-legacy to delete the legacy bucket after a successful copy; legacy support will be dropped in a future release.)`
1022
1022
  );
@@ -7010,6 +7010,60 @@ Error: ${err.message || "Unknown error"}`,
7010
7010
  }
7011
7011
  return resourceType.startsWith("AWS::");
7012
7012
  }
7013
+ /**
7014
+ * Adopt an already-deployed resource into cdkd state via Cloud Control API.
7015
+ *
7016
+ * Strategy: explicit-override only.
7017
+ * - With `knownPhysicalId` (from `--resource <id>=<physicalId>` or
7018
+ * `--resource-mapping`): call `GetResource(TypeName, Identifier)`,
7019
+ * parse `ResourceModel` (returned as a JSON string by CC API), and
7020
+ * return its keys as `attributes`.
7021
+ * - Without `knownPhysicalId`: return `null`. CC API has no efficient
7022
+ * `aws:cdk:path`-tag lookup — `ListResources` returns identifiers
7023
+ * only, so tag lookup would require one `GetResource` per resource
7024
+ * in the account, plus per-service tag-API calls (which CC API
7025
+ * doesn't expose uniformly). Cost vs. value isn't worth it; users
7026
+ * who need adoption for CC-API-only resource types should pass
7027
+ * `--resource <id>=<physicalId>` for those resources.
7028
+ *
7029
+ * SDK providers (S3, Lambda, IAM Role, etc.) implement their own
7030
+ * `import` with tag-based auto-lookup; this fallback only kicks in for
7031
+ * resource types that don't have a dedicated SDK provider.
7032
+ */
7033
+ async import(input) {
7034
+ if (!input.knownPhysicalId) {
7035
+ return null;
7036
+ }
7037
+ try {
7038
+ const resp = await this.cloudControlClient.send(
7039
+ new GetResourceCommand2({
7040
+ TypeName: input.resourceType,
7041
+ Identifier: input.knownPhysicalId
7042
+ })
7043
+ );
7044
+ let attributes = {};
7045
+ const raw = resp.ResourceDescription?.Properties;
7046
+ if (typeof raw === "string" && raw.length > 0) {
7047
+ try {
7048
+ const parsed = JSON.parse(raw);
7049
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
7050
+ attributes = parsed;
7051
+ }
7052
+ } catch (parseErr) {
7053
+ this.logger.debug(
7054
+ `Failed to parse CC API ResourceModel for ${input.resourceType}/${input.knownPhysicalId}: ${parseErr instanceof Error ? parseErr.message : String(parseErr)}`
7055
+ );
7056
+ }
7057
+ }
7058
+ return { physicalId: input.knownPhysicalId, attributes };
7059
+ } catch (error) {
7060
+ const err = error;
7061
+ if (err.name === "ResourceNotFoundException") {
7062
+ return null;
7063
+ }
7064
+ throw error;
7065
+ }
7066
+ }
7013
7067
  };
7014
7068
 
7015
7069
  // src/provisioning/providers/custom-resource-provider.ts
@@ -30222,7 +30276,7 @@ import {
30222
30276
  } from "@aws-sdk/client-s3";
30223
30277
  init_aws_clients();
30224
30278
 
30225
- // src/cli/commands/state-migrate-bucket.ts
30279
+ // src/cli/commands/state-migrate.ts
30226
30280
  import * as readline2 from "node:readline/promises";
30227
30281
  import { Command as Command9 } from "commander";
30228
30282
  import {
@@ -30240,7 +30294,7 @@ import {
30240
30294
  } from "@aws-sdk/client-s3";
30241
30295
  import { GetCallerIdentityCommand as GetCallerIdentityCommand8 } from "@aws-sdk/client-sts";
30242
30296
  init_aws_clients();
30243
- async function stateMigrateBucketCommand(options) {
30297
+ async function stateMigrateCommand(options) {
30244
30298
  const logger = getLogger();
30245
30299
  if (options.verbose)
30246
30300
  logger.setLevel("debug");
@@ -30506,8 +30560,8 @@ async function confirmPrompt(prompt) {
30506
30560
  rl.close();
30507
30561
  }
30508
30562
  }
30509
- function createStateMigrateBucketCommand() {
30510
- const cmd = new Command9("migrate-bucket").description(
30563
+ function createStateMigrateCommand() {
30564
+ const cmd = new Command9("migrate").description(
30511
30565
  "Migrate state from the legacy region-suffixed bucket (cdkd-state-{account}-{region}) to the new region-free default (cdkd-state-{account}). Source bucket is kept by default; pass --remove-legacy to delete it after a successful migration."
30512
30566
  ).option(
30513
30567
  "--region <region>",
@@ -30522,7 +30576,7 @@ function createStateMigrateBucketCommand() {
30522
30576
  "--remove-legacy",
30523
30577
  "Delete the source bucket after successful migration. Default: keep it.",
30524
30578
  false
30525
- ).action(withErrorHandling(stateMigrateBucketCommand));
30579
+ ).action(withErrorHandling(stateMigrateCommand));
30526
30580
  commonOptions.forEach((o) => cmd.addOption(o));
30527
30581
  return cmd;
30528
30582
  }
@@ -31096,7 +31150,7 @@ function formatBucketSource(source) {
31096
31150
  case "default":
31097
31151
  return "default (account ID from STS)";
31098
31152
  case "default-legacy":
31099
- return "default (legacy region-suffixed name; cdkd state migrate-bucket recommended)";
31153
+ return "default (legacy region-suffixed name; cdkd state migrate recommended)";
31100
31154
  }
31101
31155
  }
31102
31156
  async function detectBucketRegion(awsClients, bucket) {
@@ -31211,7 +31265,7 @@ function createStateCommand() {
31211
31265
  cmd.addCommand(createStateShowCommand());
31212
31266
  cmd.addCommand(createStateRmCommand());
31213
31267
  cmd.addCommand(createStateDestroyCommand());
31214
- cmd.addCommand(createStateMigrateBucketCommand());
31268
+ cmd.addCommand(createStateMigrateCommand());
31215
31269
  return cmd;
31216
31270
  }
31217
31271
 
@@ -31576,7 +31630,7 @@ function reorderArgs(argv) {
31576
31630
  }
31577
31631
  async function main() {
31578
31632
  const program = new Command12();
31579
- program.name("cdkd").description("CDK Direct - Deploy AWS CDK apps directly via SDK/Cloud Control API").version("0.15.0");
31633
+ program.name("cdkd").description("CDK Direct - Deploy AWS CDK apps directly via SDK/Cloud Control API").version("0.16.0");
31580
31634
  program.addCommand(createBootstrapCommand());
31581
31635
  program.addCommand(createSynthCommand());
31582
31636
  program.addCommand(createListCommand());