fix(cloudformation): register !Cidr and !GetAZs shorthand YAML tags (#1635)

The Fn::Cidr and Fn::GetAZs intrinsics were added in #1365, but their YAML shorthand tags (!Cidr, !GetAZs) were never registered in CloudFormationYamlParser. Templates using the shorthand fail to parse with "could not determine a constructor for the tag !Cidr", while the long form (Fn::Cidr / Fn::GetAZs) works. Register the two missing tags alongside the other intrinsic shorthands so both forms behave identically.
This commit is contained in:
武田隆志 authored and GitHub committed 2026-07-02 23:16:04 -05:00
1 parent 8b39ead1a4
commit 8366ac256a
2 files changed
+48

No files matched your search

@@ -0,0 +1,46 @@
package io.github.hectorvent.floci.services.cloudformation;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
class CloudFormationYamlParserTest {
private final ObjectMapper mapper = new ObjectMapper();
private JsonNode parse(String yaml) throws Exception {
return new CloudFormationYamlParser(mapper).parse(yaml);
}
@Test
void cidrShorthandExpandsToFnCidr() throws Exception {
JsonNode cidr = parse("Value: !Cidr [\"10.0.0.0/16\", 4, 8]").get("Value").get("Fn::Cidr");
assertTrue(cidr.isArray());
assertEquals("10.0.0.0/16", cidr.get(0).asText());
assertEquals(4, cidr.get(1).asInt());
assertEquals(8, cidr.get(2).asInt());
}
@Test
void getAzsShorthandExpandsToFnGetAZs() throws Exception {
assertEquals("", parse("Value: !GetAZs \"\"").get("Value").get("Fn::GetAZs").asText());
}
@Test
void cidrShorthandMatchesLongFormInNestedSelect() throws Exception {
JsonNode shorthand = parse("CidrBlock: !Select [1, !Cidr [!GetAtt Vpc.CidrBlock, 4, 8]]");
JsonNode longForm = parse("""
CidrBlock:
Fn::Select:
- 1
- Fn::Cidr:
- Fn::GetAtt: [Vpc, CidrBlock]
- 4
- 8
""");
assertEquals(longForm, shorthand);
}
}