@intentius/chant-lexicon-aws 0.0.14 → 0.0.15

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.
@@ -326,6 +326,46 @@ describe("LexiconOutput serialization", () => {
326
326
  });
327
327
  });
328
328
 
329
+ // ── StackOutput Serialization ──────────────────────────
330
+
331
+ describe("stackOutput serialization", () => {
332
+ test("Id attribute uses Ref (not Fn::GetAtt)", () => {
333
+ const bucket = new MockBucket({ BucketName: "my-bucket" });
334
+ const idRef = new AttrRef(bucket, "Id");
335
+ idRef._setLogicalName("MyBucket");
336
+
337
+ const output = stackOutput(idRef);
338
+
339
+ const entities = new Map<string, Declarable>();
340
+ entities.set("MyBucket", bucket);
341
+ entities.set("MyBucketId", output as unknown as Declarable);
342
+
343
+ const result = awsSerializer.serialize(entities);
344
+ const template = JSON.parse(result as string);
345
+
346
+ expect(template.Outputs.MyBucketId.Value).toEqual({ Ref: "MyBucket" });
347
+ });
348
+
349
+ test("non-Id attribute uses Fn::GetAtt", () => {
350
+ const bucket = new MockBucket({ BucketName: "my-bucket" });
351
+ const arnRef = new AttrRef(bucket, "Arn");
352
+ arnRef._setLogicalName("MyBucket");
353
+
354
+ const output = stackOutput(arnRef);
355
+
356
+ const entities = new Map<string, Declarable>();
357
+ entities.set("MyBucket", bucket);
358
+ entities.set("MyBucketArn", output as unknown as Declarable);
359
+
360
+ const result = awsSerializer.serialize(entities);
361
+ const template = JSON.parse(result as string);
362
+
363
+ expect(template.Outputs.MyBucketArn.Value).toEqual({
364
+ "Fn::GetAtt": ["MyBucket", "Arn"],
365
+ });
366
+ });
367
+ });
368
+
329
369
  // ── Nested Stack Serialization ──────────────────────────
330
370
 
331
371
  function mockChildBuildResult(childTemplate: object): BuildResult {
package/src/serializer.ts CHANGED
@@ -282,8 +282,13 @@ function serializeToTemplate(
282
282
  const ref = stackOutput.sourceRef;
283
283
  const logicalName = ref.getLogicalName();
284
284
  if (logicalName) {
285
+ // Use Ref for primary identifier ("Id") since not all resources
286
+ // support Fn::GetAtt for their primary identifier (e.g. ACM Certificate).
287
+ // Ref always returns the primary identifier for any CF resource.
285
288
  const output: CFOutput = {
286
- Value: { "Fn::GetAtt": [logicalName, ref.attribute] },
289
+ Value: ref.attribute === "Id"
290
+ ? { Ref: logicalName }
291
+ : { "Fn::GetAtt": [logicalName, ref.attribute] },
287
292
  };
288
293
  if (stackOutput.description) {
289
294
  output.Description = stackOutput.description;