diff --git a/docs/services/cloudformation.md b/docs/services/cloudformation.md index 2340d7a379..ecc809ce52 100644 --- a/docs/services/cloudformation.md +++ b/docs/services/cloudformation.md @@ -233,7 +233,7 @@ before provisioning: - `AWS::SSM::Parameter::Value>` and `AWS::SSM::Parameter::Name` typed parameters are **not yet** resolved — they are passed through as their literal input. -The `AWS::SSM::Parameter` **resource** type exposes `Value`, `Type`, and `Name` attributes through +The `AWS::SSM::Parameter` **resource** type exposes `Value`, `Type`, `Name`, and `Arn` attributes through `Ref` / `Fn::GetAtt` so downstream resources can consume a parameter the same stack creates. ## AWS::Include (`Fn::Transform`) diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/SsmCfnProvisioner.java b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/SsmCfnProvisioner.java index 0105371259..f0910cbb71 100644 --- a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/SsmCfnProvisioner.java +++ b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/SsmCfnProvisioner.java @@ -1,6 +1,7 @@ package io.github.hectorvent.floci.services.cloudformation.provisioners; import com.fasterxml.jackson.databind.JsonNode; +import io.github.hectorvent.floci.core.common.AwsArnUtils; import io.github.hectorvent.floci.services.cloudformation.model.StackResource; import io.github.hectorvent.floci.services.ssm.SsmService; import jakarta.enterprise.context.ApplicationScoped; @@ -41,6 +42,13 @@ public class SsmCfnProvisioner implements CfnResourceProvisioner { r.getAttributes().put("Name", name); r.getAttributes().put("Type", type); r.getAttributes().put("Value", value); + r.getAttributes().put("Arn", parameterArn(name, ctx)); + } + + /** AWS's form is {@code parameter/} whether or not the name starts with a slash. */ + private static String parameterArn(String name, ProvisionContext ctx) { + String path = name.startsWith("/") ? name : "/" + name; + return AwsArnUtils.Arn.of("ssm", ctx.region(), ctx.accountId(), "parameter" + path).toString(); } @Override diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/LeafCfnProvisionerTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/LeafCfnProvisionerTest.java index 3d554cbff2..01b66821d5 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/LeafCfnProvisionerTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/LeafCfnProvisionerTest.java @@ -166,7 +166,20 @@ class LeafCfnProvisionerTest { verify(ssm).putParameter("/app/db", "secret", "String", null, true, REGION); assertEquals("/app/db", r.getPhysicalId()); - assertEquals(Map.of("Name", "/app/db", "Type", "String", "Value", "secret"), r.getAttributes()); + assertEquals(Map.of("Name", "/app/db", "Type", "String", "Value", "secret", + "Arn", "arn:aws:ssm:us-east-1:000000000000:parameter/app/db"), r.getAttributes()); + } + + @Test + void arnOfANameWithoutALeadingSlashStillHasTheParameterPrefix() { + // AWS ARNs are always arn:...:parameter/; a name without a leading slash gets the + // slash inserted, a name with one is not doubled. + StackResource r = resource("Param", "AWS::SSM::Parameter"); + provisioner.provision(r, props(""" + {"Name": "db-host", "Value": "localhost"} + """), ctx); + + assertEquals("arn:aws:ssm:us-east-1:000000000000:parameter/db-host", r.getAttributes().get("Arn")); } @Test