mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(cloudformation): provision Auto Scaling groups and launch configurations (#1372)
Inject AutoScalingService and add provision + delete handling for AWS::AutoScaling::LaunchConfiguration and AWS::AutoScaling::AutoScalingGroup. Launch configurations map ImageId, InstanceType, KeyName, SecurityGroups, UserData and IamInstanceProfile; groups map the launch configuration or launch template, sizes, availability zones, target groups, load balancers, health check and tags. Ref returns the resource name; Fn::GetAtt Arn returns the resource ARN. Docker-free integration test: CreateStack -> DescribeAutoScalingGroups shows the group referencing the launch configuration.
This commit is contained in:
1 parent
6004e57c29
commit
9327a252d6
4 files changed
+199
-3
No files matched your search
+96
@@ -0,0 +1,96 @@
|
||||
package io.github.hectorvent.floci.services.cloudformation;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
|
||||
/**
|
||||
* End-to-end check that CloudFormation provisions AWS::AutoScaling::LaunchConfiguration and
|
||||
* AWS::AutoScaling::AutoScalingGroup for real (into AutoScalingService) rather than stubbing them,
|
||||
* and that the group references the launch configuration created in the same stack. Both are
|
||||
* metadata (no container), so the test is Docker-free. Auto Scaling is the Query API.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class CloudFormationAutoScalingIntegrationTest {
|
||||
|
||||
private static final String CFN_AUTH =
|
||||
"AWS4-HMAC-SHA256 Credential=test/20260205/us-east-1/cloudformation/aws4_request";
|
||||
private static final String ASG_AUTH =
|
||||
"AWS4-HMAC-SHA256 Credential=test/20260205/us-east-1/autoscaling/aws4_request";
|
||||
|
||||
@Test
|
||||
void createStackProvisionsAutoScalingGroupVisibleToAutoScaling() {
|
||||
String suffix = Long.toString(System.nanoTime(), 36);
|
||||
String lcName = "cfn-lc-" + suffix;
|
||||
String asgName = "cfn-asg-" + suffix;
|
||||
String stackName = "cfn-asg-stack-" + suffix;
|
||||
|
||||
String template = """
|
||||
{
|
||||
"Resources": {
|
||||
"LaunchConfig": {
|
||||
"Type": "AWS::AutoScaling::LaunchConfiguration",
|
||||
"Properties": {
|
||||
"LaunchConfigurationName": "%s",
|
||||
"ImageId": "ami-12345678",
|
||||
"InstanceType": "t3.micro"
|
||||
}
|
||||
},
|
||||
"Asg": {
|
||||
"Type": "AWS::AutoScaling::AutoScalingGroup",
|
||||
"Properties": {
|
||||
"AutoScalingGroupName": "%s",
|
||||
"LaunchConfigurationName": {"Ref": "LaunchConfig"},
|
||||
"MinSize": 1,
|
||||
"MaxSize": 3,
|
||||
"DesiredCapacity": 2,
|
||||
"AvailabilityZones": ["us-east-1a"]
|
||||
}
|
||||
}
|
||||
},
|
||||
"Outputs": {
|
||||
"AsgArn": {"Value": {"Fn::GetAtt": ["Asg", "Arn"]}}
|
||||
}
|
||||
}
|
||||
""".formatted(lcName, asgName);
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", CFN_AUTH)
|
||||
.formParam("Action", "CreateStack")
|
||||
.formParam("StackName", stackName)
|
||||
.formParam("TemplateBody", template)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
// Stack completes and Fn::GetAtt(Asg, Arn) resolves to the real ASG ARN.
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", CFN_AUTH)
|
||||
.formParam("Action", "DescribeStacks")
|
||||
.formParam("StackName", stackName)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<StackStatus>CREATE_COMPLETE</StackStatus>"))
|
||||
.body(containsString(":autoScalingGroup:" + asgName));
|
||||
|
||||
// The group really exists in Auto Scaling and references the launch configuration.
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", ASG_AUTH)
|
||||
.formParam("Action", "DescribeAutoScalingGroups")
|
||||
.formParam("AutoScalingGroupNames.member.1", asgName)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString(asgName))
|
||||
.body(containsString(lcName));
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -48,7 +48,7 @@ class CustomResourceProvisionerTest {
|
||||
|
||||
provisioner = new CloudFormationResourceProvisioner(
|
||||
null, null, null, null, lambdaService, null, null, null, null, null,
|
||||
null, null, null, null, null, null, mapper, store, endpoint, null, null, null, null, null, null, null, null, null, null);
|
||||
null, null, null, null, null, null, mapper, store, endpoint, null, null, null, null, null, null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
private CloudFormationTemplateEngine engine() {
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ class RdsCfnProvisionerTest {
|
||||
null, null, null, null, null, null,
|
||||
mapper,
|
||||
null, null, null, null, null, null, null,
|
||||
rdsService, null, null, null, null);
|
||||
rdsService, null, null, null, null, null);
|
||||
}
|
||||
|
||||
private CloudFormationTemplateEngine engine() {
|
||||
|
||||
Reference in new issue
Block a user