Light, fluffy, and always free - The AWS Local Emulator alternative
fix(cloudformation): create stage from AWS::ApiGateway::Deployment inline StageName (#1400)
Hector Venturaf01a680bff9f
diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationResourceProvisioner.java b/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationResourceProvisioner.javaindex 2ecddeb9e0..ec5cb01af5 100644--- a/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationResourceProvisioner.java+++ b/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationResourceProvisioner.java@@ -2601,6 +2601,20 @@ public class CloudFormationResourceProvisioner {var deployment = apiGatewayService.createDeployment(region, apiId, req);r.setPhysicalId(deployment.id());++ // AWS::ApiGateway::Deployment accepts an inline StageName: when present, AWS creates that+ // stage pointing at this deployment, with no separate AWS::ApiGateway::Stage resource.+ String stageName = resolveOptional(props, "StageName", engine);+ if (stageName != null && !stageName.isBlank()) {+ Map<String, Object> stageReq = new HashMap<>();+ stageReq.put("stageName", stageName);+ stageReq.put("deploymentId", deployment.id());+ JsonNode stageDescription = props != null ? props.get("StageDescription") : null;+ if (stageDescription != null && stageDescription.has("Description")) {+ stageReq.put("description", resolveOptional(stageDescription, "Description", engine));+ }+ apiGatewayService.createStage(region, apiId, stageReq);+ }}private void provisionApiGatewayStage(StackResource r, JsonNode props, CloudFormationTemplateEngine engine,diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationIntegrationTest.javaindex c5a32c8f90..c288dc5c7c 100644--- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationIntegrationTest.java@@ -3971,6 +3971,78 @@ class CloudFormationIntegrationTest {.body("item[0].type", equalTo("TOKEN"));}+ // ── Issue #1163: AWS::ApiGateway::Deployment with inline StageName creates the stage ──++ @Test+ void createStack_withApiGatewayDeploymentStageName_createsStage() {+ // Regression test for issue #1163: a Deployment carrying an inline StageName created+ // the deployment but never the stage, so `get-stages` returned empty and invoking+ // .../{stage}/_user_request_/... returned "Stage not found".+ String stackName = "cfn-apigw-deploy-stagename-stack";+ String template = """+ {+ "Resources": {+ "RestApi": {+ "Type": "AWS::ApiGateway::RestApi",+ "Properties": {+ "Name": "cfn-apigw-deploy-stagename-api"+ }+ },+ "Deployment": {+ "Type": "AWS::ApiGateway::Deployment",+ "Properties": {+ "RestApiId": {"Ref": "RestApi"},+ "StageName": "prod"+ }+ }+ }+ }+ """;++ given()+ .contentType("application/x-www-form-urlencoded")+ .formParam("Action", "CreateStack")+ .formParam("StackName", stackName)+ .formParam("TemplateBody", template)+ .when()+ .post("/")+ .then()+ .statusCode(200);++ given()+ .contentType("application/x-www-form-urlencoded")+ .formParam("Action", "DescribeStacks")+ .formParam("StackName", stackName)+ .when()+ .post("/")+ .then()+ .statusCode(200)+ .body(containsString("<StackStatus>CREATE_COMPLETE</StackStatus>"));++ String resourcesXml = given()+ .contentType("application/x-www-form-urlencoded")+ .formParam("Action", "DescribeStackResources")+ .formParam("StackName", stackName)+ .when()+ .post("/")+ .then()+ .statusCode(200)+ .extract().asString();++ String apiId = physicalIdByLogicalId(resourcesXml, "RestApi");+ String deploymentId = physicalIdByLogicalId(resourcesXml, "Deployment");++ // The inline StageName must have produced a real stage bound to this deployment.+ given()+ .when()+ .get("/restapis/" + apiId + "/stages")+ .then()+ .statusCode(200)+ .body("item.size()", equalTo(1))+ .body("item[0].stageName", equalTo("prod"))+ .body("item[0].deploymentId", equalTo(deploymentId));+ }+@Testvoid createStack_withApiGatewayMethod_wiresAuthorizerIdViaRef() {// Core scenario from issue #788: `AuthorizationType: CUSTOM` plus