@go-to-k/cdkd 0.23.2 → 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/README.md CHANGED
@@ -582,15 +582,21 @@ cdkd import MyStack \
582
582
  # CDK CLI compat: read overrides from a JSON file.
583
583
  cdkd import MyStack --resource-mapping mapping.json
584
584
  # mapping.json: { "MyBucket": "my-bucket-name", "MyFn": "my-function-name" }
585
+
586
+ # CDK CLI compat: inline JSON (handy for non-TTY CI scripts).
587
+ cdkd import MyStack --resource-mapping-inline '{"MyBucket":"my-bucket-name"}'
585
588
  ```
586
589
 
587
- When at least one `--resource` flag (or a `--resource-mapping` file) is
588
- supplied, **only the listed resources are imported**. Every other
589
- resource in the template is reported as `out of scope` and left out of
590
- state the next `cdkd deploy` will treat them as new and CREATE them.
591
- This matches the semantics of `cdk import --resource-mapping`. cdkd
592
- validates that every override key is a real logical ID in the
593
- template; a typo aborts the run rather than silently importing nothing.
590
+ When at least one `--resource` flag (or a `--resource-mapping` /
591
+ `--resource-mapping-inline` payload) is supplied, **only the listed
592
+ resources are imported**. Every other resource in the template is
593
+ reported as `out of scope` and left out of state the next `cdkd
594
+ deploy` will treat them as new and CREATE them. This matches the
595
+ semantics of `cdk import --resource-mapping` /
596
+ `--resource-mapping-inline`. cdkd validates that every override key is
597
+ a real logical ID in the template; a typo aborts the run rather than
598
+ silently importing nothing. `--resource-mapping` and
599
+ `--resource-mapping-inline` are mutually exclusive — pick one source.
594
600
 
595
601
  Use selective mode when you want to **adopt a few specific resources**
596
602
  out of a larger stack — for example, you have one S3 bucket that was
@@ -641,6 +647,50 @@ services, anything in Cloud Control API), use the explicit
641
647
  exactly this case. Resource types whose provider does not implement
642
648
  import are reported as `unsupported` and skipped.
643
649
 
650
+ ### `cdkd import` vs upstream `cdk import`
651
+
652
+ cdkd's `import` command mirrors the surface of upstream
653
+ [`cdk import`](https://docs.aws.amazon.com/cdk/v2/guide/ref-cli-cmd-import.html)
654
+ where it can, but the underlying mechanism is fundamentally different
655
+ and a handful of upstream-only flags are not implemented. Use this
656
+ table to predict behavior when migrating from `cdk import`.
657
+
658
+ | Topic | `cdk import` (upstream) | `cdkd import` |
659
+ | --- | --- | --- |
660
+ | Mechanism | CloudFormation `CreateChangeSet` with `ResourcesToImport` — atomic, all-or-nothing. | Per-resource SDK calls (e.g. `s3:HeadBucket`, `lambda:GetFunction`, IAM `ListRoleTags`). **Not atomic.** |
661
+ | Failure mode | Failed import rolls the changeset back; the stack is left unchanged. | Per-resource: `imported` / `skipped-not-found` / `skipped-no-impl` / `skipped-out-of-scope` / `failed` rows are summarized. State is written for whatever succeeded — but only after a confirmation prompt (or `--yes`), so a partial run is opt-in. To roll a partial import back, use `cdkd state orphan <stack>` (drops the state record only). |
662
+ | Selective mode (`--resource-mapping <file>`) | Supported. Listed resources are imported; unlisted resources cause the changeset to fail. | Supported. Listed resources are imported; unlisted resources are reported as `out of scope` and left out of state (next `cdkd deploy` will CREATE them). |
663
+ | Selective mode (`--resource <id>=<physical>` repeatable) | Not supported (upstream uses interactive prompts or a mapping file). | Supported as cdkd's CLI-friendly equivalent. |
664
+ | `--resource-mapping-inline '<json>'` | Supported (use in non-TTY environments). | **Not supported.** Use `--resource <id>=<physical>` (repeatable) or `--resource-mapping <file>` instead. |
665
+ | `--record-resource-mapping <file>` | Supported (writes the mapping the user typed at the prompt to a file for re-use). | **Not supported.** cdkd has no interactive prompt to record. |
666
+ | Interactive prompt for missing IDs | Default in TTY — prompts for every resource not covered by a mapping file. | **Not supported.** cdkd is non-interactive: missing logical IDs are looked up by `aws:cdk:path` tag in `auto` / `hybrid` modes, or skipped as `out of scope` in selective mode. The only prompt is the final "write state?" confirmation, which `--yes` skips. |
667
+ | Typo'd logical ID | Aborts with a clear error before any AWS calls. | Aborts with a clear error before any AWS calls — checked against the synthesized template. |
668
+ | Whole-stack tag-based import | **Not supported.** | **cdkd-specific.** With no flags, cdkd looks every resource up by its `aws:cdk:path` tag — the typical case for adopting a stack previously deployed by `cdk deploy`. |
669
+ | Hybrid mode (overrides + tag fallback) | **Not supported.** | **cdkd-specific.** `--auto` together with `--resource` lets listed resources use the explicit physical id while everything else still goes through tag lookup. |
670
+ | Nested stacks (`AWS::CloudFormation::Stack`) | Explicitly unsupported. | Also unsupported in practice — cdkd does not deploy nested CloudFormation stacks at all (no `AWS::CloudFormation::Stack` provider). The `Stack` resource itself would be reported as `unsupported`. CDK Stages (separate top-level stacks) are fine: pass the stack's display path or physical name as the positional argument. |
671
+ | Bootstrap requirement | Bootstrap v12+ (deploy role needs to read the encrypted staging bucket). | cdkd's own state bucket; no CDK bootstrap version requirement. |
672
+ | Resource-type coverage | Whatever [CloudFormation supports for import](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resource-import-supported-resources.html). | The set of cdkd providers that implement `import()` (see [CLAUDE.md](CLAUDE.md) for the current list). For any other CC-API-supported type, use `--resource <id>=<physical>` to drive the Cloud Control API fallback. The two lists overlap heavily but are not identical. |
673
+ | Confirmation prompt before writing state | n/a (CloudFormation operates atomically). | Yes — cdkd asks before writing the state file. Skip with `--yes`. |
674
+ | `--force` | "Continue even if the diff includes updates or deletions" — about diff strictness. | "Overwrite an existing state record" — about state safety. **Same flag name, different meaning.** |
675
+ | `--dry-run` | Implied by `--no-execute` (creates the changeset without executing). | Native: shows the import plan and exits without writing state. |
676
+
677
+ #### Practical implications when migrating from `cdk import`
678
+
679
+ - If you script around `--resource-mapping <file>`: behavior matches.
680
+ The file format (`{"LogicalId": "physical-id"}`) is the same.
681
+ - If you script around `--resource-mapping-inline`: rewrite as
682
+ repeated `--resource <id>=<physical>` flags, or write a temp file.
683
+ - If your workflow relies on the interactive prompt: rewrite as
684
+ `--resource-mapping <file>`. cdkd will not prompt.
685
+ - If you rely on atomic rollback: cdkd cannot offer that — its
686
+ per-resource model writes state only after the full pass completes
687
+ (and after confirmation), so a partial run is bounded, but if a
688
+ later resource fails after several earlier ones already returned
689
+ successfully and you confirm the write, those earlier ones are
690
+ in cdkd state. Use `cdkd state orphan <stack>` to back out.
691
+ - If you import nested stacks: neither tool supports this. Convert
692
+ to top-level CDK stacks first.
693
+
644
694
  ## State Management
645
695
 
646
696
  State is stored in S3. Keys are scoped by `(stackName, region)` so the same
package/dist/cli.js CHANGED
@@ -34070,7 +34070,11 @@ async function importCommand(stackArg, options) {
34070
34070
  `State already exists for stack '${stackInfo.stackName}' (${targetRegion}). Pass --force to overwrite. (cdkd state import rebuilds the resource map from AWS, so the existing state \u2014 including any drift you've manually edited \u2014 will be lost.)`
34071
34071
  );
34072
34072
  }
34073
- const overrides = parseResourceOverrides(options.resource, options.resourceMapping);
34073
+ const overrides = parseResourceOverrides(
34074
+ options.resource,
34075
+ options.resourceMapping,
34076
+ options.resourceMappingInline
34077
+ );
34074
34078
  if (overrides.size > 0) {
34075
34079
  logger.debug(`User-supplied physical IDs: ${[...overrides.keys()].join(", ")}`);
34076
34080
  }
@@ -34213,28 +34217,30 @@ async function importOne(task) {
34213
34217
  };
34214
34218
  }
34215
34219
  }
34216
- function parseResourceOverrides(flags, mappingFile) {
34220
+ function parseResourceOverrides(flags, mappingFile, mappingInline) {
34217
34221
  const map = /* @__PURE__ */ new Map();
34222
+ if (mappingFile && mappingInline) {
34223
+ throw new Error(
34224
+ "--resource-mapping and --resource-mapping-inline are mutually exclusive; pass only one."
34225
+ );
34226
+ }
34218
34227
  if (mappingFile) {
34219
- let parsed;
34228
+ let raw;
34220
34229
  try {
34221
- parsed = JSON.parse(readFileSync5(mappingFile, "utf-8"));
34230
+ raw = readFileSync5(mappingFile, "utf-8");
34222
34231
  } catch (err) {
34223
34232
  throw new Error(
34224
34233
  `Failed to read --resource-mapping file '${mappingFile}': ` + (err instanceof Error ? err.message : String(err))
34225
34234
  );
34226
34235
  }
34227
- if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
34228
- throw new Error(
34229
- `--resource-mapping file '${mappingFile}' must be a JSON object {logicalId: physicalId}`
34230
- );
34236
+ const parsed = parseMappingJson(raw, `--resource-mapping file '${mappingFile}'`);
34237
+ for (const [key, value] of Object.entries(parsed)) {
34238
+ map.set(key, value);
34231
34239
  }
34240
+ }
34241
+ if (mappingInline) {
34242
+ const parsed = parseMappingJson(mappingInline, "--resource-mapping-inline");
34232
34243
  for (const [key, value] of Object.entries(parsed)) {
34233
- if (typeof value !== "string") {
34234
- throw new Error(
34235
- `--resource-mapping: value for '${key}' must be a string, got ${typeof value}`
34236
- );
34237
- }
34238
34244
  map.set(key, value);
34239
34245
  }
34240
34246
  }
@@ -34247,6 +34253,27 @@ function parseResourceOverrides(flags, mappingFile) {
34247
34253
  }
34248
34254
  return map;
34249
34255
  }
34256
+ function parseMappingJson(raw, source) {
34257
+ let parsed;
34258
+ try {
34259
+ parsed = JSON.parse(raw);
34260
+ } catch (err) {
34261
+ throw new Error(
34262
+ `Failed to parse ${source} as JSON: ` + (err instanceof Error ? err.message : String(err))
34263
+ );
34264
+ }
34265
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
34266
+ throw new Error(`${source} must be a JSON object {logicalId: physicalId}`);
34267
+ }
34268
+ const out = {};
34269
+ for (const [key, value] of Object.entries(parsed)) {
34270
+ if (typeof value !== "string") {
34271
+ throw new Error(`${source}: value for '${key}' must be a string, got ${typeof value}`);
34272
+ }
34273
+ out[key] = value;
34274
+ }
34275
+ return out;
34276
+ }
34250
34277
  function readCdkPath(resource) {
34251
34278
  const meta = resource.Metadata;
34252
34279
  if (!meta)
@@ -34347,7 +34374,10 @@ function createImportCommand() {
34347
34374
  []
34348
34375
  ).option(
34349
34376
  "--resource-mapping <file>",
34350
- "Path to a JSON file of {logicalId: physicalId} overrides (CDK CLI `cdk import --resource-mapping` compatible). Implies selective mode unless --auto is set."
34377
+ "Path to a JSON file of {logicalId: physicalId} overrides (CDK CLI `cdk import --resource-mapping` compatible). Implies selective mode unless --auto is set. Mutually exclusive with --resource-mapping-inline."
34378
+ ).option(
34379
+ "--resource-mapping-inline <json>",
34380
+ "Inline JSON object of {logicalId: physicalId} overrides (CDK CLI `cdk import --resource-mapping-inline` compatible). Same shape as --resource-mapping but supplied as a string \u2014 useful for non-TTY CI scripts that do not want a separate file. Implies selective mode unless --auto is set. Mutually exclusive with --resource-mapping."
34351
34381
  ).option(
34352
34382
  "--auto",
34353
34383
  "Hybrid mode: when explicit overrides are supplied, ALSO tag-import every other resource in the template. Without this flag, --resource / --resource-mapping behave as a whitelist (CDK CLI parity).",
@@ -34393,7 +34423,7 @@ function reorderArgs(argv) {
34393
34423
  }
34394
34424
  async function main() {
34395
34425
  const program = new Command13();
34396
- program.name("cdkd").description("CDK Direct - Deploy AWS CDK apps directly via SDK/Cloud Control API").version("0.23.2");
34426
+ program.name("cdkd").description("CDK Direct - Deploy AWS CDK apps directly via SDK/Cloud Control API").version("0.24.0");
34397
34427
  program.addCommand(createBootstrapCommand());
34398
34428
  program.addCommand(createSynthCommand());
34399
34429
  program.addCommand(createListCommand());