mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(cloudformation): preserve unquoted YAML dates as text (#8120)
This commit is contained in:
1 parent
c0a087a597
commit
f3b61cc368
3 files changed
+80
No files matched your search
@@ -67,6 +67,8 @@ public class CloudFormationYamlParser {
|
||||
register("!Length", n -> fnMap("Fn::Length", n));
|
||||
register("!ToJsonString", n -> fnMap("Fn::ToJsonString", n));
|
||||
register("!Transform", n -> fnMap("Fn::Transform", n));
|
||||
// CloudFormation has no date type: an unquoted 2010-09-09 or 2012-10-17 is the text.
|
||||
yamlConstructors.put(Tag.TIMESTAMP, yamlConstructors.get(Tag.STR));
|
||||
}
|
||||
|
||||
private void register(String tag, NodeConverter converter) {
|
||||
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
package io.floci.aws.services.cloudformation;
|
||||
|
||||
import io.floci.aws.testing.AwsTestClients;
|
||||
import io.floci.aws.testing.CfnStackWaits;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import software.amazon.awssdk.regions.Region;
|
||||
import software.amazon.awssdk.services.cloudformation.CloudFormationClient;
|
||||
import software.amazon.awssdk.services.cloudformation.model.Stack;
|
||||
import software.amazon.awssdk.services.ssm.SsmClient;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
@QuarkusTest
|
||||
class CloudFormationYamlDateIntegrationTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(booleans = {false, true})
|
||||
void dateDefaultsRemainTextInResourcesAndOutputs(boolean quoted) {
|
||||
String name = "cfn-yaml-date-" + UUID.randomUUID();
|
||||
String date = quoted ? "'2012-10-17'" : "2012-10-17";
|
||||
String template = """
|
||||
AWSTemplateFormatVersion: '2010-09-09'
|
||||
Parameters:
|
||||
DateValue:
|
||||
Type: String
|
||||
Default: %s
|
||||
Resources:
|
||||
Parameter:
|
||||
Type: AWS::SSM::Parameter
|
||||
Properties:
|
||||
Name: %s
|
||||
Type: String
|
||||
Value: !Ref DateValue
|
||||
Outputs:
|
||||
DateText:
|
||||
Value: !Ref DateValue
|
||||
""".formatted(date, name);
|
||||
|
||||
try (CloudFormationClient cloudFormation = AwsTestClients.create(
|
||||
CloudFormationClient.builder(), "test", Region.US_EAST_1);
|
||||
SsmClient ssm = AwsTestClients.create(SsmClient.builder(), "test", Region.US_EAST_1)) {
|
||||
cloudFormation.createStack(request -> request.stackName(name).templateBody(template));
|
||||
try {
|
||||
Stack stack = CfnStackWaits.awaitStatus(cloudFormation, name, "CREATE_COMPLETE");
|
||||
|
||||
assertEquals("2012-10-17", ssm.getParameter(request -> request.name(name)).parameter().value());
|
||||
assertEquals("2012-10-17", CfnStackWaits.output(stack, "DateText"));
|
||||
assertEquals("2012-10-17", stack.parameters().stream()
|
||||
.filter(parameter -> "DateValue".equals(parameter.parameterKey()))
|
||||
.findFirst().orElseThrow().parameterValue());
|
||||
} finally {
|
||||
cloudFormation.deleteStack(request -> request.stackName(name));
|
||||
CfnStackWaits.awaitStackDeleted(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -93,4 +93,21 @@ class CloudFormationYamlParserTest {
|
||||
assertTrue(getAtt.isTextual());
|
||||
assertEquals(operand, getAtt.textValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
void unquotedDatesStayText() throws Exception {
|
||||
JsonNode node = parse("""
|
||||
AWSTemplateFormatVersion: 2010-09-09
|
||||
Resources:
|
||||
Policy:
|
||||
Properties:
|
||||
PolicyDocument:
|
||||
Version: 2012-10-17
|
||||
""");
|
||||
assertTrue(node.get("AWSTemplateFormatVersion").isTextual());
|
||||
assertEquals("2010-09-09", node.get("AWSTemplateFormatVersion").asText());
|
||||
JsonNode version = node.get("Resources").get("Policy").get("Properties").get("PolicyDocument").get("Version");
|
||||
assertTrue(version.isTextual());
|
||||
assertEquals("2012-10-17", version.asText());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user