mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(autoscaling): round-trip launch configuration InstanceMonitoring and BlockDeviceMappings (#3174)
CreateLaunchConfiguration stores InstanceMonitoring.Enabled and BlockDeviceMappings, and DescribeLaunchConfigurations returns both structures the way AWS does, with monitoring defaulting to enabled and mappings to an empty list. The Terraform provider read the missing elements as disabled monitoring and no root device, which forced a replacement on every plan. Ported from lex00/floci#132.
This commit is contained in:
1 parent
f485122ffc
commit
4cc850e8df
7 files changed
+341
-3
No files matched your search
+88
@@ -62,6 +62,94 @@ class AutoScalingIntegrationTest {
|
||||
.body(containsString("t3.micro"));
|
||||
}
|
||||
|
||||
// AWS always returns InstanceMonitoring and BlockDeviceMappings from
|
||||
// DescribeLaunchConfigurations. Omitting them made the Terraform provider read
|
||||
// enable_monitoring as false and root_block_device as empty, which forced a
|
||||
// replacement on every plan.
|
||||
@Test
|
||||
@Order(42)
|
||||
void launchConfigurationRoundTripsMonitoringAndBlockDeviceMappings() {
|
||||
given()
|
||||
.formParam("Action", "CreateLaunchConfiguration")
|
||||
.formParam("LaunchConfigurationName", "my-lc-with-root-device")
|
||||
.formParam("ImageId", "ami-12345678")
|
||||
.formParam("InstanceType", "t3.micro")
|
||||
.formParam("InstanceMonitoring.Enabled", "false")
|
||||
.formParam("BlockDeviceMappings.member.1.DeviceName", "/dev/xvda")
|
||||
.formParam("BlockDeviceMappings.member.1.Ebs.VolumeSize", "100")
|
||||
.formParam("BlockDeviceMappings.member.1.Ebs.VolumeType", "gp3")
|
||||
.formParam("BlockDeviceMappings.member.1.Ebs.Throughput", "125")
|
||||
.formParam("BlockDeviceMappings.member.1.Ebs.DeleteOnTermination", "true")
|
||||
.formParam("BlockDeviceMappings.member.2.DeviceName", "/dev/sdb")
|
||||
.formParam("BlockDeviceMappings.member.2.VirtualName", "ephemeral0")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("CreateLaunchConfigurationResponse"));
|
||||
|
||||
given()
|
||||
.formParam("Action", "DescribeLaunchConfigurations")
|
||||
.formParam("LaunchConfigurationNames.member.1", "my-lc-with-root-device")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<InstanceMonitoring><Enabled>false</Enabled></InstanceMonitoring>"))
|
||||
.body(containsString("<DeviceName>/dev/xvda</DeviceName>"))
|
||||
.body(containsString("<VolumeSize>100</VolumeSize>"))
|
||||
.body(containsString("<VolumeType>gp3</VolumeType>"))
|
||||
.body(containsString("<Throughput>125</Throughput>"))
|
||||
.body(containsString("<DeleteOnTermination>true</DeleteOnTermination>"))
|
||||
.body(containsString("<VirtualName>ephemeral0</VirtualName>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(43)
|
||||
void launchConfigurationDefaultsMonitoringToEnabledAndMappingsToEmpty() {
|
||||
given()
|
||||
.formParam("Action", "CreateLaunchConfiguration")
|
||||
.formParam("LaunchConfigurationName", "my-lc-defaults")
|
||||
.formParam("ImageId", "ami-12345678")
|
||||
.formParam("InstanceType", "t3.micro")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.formParam("Action", "DescribeLaunchConfigurations")
|
||||
.formParam("LaunchConfigurationNames.member.1", "my-lc-defaults")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<InstanceMonitoring><Enabled>true</Enabled></InstanceMonitoring>"))
|
||||
.body(containsString("<BlockDeviceMappings></BlockDeviceMappings>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(44)
|
||||
void launchConfigurationRejectsAMappingWithoutADeviceName() {
|
||||
given()
|
||||
.formParam("Action", "CreateLaunchConfiguration")
|
||||
.formParam("LaunchConfigurationName", "my-lc-bad-mapping")
|
||||
.formParam("ImageId", "ami-12345678")
|
||||
.formParam("InstanceType", "t3.micro")
|
||||
.formParam("BlockDeviceMappings.member.1.Ebs.VolumeSize", "100")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body(containsString("ValidationError"))
|
||||
.body(containsString("BlockDeviceMappings.member.1.DeviceName"));
|
||||
}
|
||||
|
||||
// ── Auto Scaling Groups ───────────────────────────────────────────────────
|
||||
|
||||
@Test
|
||||
|
||||
+50
@@ -4,6 +4,7 @@ import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.services.autoscaling.model.AsgInstance;
|
||||
import io.github.hectorvent.floci.services.autoscaling.model.InstanceRefresh;
|
||||
import io.github.hectorvent.floci.services.autoscaling.model.LaunchConfigurationBlockDeviceMapping;
|
||||
import io.github.hectorvent.floci.services.autoscaling.model.MixedInstancesPolicy;
|
||||
import io.github.hectorvent.floci.services.ec2.Ec2Service;
|
||||
import io.github.hectorvent.floci.services.ec2.model.GroupIdentifier;
|
||||
@@ -205,6 +206,55 @@ class AutoScalingServiceTest {
|
||||
service.describeLaunchConfigurations(REGION, List.of("lc-from-instance")).getFirst());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createLaunchConfigurationDefaultsInstanceMonitoringToEnabled() {
|
||||
var lc = service.createLaunchConfiguration(REGION, "lc-default-monitoring", null,
|
||||
"ami-12345678", "t3.micro", null, List.of(), null, null, null);
|
||||
|
||||
assertEquals(Boolean.TRUE, lc.getInstanceMonitoringEnabled());
|
||||
assertEquals(List.of(), lc.getBlockDeviceMappings());
|
||||
assertEquals(Boolean.TRUE,
|
||||
service.describeLaunchConfigurations(REGION, List.of("lc-default-monitoring"))
|
||||
.getFirst().getInstanceMonitoringEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createLaunchConfigurationKeepsAnExplicitInstanceMonitoringOverride() {
|
||||
var lc = service.createLaunchConfiguration(REGION, "lc-monitoring-off", null,
|
||||
"ami-12345678", "t3.micro", null, List.of(), null, null, null, Boolean.FALSE, List.of());
|
||||
|
||||
assertEquals(Boolean.FALSE, lc.getInstanceMonitoringEnabled());
|
||||
assertEquals(Boolean.FALSE,
|
||||
service.describeLaunchConfigurations(REGION, List.of("lc-monitoring-off"))
|
||||
.getFirst().getInstanceMonitoringEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createLaunchConfigurationRoundTripsBlockDeviceMappings() {
|
||||
var ebs = new LaunchConfigurationBlockDeviceMapping.Ebs();
|
||||
ebs.setVolumeSize(100);
|
||||
ebs.setVolumeType("gp3");
|
||||
ebs.setIops(3000);
|
||||
ebs.setThroughput(125);
|
||||
ebs.setDeleteOnTermination(true);
|
||||
var mapping = new LaunchConfigurationBlockDeviceMapping();
|
||||
mapping.setDeviceName("/dev/xvda");
|
||||
mapping.setEbs(ebs);
|
||||
|
||||
service.createLaunchConfiguration(REGION, "lc-with-root-device", null,
|
||||
"ami-12345678", "t3.micro", null, List.of(), null, null, null, null, List.of(mapping));
|
||||
|
||||
var stored = service.describeLaunchConfigurations(REGION, List.of("lc-with-root-device"))
|
||||
.getFirst().getBlockDeviceMappings();
|
||||
assertEquals(1, stored.size());
|
||||
assertEquals("/dev/xvda", stored.getFirst().getDeviceName());
|
||||
assertEquals(100, stored.getFirst().getEbs().getVolumeSize());
|
||||
assertEquals("gp3", stored.getFirst().getEbs().getVolumeType());
|
||||
assertEquals(3000, stored.getFirst().getEbs().getIops());
|
||||
assertEquals(125, stored.getFirst().getEbs().getThroughput());
|
||||
assertEquals(Boolean.TRUE, stored.getFirst().getEbs().getDeleteOnTermination());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createAutoScalingGroupRejectsUnresolvedLaunchTemplateBeforeMutation() {
|
||||
Ec2Service ec2Service = mock(Ec2Service.class);
|
||||
|
||||
Reference in new issue
Block a user