feat(cloudcontrol): include EC2 resource tags (#1933)

* feat(cloudcontrol): include EC2 resource tags

* test(ec2): isolate tag assertions

* fix(cloudcontrol): emit AWS-shaped EC2 tags

* fix(cloudcontrol): filter malformed EC2 tags
This commit is contained in:
Jason van Zyl authored and GitHub committed 2026-08-01 15:55:54 -05:00
1 parent 847c30a52d
commit 205a8f174b
4 files changed
+128 -9

No files matched your search

@@ -7,6 +7,7 @@ import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.services.ec2.Ec2Service;
import io.github.hectorvent.floci.services.ec2.model.SecurityGroup;
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.Vpc;
import io.github.hectorvent.floci.services.iam.IamService;
import io.github.hectorvent.floci.services.iam.model.IamRole;
@@ -66,6 +67,7 @@ public class CloudControlService {
properties.put("VpcId", vpc.getVpcId());
properties.put("CidrBlock", vpc.getCidrBlock());
properties.put("InstanceTenancy", vpc.getInstanceTenancy());
addTags(properties, vpc.getTags());
resources.add(new ResourceDescription(vpc.getVpcId(), propertiesString(properties)));
}
return resources;
@@ -79,6 +81,7 @@ public class CloudControlService {
properties.put("VpcId", subnet.getVpcId());
properties.put("CidrBlock", subnet.getCidrBlock());
properties.put("AvailabilityZone", subnet.getAvailabilityZone());
addTags(properties, subnet.getTags());
resources.add(new ResourceDescription(subnet.getSubnetId(), propertiesString(properties)));
}
return resources;
@@ -92,6 +95,7 @@ public class CloudControlService {
properties.put("GroupName", group.getGroupName());
properties.put("GroupDescription", group.getDescription());
properties.put("VpcId", group.getVpcId());
addTags(properties, group.getTags());
resources.add(new ResourceDescription(group.getGroupId(), propertiesString(properties)));
}
return resources;
@@ -130,5 +134,23 @@ public class CloudControlService {
}
}
private void addTags(ObjectNode properties, List<Tag> tags) {
if (tags == null || tags.isEmpty()) {
return;
}
List<Tag> validTags = tags.stream()
.filter(tag -> tag != null && tag.getKey() != null && !tag.getKey().isBlank())
.toList();
if (validTags.isEmpty()) {
return;
}
var tagArray = properties.putArray("Tags");
for (Tag tag : validTags) {
tagArray.addObject()
.put("Key", tag.getKey())
.put("Value", tag.getValue() == null ? "" : tag.getValue());
}
}
public record ResourceDescription(String identifier, String properties) {}
}