@znemz/cfn-include 2.1.10 → 2.1.11

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
@@ -1201,6 +1201,28 @@ If an AWS pseudo-parameter is not set via environment variables, it falls back t
1201
1201
  **Error handling:**
1202
1202
  If a reference cannot be resolved, `Fn::RefNow` will throw an error. Ensure all referenced parameters and variables are available via inject, scope, or environment variables.
1203
1203
 
1204
+ **CLI Options for Fn::RefNow:**
1205
+
1206
+ The `cfn-include` command provides CLI options to control how unresolved references are handled:
1207
+
1208
+ - `--ref-now-ignore-missing`: Do not fail if a `Fn::RefNow` reference cannot be resolved. Instead, the reference will be returned in AWS CloudFormation's standard `Ref` syntax (e.g., `{ Ref: 'UnresolvedRef' }`), allowing CloudFormation to resolve it at stack creation time.
1209
+ - `--ref-now-ignores <names>`: Comma-separated list of reference names to ignore if not found. These references will be returned in `Ref` syntax instead of throwing an error.
1210
+
1211
+ **Example usage:**
1212
+
1213
+ ```bash
1214
+ # Ignore all unresolved references
1215
+ cfn-include template.yaml --ref-now-ignore-missing
1216
+
1217
+ # Ignore specific reference names
1218
+ cfn-include template.yaml --ref-now-ignores "OptionalRef1,OptionalRef2"
1219
+
1220
+ # Combine both options
1221
+ cfn-include template.yaml --ref-now-ignore-missing --ref-now-ignores "SpecificRef"
1222
+ ```
1223
+
1224
+ This is useful for templates that reference CloudFormation parameters or other resources that may not be available at template processing time but will be available at stack creation time.
1225
+
1204
1226
  ## Fn::ApplyTags
1205
1227
 
1206
1228
  See [ApplyTags test file](t/tests/applyTags.yml).
package/bin/cli.js CHANGED
@@ -88,6 +88,14 @@ const { env } = process;
88
88
 
89
89
  desc: `console log out include options in recurse step`,
90
90
  },
91
+ 'ref-now-ignore-missing': {
92
+ boolean: true,
93
+ desc: 'do not fail if Fn::RefNow reference cannot be resolved',
94
+ },
95
+ 'ref-now-ignores': {
96
+ string: true,
97
+ desc: 'comma-separated list of reference names to ignore if not found',
98
+ },
91
99
  version: {
92
100
  boolean: true,
93
101
  desc: 'print version and exit',
@@ -102,6 +110,9 @@ const { env } = process;
102
110
  // make enable an array
103
111
  opts.enable = opts.enable.split(',');
104
112
 
113
+ // Parse ref-now-ignores into an array
114
+ const refNowIgnores = opts['ref-now-ignores'] ? opts['ref-now-ignores'].split(',').map(s => s.trim()) : [];
115
+
105
116
  let promise;
106
117
  if (opts.path) {
107
118
  let location;
@@ -115,6 +126,8 @@ if (opts.path) {
115
126
  doEval: opts.enable.includes('eval'),
116
127
  inject: opts.inject,
117
128
  doLog: opts.doLog,
129
+ refNowIgnoreMissing: opts['ref-now-ignore-missing'],
130
+ refNowIgnores: refNowIgnores,
118
131
  });
119
132
  } else {
120
133
  promise = new Promise((resolve, reject) => {
@@ -142,6 +155,8 @@ if (opts.path) {
142
155
  doEval: opts.enable.includes('eval'),
143
156
  inject: opts.inject,
144
157
  doLog: opts.doLog,
158
+ refNowIgnoreMissing: opts['ref-now-ignore-missing'],
159
+ refNowIgnores: refNowIgnores,
145
160
  }).catch((err) => console.error(err));
146
161
  });
147
162
  }
package/index.js CHANGED
@@ -484,6 +484,11 @@ async function recurse({ base, scope, cft, ...opts }) {
484
484
  return recurse({ base, scope, cft: cft['Fn::RefNow'], ...opts }).then((logicalName) => {
485
485
  let refName = logicalName;
486
486
 
487
+ // Check if this ref name is in the ignores list
488
+ if (opts.refNowIgnores && opts.refNowIgnores.includes(refName)) {
489
+ return { Ref: refName };
490
+ }
491
+
487
492
  // Merge AWS pseudo-parameters with inject and scope variables
488
493
  const allRefs = {
489
494
  ...getAwsPseudoParameters(),
@@ -497,7 +502,12 @@ async function recurse({ base, scope, cft, ...opts }) {
497
502
  return allRefs[refName];
498
503
  }
499
504
 
500
- // If not found, throw an error
505
+ // If not found and refNowIgnoreMissing is true, return Ref syntax; otherwise throw error
506
+ if (opts.refNowIgnoreMissing) {
507
+ return { Ref: refName };
508
+ }
509
+
510
+ // Default behavior: throw an error (backward compatible)
501
511
  throw new Error(`Unable to resolve Ref for logical name: ${refName}`);
502
512
  });
503
513
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@znemz/cfn-include",
3
- "version": "2.1.10",
3
+ "version": "2.1.11",
4
4
  "description": "Preprocessor for CloudFormation templates with support for loops and flexible include statements",
5
5
  "keywords": [
6
6
  "aws",