fix(ec2): record EbsOptimized from RunInstances (#6875)

* fix(ec2): record EbsOptimized from RunInstances

RunInstances dropped EbsOptimized, so an aws_instance with
ebs_optimized = true read back false and Terraform replaced it on every
plan. The request's value, else the launch template's, is now recorded on
each launched instance.

It is applied after the launch on the RunInstances API path only;
instances launched by CloudFormation, Auto Scaling or Fleet still report
false (documented).

* test(ec2): clean up the launch template and each instance if a launch fails

The launch-template case launched both instances before its cleanup scope
opened, so a failed launch leaked the template and, on the second launch,
the first instance.
This commit is contained in:
Allen Sanborn authored and GitHub committed 2026-10-28 21:05:31 -04:00
1 parent e820414f22
commit 3f36c4e99e
3 files changed
+112 -1

No files matched your search

@@ -940,6 +940,20 @@ public class Ec2QueryHandler {
p.getFirst("Placement.HostId"), p.getFirst("Placement.Tenancy"), blockDeviceMappings,
"spot".equals(marketType), privateIpAddress, capacitySpecification);
// The request's EbsOptimized wins over a launch template's. Applied after the launch, on this
// API path only: CloudFormation, Auto Scaling and Fleet launches still read false. Passing it
// into Ec2Service.runInstances would cover all of them.
Boolean ebsOptimized = boolParam(p, "EbsOptimized");
if (ebsOptimized == null && launchTemplateData != null) {
ebsOptimized = launchTemplateData.getEbsOptimized();
}
if (ebsOptimized != null) {
for (Instance inst : res.getInstances()) {
service.modifyInstanceAttribute(region, inst.getInstanceId(), "ebsOptimized", ebsOptimized.toString());
inst.setEbsOptimized(ebsOptimized);
}
}
if (!networkInterfaceTags.isEmpty()) {
List<String> eniIds = new ArrayList<>();
for (Instance inst : res.getInstances()) {