fix(autoscaling): propagate ASG tags at launch (#1734)

* fix(autoscaling): propagate ASG tags at launch

* docs: sync service action tables
This commit is contained in:
Jason van Zyl authored and GitHub committed 2026-07-09 00:21:36 -05:00
1 parent 291752c36e
commit acedc30017
10 files changed
+117 -26

No files matched your search

@@ -465,6 +465,11 @@ class AutoScalingIntegrationTest {
.formParam("Tags.member.1.Key", "owner")
.formParam("Tags.member.1.Value", "sample-app")
.formParam("Tags.member.1.PropagateAtLaunch", "true")
.formParam("Tags.member.2.ResourceId", "my-lt-asg")
.formParam("Tags.member.2.ResourceType", "auto-scaling-group")
.formParam("Tags.member.2.Key", "control-plane-only")
.formParam("Tags.member.2.Value", "true")
.formParam("Tags.member.2.PropagateAtLaunch", "false")
.header("Authorization", AUTH)
.when()
.post("/")
@@ -489,7 +494,10 @@ class AutoScalingIntegrationTest {
.body(containsString("<Version>$Latest</Version>"))
.body(containsString("<VPCZoneIdentifier>subnet-12345678,subnet-87654321</VPCZoneIdentifier>"))
.body(containsString("owner"))
.body(containsString("sample-app"));
.body(containsString("sample-app"))
.body(containsString("<PropagateAtLaunch>true</PropagateAtLaunch>"))
.body(containsString("control-plane-only"))
.body(containsString("<PropagateAtLaunch>false</PropagateAtLaunch>"));
given()
.formParam("Action", "DeleteTags")
@@ -37,7 +37,7 @@ class AutoScalingQueryHandlerTest {
"EC2",
0,
List.of("Default"),
java.util.Map.of());
java.util.Map.of(), java.util.Map.of());
AutoScalingQueryHandler handler = new AutoScalingQueryHandler(service);
MultivaluedHashMap<String, String> startParams = new MultivaluedHashMap<>();
@@ -102,6 +102,7 @@ class AutoScalingQueryHandlerTest {
"EC2",
0,
List.of("Default"),
java.util.Map.of(),
java.util.Map.of());
AsgInstance instance = new AsgInstance();
instance.setInstanceId("i-original");
@@ -157,7 +158,7 @@ class AutoScalingQueryHandlerTest {
"EC2",
0,
List.of("Default"),
java.util.Map.of());
java.util.Map.of(), java.util.Map.of());
AsgInstance instance = new AsgInstance();
instance.setInstanceId("i-current");
instance.setAvailabilityZone("us-east-1a");
@@ -206,7 +207,7 @@ class AutoScalingQueryHandlerTest {
"EC2",
0,
List.of("Default"),
java.util.Map.of());
java.util.Map.of(), java.util.Map.of());
AutoScalingQueryHandler handler = new AutoScalingQueryHandler(service);
MultivaluedHashMap<String, String> putParams = new MultivaluedHashMap<>();
@@ -21,6 +21,7 @@ import java.util.Map;
import java.util.Set;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.anyList;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
@@ -70,6 +71,10 @@ class AutoScalingReconcilerTest {
asg.setDesiredCapacity(1);
asg.setLaunchTemplateId("lt-123");
asg.setLaunchTemplateVersion("1");
asg.getTags().put("job-id", "2001");
asg.getTags().put("control-plane-only", "true");
asg.getTagPropagateAtLaunch().put("job-id", true);
asg.getTagPropagateAtLaunch().put("control-plane-only", false);
LaunchTemplate launchTemplate = new LaunchTemplate();
launchTemplate.setLaunchTemplateId("lt-123");
@@ -79,6 +84,7 @@ class AutoScalingReconcilerTest {
version.setInstanceType("t3.micro");
version.setIamInstanceProfileArn("arn:aws:iam::000000000000:instance-profile/app-profile");
List<Tag> instanceTags = List.of(new Tag("app.ClusterId", "development"));
List<Tag> propagatedTags = List.of(new Tag("app.ClusterId", "development"), new Tag("job-id", "2001"));
version.setInstanceTags(instanceTags);
when(ec2Service.describeLaunchTemplates("us-east-1", List.of("lt-123"), List.of(), Map.of()))
.thenReturn(List.of(launchTemplate));
@@ -90,7 +96,7 @@ class AutoScalingReconcilerTest {
reservation.setInstances(List.of(ec2Instance));
when(ec2Service.runInstances(eq("us-east-1"), eq("ami-version-1"), eq("t3.micro"),
eq(1), eq(1), eq(null), eq(List.of()), eq(null), eq(null),
eq(instanceTags), eq(null), eq("arn:aws:iam::000000000000:instance-profile/app-profile"))).thenReturn(reservation);
anyList(), eq(null), eq("arn:aws:iam::000000000000:instance-profile/app-profile"))).thenReturn(reservation);
reconciler.reconcile(asg);
@@ -98,9 +104,15 @@ class AutoScalingReconcilerTest {
assertEquals("i-launched", asg.getInstances().getFirst().getInstanceId());
assertEquals("lt-123", asg.getInstances().getFirst().getLaunchTemplateId());
assertEquals("1", asg.getInstances().getFirst().getLaunchTemplateVersion());
ArgumentCaptor<List<Tag>> tags = ArgumentCaptor.captor();
verify(ec2Service).runInstances(eq("us-east-1"), eq("ami-version-1"), eq("t3.micro"),
eq(1), eq(1), eq(null), eq(List.of()), eq(null), eq(null),
eq(instanceTags), eq(null), eq("arn:aws:iam::000000000000:instance-profile/app-profile"));
tags.capture(), eq(null), eq("arn:aws:iam::000000000000:instance-profile/app-profile"));
assertEquals(propagatedTags.size(), tags.getValue().size());
assertEquals("app.ClusterId", tags.getValue().get(0).getKey());
assertEquals("development", tags.getValue().get(0).getValue());
assertEquals("job-id", tags.getValue().get(1).getKey());
assertEquals("2001", tags.getValue().get(1).getValue());
}
@Test
@@ -48,7 +48,7 @@ class AutoScalingServiceTest {
"EC2",
0,
List.of("Default"),
java.util.Map.of());
java.util.Map.of(), java.util.Map.of());
}
@Test
@@ -120,7 +120,7 @@ class AutoScalingServiceTest {
"EC2",
0,
List.of("Default"),
java.util.Map.of()));
java.util.Map.of(), java.util.Map.of()));
assertEquals("ValidationError", error.getErrorCode());
assertEquals(AutoScalingService.MISSING_LAUNCH_TEMPLATE_IMAGE_ID_MESSAGE, error.getMessage());
@@ -229,7 +229,7 @@ class AutoScalingServiceTest {
"EC2",
0,
List.of("Default"),
java.util.Map.of()));
java.util.Map.of(), java.util.Map.of()));
assertEquals("ValidationError", error.getErrorCode());
assertEquals(AutoScalingService.INVALID_LAUNCH_TEMPLATE_MESSAGE, error.getMessage());
@@ -633,7 +633,7 @@ class AutoScalingServiceTest {
"EC2",
0,
List.of("Default"),
java.util.Map.of());
java.util.Map.of(), java.util.Map.of());
}
private static final class AutoScalingGroupFixture {
@@ -46,7 +46,11 @@ class CloudFormationAutoScalingIntegrationTest {
"MinSize": 1,
"MaxSize": 3,
"DesiredCapacity": 2,
"AvailabilityZones": ["us-east-1a"]
"AvailabilityZones": ["us-east-1a"],
"Tags": [
{"Key": "cluster", "Value": "demo", "PropagateAtLaunch": true},
{"Key": "control-plane", "Value": "only", "PropagateAtLaunch": false}
]
}
}
},
@@ -91,6 +95,12 @@ class CloudFormationAutoScalingIntegrationTest {
.then()
.statusCode(200)
.body(containsString(asgName))
.body(containsString(lcName));
.body(containsString(lcName))
.body(containsString("<Key>cluster</Key>"))
.body(containsString("<Value>demo</Value>"))
.body(containsString("<PropagateAtLaunch>true</PropagateAtLaunch>"))
.body(containsString("<Key>control-plane</Key>"))
.body(containsString("<Value>only</Value>"))
.body(containsString("<PropagateAtLaunch>false</PropagateAtLaunch>"));
}
}