mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(cloudformation): provision CloudWatch Logs log groups (#1369)
Inject CloudWatchLogsService and add provision + delete handling for AWS::Logs::LogGroup, mapping LogGroupName, RetentionInDays and Tags. Ref returns the log group name; Fn::GetAtt Arn returns the log-group ARN. Docker-free integration test: CreateStack -> DescribeLogGroups shows the group.
This commit is contained in:
1 parent
50c768643d
commit
57d9ef5ad8
4 files changed
+128
-3
No files matched your search
+86
@@ -0,0 +1,86 @@
|
||||
package io.github.hectorvent.floci.services.cloudformation;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.config.EncoderConfig;
|
||||
import io.restassured.http.ContentType;
|
||||
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 an AWS::Logs::LogGroup for real (into
|
||||
* CloudWatchLogsService) rather than stubbing it. Log groups are metadata (no container), so the
|
||||
* test is Docker-free.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class CloudFormationLogsIntegrationTest {
|
||||
|
||||
private static final String CFN_AUTH =
|
||||
"AWS4-HMAC-SHA256 Credential=test/20260205/us-east-1/cloudformation/aws4_request";
|
||||
private static final String LOGS_AUTH =
|
||||
"AWS4-HMAC-SHA256 Credential=test/20260205/us-east-1/logs/aws4_request";
|
||||
|
||||
@Test
|
||||
void createStackProvisionsLogGroupVisibleToCloudWatchLogs() {
|
||||
String suffix = Long.toString(System.nanoTime(), 36);
|
||||
String logGroupName = "/cfn/test/" + suffix;
|
||||
String stackName = "cfn-logs-stack-" + suffix;
|
||||
|
||||
String template = """
|
||||
{
|
||||
"Resources": {
|
||||
"LogGroup": {
|
||||
"Type": "AWS::Logs::LogGroup",
|
||||
"Properties": {
|
||||
"LogGroupName": "%s",
|
||||
"RetentionInDays": 7
|
||||
}
|
||||
}
|
||||
},
|
||||
"Outputs": {
|
||||
"GroupArn": {"Value": {"Fn::GetAtt": ["LogGroup", "Arn"]}}
|
||||
}
|
||||
}
|
||||
""".formatted(logGroupName);
|
||||
|
||||
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(LogGroup, Arn) resolves to the log group 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("log-group:" + logGroupName + ":*"));
|
||||
|
||||
// The log group really exists in CloudWatch Logs.
|
||||
given()
|
||||
.config(RestAssured.config().encoderConfig(EncoderConfig.encoderConfig()
|
||||
.encodeContentTypeAs("application/x-amz-json-1.1", ContentType.TEXT)))
|
||||
.header("Authorization", LOGS_AUTH)
|
||||
.header("X-Amz-Target", "Logs_20140328.DescribeLogGroups")
|
||||
.contentType("application/x-amz-json-1.1")
|
||||
.body("{\"logGroupNamePrefix\":\"" + logGroupName + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString(logGroupName));
|
||||
}
|
||||
}
|
||||
+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, mapper, store, endpoint, 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);
|
||||
rdsService, null, null);
|
||||
}
|
||||
|
||||
private CloudFormationTemplateEngine engine() {
|
||||
|
||||
Reference in new issue
Block a user