mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
fix(ec2): add volumeId to BlockDeviceMapping and disableApiStop/disableApiTermination to DescribeInstanceAttribute (#1028)
Fixes Terraform provider crash when creating aws_instance against floci. Changes: - Add rootVolumeId field to Instance model - Create root EBS volume (gp3) with VolumeAttachment on instance launch - Include volumeId in blockDeviceMapping XML response (null-safe) - Delete root volume on instance termination (deleteOnTermination behavior) - Use inst.getRootDeviceName() for volume attachment device name - Add disableApiStop/disableApiTermination model fields and DescribeInstanceAttribute support (with comment documenting known limitation that ModifyInstanceAttribute does not yet wire these) - Add integration tests for blockDeviceMapping volumeId, DescribeVolumes in-use state, DescribeInstanceAttribute, and volume cleanup on terminate Ref: floci-io/floci#871
This commit is contained in:
1 parent
55a90e8299
commit
ad02786b8a
4 files changed
+161
-7
No files matched your search
@@ -423,6 +423,10 @@ public class Ec2QueryHandler {
|
||||
xml.start("sourceDestCheck").elem("value", String.valueOf(inst.isSourceDestCheck())).end("sourceDestCheck");
|
||||
} else if ("ebsOptimized".equals(attribute)) {
|
||||
xml.start("ebsOptimized").elem("value", String.valueOf(inst.isEbsOptimized())).end("ebsOptimized");
|
||||
} else if ("disableApiStop".equals(attribute)) {
|
||||
xml.start("disableApiStop").elem("value", String.valueOf(inst.isDisableApiStop())).end("disableApiStop");
|
||||
} else if ("disableApiTermination".equals(attribute)) {
|
||||
xml.start("disableApiTermination").elem("value", String.valueOf(inst.isDisableApiTermination())).end("disableApiTermination");
|
||||
}
|
||||
xml.end("DescribeInstanceAttributeResponse");
|
||||
return xmlResponse(xml.build());
|
||||
@@ -1320,16 +1324,19 @@ public class Ec2QueryHandler {
|
||||
.end("privateDnsNameOptions")
|
||||
.start("capacityReservationSpecification")
|
||||
.elem("capacityReservationPreference", "open")
|
||||
.end("capacityReservationSpecification")
|
||||
.start("blockDeviceMapping")
|
||||
.end("capacityReservationSpecification");
|
||||
if (inst.getRootVolumeId() != null) {
|
||||
xml.start("blockDeviceMapping")
|
||||
.start("item")
|
||||
.elem("deviceName", inst.getRootDeviceName())
|
||||
.start("ebs")
|
||||
.elem("volumeId", inst.getRootVolumeId())
|
||||
.elem("status", "attached")
|
||||
.elem("deleteOnTermination", "true")
|
||||
.end("ebs")
|
||||
.end("item")
|
||||
.end("blockDeviceMapping");
|
||||
}
|
||||
xml.raw(tagSetXml(inst.getTags()));
|
||||
return xml.build();
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ import io.github.hectorvent.floci.services.ec2.model.SecurityGroupRule;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Subnet;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Tag;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Volume;
|
||||
import io.github.hectorvent.floci.services.ec2.model.VolumeAttachment;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Vpc;
|
||||
import io.github.hectorvent.floci.services.ec2.model.VpcCidrBlockAssociation;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
@@ -284,6 +285,27 @@ public class Ec2Service {
|
||||
eni.setDeviceIndex(0);
|
||||
inst.getNetworkInterfaces().add(eni);
|
||||
|
||||
// Root EBS volume
|
||||
String rootVolId = "vol-" + randomHex(17);
|
||||
inst.setRootVolumeId(rootVolId);
|
||||
Volume rootVol = new Volume();
|
||||
rootVol.setVolumeId(rootVolId);
|
||||
rootVol.setAvailabilityZone(az);
|
||||
rootVol.setVolumeType("gp3");
|
||||
rootVol.setSize(8);
|
||||
rootVol.setState("in-use");
|
||||
rootVol.setRegion(region);
|
||||
rootVol.setCreateTime(Instant.now());
|
||||
VolumeAttachment att = new VolumeAttachment();
|
||||
att.setVolumeId(rootVolId);
|
||||
att.setInstanceId(instanceId);
|
||||
att.setDevice(inst.getRootDeviceName());
|
||||
att.setState("attached");
|
||||
att.setDeleteOnTermination(true);
|
||||
att.setAttachTime(Instant.now());
|
||||
rootVol.getAttachments().add(att);
|
||||
volumes.put(key(region, rootVolId), rootVol);
|
||||
|
||||
instances.put(key(region, instanceId), inst);
|
||||
reservation.getInstances().add(inst);
|
||||
|
||||
@@ -371,6 +393,10 @@ public class Ec2Service {
|
||||
} else {
|
||||
containerManager.terminate(inst);
|
||||
}
|
||||
// Delete root volume if deleteOnTermination (matches real AWS behavior)
|
||||
if (inst.getRootVolumeId() != null) {
|
||||
volumes.remove(key(region, inst.getRootVolumeId()));
|
||||
}
|
||||
Map<String, String> entry = new LinkedHashMap<>();
|
||||
entry.put("instanceId", id);
|
||||
entry.put("previousState", prev.getName());
|
||||
|
||||
@@ -42,6 +42,14 @@ public class Instance {
|
||||
private String region;
|
||||
private List<Tag> tags = new ArrayList<>();
|
||||
|
||||
private String rootVolumeId;
|
||||
|
||||
// NOTE: disableApiStop and disableApiTermination are stored but ModifyInstanceAttribute
|
||||
// does not yet wire them through. Terraform reads these via DescribeInstanceAttribute;
|
||||
// without model backing, a modify → plan cycle would show drift. Tracked as a known limitation.
|
||||
private boolean disableApiStop = false;
|
||||
private boolean disableApiTermination = false;
|
||||
|
||||
// Docker backing fields (not serialised to AWS wire format)
|
||||
private String dockerContainerId;
|
||||
private String containerBridgeIp;
|
||||
@@ -155,4 +163,13 @@ public class Instance {
|
||||
|
||||
public String getContainerBridgeIp() { return containerBridgeIp; }
|
||||
public void setContainerBridgeIp(String containerBridgeIp) { this.containerBridgeIp = containerBridgeIp; }
|
||||
|
||||
public String getRootVolumeId() { return rootVolumeId; }
|
||||
public void setRootVolumeId(String rootVolumeId) { this.rootVolumeId = rootVolumeId; }
|
||||
|
||||
public boolean isDisableApiStop() { return disableApiStop; }
|
||||
public void setDisableApiStop(boolean disableApiStop) { this.disableApiStop = disableApiStop; }
|
||||
|
||||
public boolean isDisableApiTermination() { return disableApiTermination; }
|
||||
public void setDisableApiTermination(boolean disableApiTermination) { this.disableApiTermination = disableApiTermination; }
|
||||
}
|
||||
Reference in new issue
Block a user