@go-to-k/cdkd 0.15.0 → 0.16.1

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
@@ -6399,6 +6399,60 @@ Error: ${err.message || "Unknown error"}`,
6399
6399
  }
6400
6400
  return resourceType.startsWith("AWS::");
6401
6401
  }
6402
+ /**
6403
+ * Adopt an already-deployed resource into cdkd state via Cloud Control API.
6404
+ *
6405
+ * Strategy: explicit-override only.
6406
+ * - With `knownPhysicalId` (from `--resource <id>=<physicalId>` or
6407
+ * `--resource-mapping`): call `GetResource(TypeName, Identifier)`,
6408
+ * parse `ResourceModel` (returned as a JSON string by CC API), and
6409
+ * return its keys as `attributes`.
6410
+ * - Without `knownPhysicalId`: return `null`. CC API has no efficient
6411
+ * `aws:cdk:path`-tag lookup — `ListResources` returns identifiers
6412
+ * only, so tag lookup would require one `GetResource` per resource
6413
+ * in the account, plus per-service tag-API calls (which CC API
6414
+ * doesn't expose uniformly). Cost vs. value isn't worth it; users
6415
+ * who need adoption for CC-API-only resource types should pass
6416
+ * `--resource <id>=<physicalId>` for those resources.
6417
+ *
6418
+ * SDK providers (S3, Lambda, IAM Role, etc.) implement their own
6419
+ * `import` with tag-based auto-lookup; this fallback only kicks in for
6420
+ * resource types that don't have a dedicated SDK provider.
6421
+ */
6422
+ async import(input) {
6423
+ if (!input.knownPhysicalId) {
6424
+ return null;
6425
+ }
6426
+ try {
6427
+ const resp = await this.cloudControlClient.send(
6428
+ new GetResourceCommand2({
6429
+ TypeName: input.resourceType,
6430
+ Identifier: input.knownPhysicalId
6431
+ })
6432
+ );
6433
+ let attributes = {};
6434
+ const raw = resp.ResourceDescription?.Properties;
6435
+ if (typeof raw === "string" && raw.length > 0) {
6436
+ try {
6437
+ const parsed = JSON.parse(raw);
6438
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
6439
+ attributes = parsed;
6440
+ }
6441
+ } catch (parseErr) {
6442
+ this.logger.debug(
6443
+ `Failed to parse CC API ResourceModel for ${input.resourceType}/${input.knownPhysicalId}: ${parseErr instanceof Error ? parseErr.message : String(parseErr)}`
6444
+ );
6445
+ }
6446
+ }
6447
+ return { physicalId: input.knownPhysicalId, attributes };
6448
+ } catch (error) {
6449
+ const err = error;
6450
+ if (err.name === "ResourceNotFoundException") {
6451
+ return null;
6452
+ }
6453
+ throw error;
6454
+ }
6455
+ }
6402
6456
  };
6403
6457
 
6404
6458
  // src/provisioning/providers/custom-resource-provider.ts