@go-to-k/cdkd 0.87.0 → 0.88.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
@@ -79512,19 +79512,35 @@ async function exportCommand(stackArg, options) {
79512
79512
  return;
79513
79513
  }
79514
79514
  }
79515
+ const userParameters = parseParameterOverrides(options.parameter);
79516
+ const { parameters: cfnParameters, missing } = resolveTemplateParameters(
79517
+ template,
79518
+ userParameters
79519
+ );
79520
+ if (missing.length > 0) {
79521
+ throw new Error(
79522
+ `Template requires parameter(s) without defaults: ${missing.join(", ")}. Pass each one as --parameter Key=Value (or set a Default in the CDK code).`
79523
+ );
79524
+ }
79515
79525
  const phase1Template = filterTemplateForImport(template, phase1Imports);
79516
79526
  await executeImportChangeSet(
79517
79527
  awsClients.cloudFormation,
79518
79528
  cfnStackName,
79519
79529
  phase1Template,
79520
- phase1Imports
79530
+ phase1Imports,
79531
+ cfnParameters
79521
79532
  );
79522
79533
  logger.info(
79523
79534
  `\u2713 Phase 1: CloudFormation stack '${cfnStackName}' created via IMPORT. ${phase1Imports.length} resource(s) imported.`
79524
79535
  );
79525
79536
  if (phase2Creates.length > 0) {
79526
79537
  try {
79527
- await executeUpdateChangeSet(awsClients.cloudFormation, cfnStackName, template);
79538
+ await executeUpdateChangeSet(
79539
+ awsClients.cloudFormation,
79540
+ cfnStackName,
79541
+ template,
79542
+ cfnParameters
79543
+ );
79528
79544
  logger.info(`\u2713 Phase 2: ${phase2Creates.length} non-importable resource(s) CREATEd.`);
79529
79545
  } catch (err) {
79530
79546
  const msg = err instanceof Error ? err.message : String(err);
@@ -79762,6 +79778,64 @@ async function fetchPrimaryIdentifier(resourceType, cfnClient) {
79762
79778
  `primary identifier unknown (DescribeType returned no usable schema and no fallback is registered). Add ${resourceType} to PRIMARY_IDENTIFIER_FALLBACK in export.ts, or open an issue.`
79763
79779
  );
79764
79780
  }
79781
+ function parseParameterOverrides(tokens) {
79782
+ const map = {};
79783
+ if (!tokens)
79784
+ return map;
79785
+ for (const t of tokens) {
79786
+ const eq = t.indexOf("=");
79787
+ if (eq < 1) {
79788
+ throw new Error(
79789
+ `Invalid --parameter '${t}': expected 'Key=Value' (e.g. --parameter Env=prod)`
79790
+ );
79791
+ }
79792
+ const key = t.slice(0, eq).trim();
79793
+ const value = t.slice(eq + 1);
79794
+ if (!key) {
79795
+ throw new Error(`Invalid --parameter '${t}': key is empty`);
79796
+ }
79797
+ map[key] = value;
79798
+ }
79799
+ return map;
79800
+ }
79801
+ function resolveTemplateParameters(template, userOverrides) {
79802
+ const tplParams = template["Parameters"];
79803
+ if (!tplParams || typeof tplParams !== "object" || Array.isArray(tplParams)) {
79804
+ const stray = Object.keys(userOverrides);
79805
+ if (stray.length > 0) {
79806
+ throw new Error(
79807
+ `--parameter override(s) supplied (${stray.join(", ")}) but template has no Parameters section.`
79808
+ );
79809
+ }
79810
+ return { parameters: [], missing: [] };
79811
+ }
79812
+ const parameters = [];
79813
+ const missing = [];
79814
+ const known = /* @__PURE__ */ new Set();
79815
+ for (const [name, raw] of Object.entries(tplParams)) {
79816
+ known.add(name);
79817
+ const def = raw ?? {};
79818
+ const override = userOverrides[name];
79819
+ if (override !== void 0) {
79820
+ parameters.push({ ParameterKey: name, ParameterValue: override });
79821
+ continue;
79822
+ }
79823
+ if ("Default" in def) {
79824
+ const value = typeof def.Default === "string" ? def.Default : String(def.Default);
79825
+ parameters.push({ ParameterKey: name, ParameterValue: value });
79826
+ continue;
79827
+ }
79828
+ missing.push(name);
79829
+ }
79830
+ for (const name of Object.keys(userOverrides)) {
79831
+ if (!known.has(name)) {
79832
+ throw new Error(
79833
+ `--parameter override '${name}' does not match any parameter in the synthesized template (template declares: ${[...known].join(", ") || "(none)"})`
79834
+ );
79835
+ }
79836
+ }
79837
+ return { parameters, missing };
79838
+ }
79765
79839
  function filterTemplateForImport(template, plan) {
79766
79840
  const allow = new Set(plan.map((p) => p.logicalId));
79767
79841
  const original = template["Resources"];
@@ -79821,7 +79895,7 @@ function printPlan(plan, cfnStackName) {
79821
79895
  }
79822
79896
  logger.info("");
79823
79897
  }
79824
- async function executeImportChangeSet(cfnClient, stackName, template, plan) {
79898
+ async function executeImportChangeSet(cfnClient, stackName, template, plan, parameters) {
79825
79899
  const logger = getLogger();
79826
79900
  const changeSetName = `cdkd-migrate-${Date.now()}`;
79827
79901
  const templateBody = JSON.stringify(template, null, 2);
@@ -79846,6 +79920,7 @@ async function executeImportChangeSet(cfnClient, stackName, template, plan) {
79846
79920
  ChangeSetType: "IMPORT",
79847
79921
  TemplateBody: templateBody,
79848
79922
  ResourcesToImport: resourcesToImport,
79923
+ ...parameters.length > 0 && { Parameters: parameters },
79849
79924
  // CDK templates routinely require CAPABILITY_IAM /
79850
79925
  // CAPABILITY_NAMED_IAM. Forward both so the user does not have to
79851
79926
  // re-discover and re-pass them.
@@ -79892,7 +79967,7 @@ async function executeImportChangeSet(cfnClient, stackName, template, plan) {
79892
79967
  throw err;
79893
79968
  }
79894
79969
  }
79895
- async function executeUpdateChangeSet(cfnClient, stackName, template) {
79970
+ async function executeUpdateChangeSet(cfnClient, stackName, template, parameters) {
79896
79971
  const logger = getLogger();
79897
79972
  const changeSetName = `cdkd-phase2-${Date.now()}`;
79898
79973
  const templateBody = JSON.stringify(template, null, 2);
@@ -79911,6 +79986,7 @@ async function executeUpdateChangeSet(cfnClient, stackName, template) {
79911
79986
  ChangeSetName: changeSetName,
79912
79987
  ChangeSetType: "UPDATE",
79913
79988
  TemplateBody: templateBody,
79989
+ ...parameters.length > 0 && { Parameters: parameters },
79914
79990
  Capabilities: ["CAPABILITY_IAM", "CAPABILITY_NAMED_IAM", "CAPABILITY_AUTO_EXPAND"]
79915
79991
  })
79916
79992
  );
@@ -80027,6 +80103,9 @@ function createExportCommand() {
80027
80103
  "--include-non-importable",
80028
80104
  "Run a 2-phase migration when the stack contains non-importable resources (Custom::*). Phase 1 imports the importable resources; phase 2 CFn-CREATEs the non-importable ones, which re-invokes each Custom Resource's onCreate handler. Make sure onCreate is idempotent before enabling.",
80029
80105
  false
80106
+ ).option(
80107
+ "--parameter <key=value...>",
80108
+ "CFn template Parameter override, repeatable. Required when the synthesized template has Parameters without Default values; otherwise overrides the template's default value. Format: --parameter Key=Value."
80030
80109
  ).action(withErrorHandling(exportCommand));
80031
80110
  [...commonOptions, ...appOptions, ...stateOptions, ...contextOptions].forEach(
80032
80111
  (opt) => cmd.addOption(opt)
@@ -80065,7 +80144,7 @@ function reorderArgs(argv) {
80065
80144
  }
80066
80145
  async function main() {
80067
80146
  const program = new Command18();
80068
- program.name("cdkd").description("CDK Direct - Deploy AWS CDK apps directly via SDK/Cloud Control API").version("0.87.0");
80147
+ program.name("cdkd").description("CDK Direct - Deploy AWS CDK apps directly via SDK/Cloud Control API").version("0.88.0");
80069
80148
  program.addCommand(createBootstrapCommand());
80070
80149
  program.addCommand(createSynthCommand());
80071
80150
  program.addCommand(createListCommand());