mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(cloudformation): fail an EC2 instance whose LaunchTemplate cannot be resolved (#4058)
Ec2InstanceCfnProvisioner swallowed a failed resolveLaunchTemplateData at debug and then launched the instance with default config (t3.micro, no template AMI/KeyName). A LaunchTemplate a stack references but that does not resolve is a real error, as on AWS, so let the AwsException propagate and fail the resource. The unused LOG field is removed with the swallow. The lookup only runs when the resolved LaunchTemplate is an object naming a template: an Fn::If that selects AWS::NoValue resolves to an empty node (CloudFormationTemplateEngine maps AWS::NoValue to ""), which on AWS means the property is absent, so it must launch without a template rather than raise InvalidLaunchTemplateId.NotFound. Refs #3810
This commit is contained in:
1 parent
12cad79616
commit
e1334cb512
2 files changed
+50
-22
No files matched your search
+31
@@ -91,6 +91,37 @@ class Ec2InstanceCfnProvisionerTest {
|
||||
eq("template-key"), anyList(), any(), any(), anyList(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aLaunchTemplateThatDoesNotResolveFailsTheInstance() throws Exception {
|
||||
when(ec2.resolveLaunchTemplateData("us-east-1", "lt-missing", null, null))
|
||||
.thenThrow(new AwsException("InvalidLaunchTemplateId.NotFound",
|
||||
"The specified launch template does not exist.", 400));
|
||||
|
||||
AwsException e = assertThrows(AwsException.class, () -> provisioner.provision(resource("Server"), props("""
|
||||
{"LaunchTemplate": {"LaunchTemplateId": "lt-missing"}}
|
||||
"""), ctx()));
|
||||
|
||||
assertEquals("InvalidLaunchTemplateId.NotFound", e.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aLaunchTemplateResolvingToNoValueLaunchesWithoutIt() throws Exception {
|
||||
Instance instance = new Instance();
|
||||
instance.setInstanceId("i-nolt");
|
||||
stubLaunch(instance);
|
||||
|
||||
// An Fn::If selecting AWS::NoValue resolves to an empty node, which on AWS means the property
|
||||
// is absent: the instance launches without a template rather than failing to resolve one.
|
||||
StackResource r = resource("Server");
|
||||
provisioner.provision(r, props("""
|
||||
{"LaunchTemplate": ""}
|
||||
"""), ctx());
|
||||
|
||||
assertEquals("i-nolt", r.getPhysicalId());
|
||||
verify(ec2).runInstances(eq("us-east-1"), any(), eq("t3.micro"), eq(1), eq(1), any(),
|
||||
anyList(), any(), any(), anyList(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void provisionsAnInstanceDeclaredWithNoProperties() {
|
||||
Instance instance = new Instance();
|
||||
|
||||
Reference in new issue
Block a user