Search in sources :

Example 56 with Parameter

use of com.amazonaws.services.cloudformation.model.Parameter in project aws-cf-templates by widdix.

the class TestStaticWebsite method test.

@Test
public void test() {
    final Context context = new Context();
    final String stackNameLambdaEdge = "lambdaedge-index-document-" + this.random8String();
    final String zoneStackName = "zone-" + this.random8String();
    final String stackName = "static-website-" + this.random8String();
    final String subDomainName = stackName;
    final String redirectSubDomainName = "www-" + stackName;
    final String domainName = subDomainName + "." + Config.get(Config.Key.DOMAIN_SUFFIX);
    final String redirectDomainName = redirectSubDomainName + "." + Config.get(Config.Key.DOMAIN_SUFFIX);
    try {
        this.createStack(context, zoneStackName, "vpc/zone-legacy.yaml", new Parameter().withParameterKey("HostedZoneName").withParameterValue(Config.get(Config.Key.DOMAIN_SUFFIX)), new Parameter().withParameterKey("HostedZoneId").withParameterValue(Config.get(Config.Key.HOSTED_ZONE_ID)));
        try {
            this.createStack(context, stackNameLambdaEdge, "static-website/lambdaedge-index-document.yaml", new Parameter().withParameterKey("DomainName").withParameterValue(domainName), new Parameter().withParameterKey("RedirectDomainName").withParameterValue(redirectDomainName));
            final String viewerRequestLambdaEdgeFunctionVersionARN = this.getStackOutputValue(stackNameLambdaEdge, "ViewerRequestLambdaEdgeFunctionVersionARN");
            try {
                this.createStack(context, stackName, "static-website/static-website.yaml", new Parameter().withParameterKey("ParentZoneStack").withParameterValue(zoneStackName), new Parameter().withParameterKey("SubDomainNameWithDot").withParameterValue(subDomainName + "."), new Parameter().withParameterKey("ViewerRequestLambdaEdgeFunctionVersionARN").withParameterValue(viewerRequestLambdaEdgeFunctionVersionARN), new Parameter().withParameterKey("EnableRedirectSubDomainName").withParameterValue("true"), new Parameter().withParameterKey("RedirectSubDomainNameWithDot").withParameterValue(redirectSubDomainName + "."), new Parameter().withParameterKey("CertificateType").withParameterValue("AcmCertificateArn"), new Parameter().withParameterKey("ExistingCertificate").withParameterValue(Config.get(Config.Key.CLOUDFRONT_ACM_CERTIFICATE_ARN)));
                final String url1 = "https://" + domainName + "/";
                final String url2 = "https://" + domainName + "/folder/";
                final String url3 = "https://" + redirectDomainName + "/";
                try {
                    this.createObject(domainName, "index.html", "hello");
                    this.createObject(domainName, "folder/index.html", "hello");
                    final Callable<HttpResponse> callable1 = () -> {
                        final HttpResponse response = WS.url(url1).timeout(10000).get();
                        // check HTTP response code
                        if (WS.getStatus(response) != 200) {
                            throw new RuntimeException("200 expected, but saw " + WS.getStatus(response));
                        }
                        return response;
                    };
                    final Callable<HttpResponse> callable2 = () -> {
                        final HttpResponse response = WS.url(url2).timeout(10000).get();
                        // check HTTP response code
                        if (WS.getStatus(response) != 200) {
                            throw new RuntimeException("200 expected, but saw " + WS.getStatus(response));
                        }
                        return response;
                    };
                    final Callable<HttpResponse> callable3 = () -> {
                        final HttpResponse response = WS.url(url3).timeout(10000).followRedirect(false).get();
                        // check HTTP response code
                        if (WS.getStatus(response) != 301) {
                            throw new RuntimeException("301 expected, but saw " + WS.getStatus(response));
                        }
                        return response;
                    };
                    this.retry(context, callable1);
                    this.retry(context, callable2);
                    this.retry(context, callable3);
                } finally {
                    this.deleteObject(context, domainName, "folder/index.html");
                    this.deleteObject(context, domainName, "index.html");
                }
            } finally {
                this.deleteStackAndRetryOnFailure(context, stackName);
            }
        } finally {
        // this stack is not deleted because Lambda@Edge functions take up to 3 hours before they can be deleted
        // the cleanup Lambda takes care of those stacks
        // this.deleteStackAndRetryOnFailure(stackNameLambdaEdge);
        }
    } finally {
        this.deleteStack(context, zoneStackName);
    }
}
Also used : Context(de.widdix.awscftemplates.Context) Parameter(com.amazonaws.services.cloudformation.model.Parameter) HttpResponse(org.apache.http.HttpResponse) ACloudFormationTest(de.widdix.awscftemplates.ACloudFormationTest) Test(org.junit.Test)

Example 57 with Parameter

use of com.amazonaws.services.cloudformation.model.Parameter in project aws-cf-templates by widdix.

the class TestStaticWebsite method testCreateAcmCertificate.

@Test
public void testCreateAcmCertificate() {
    final Context context = new Context();
    final String zoneStackName = "zone-" + this.random8String();
    final String stackName = "static-website-" + this.random8String();
    final String subDomainName = stackName;
    final String redirectSubDomainName = "www-" + stackName;
    final String domainName = subDomainName + "." + Config.get(Config.Key.DOMAIN_SUFFIX);
    final String redirectDomainName = redirectSubDomainName + "." + Config.get(Config.Key.DOMAIN_SUFFIX);
    try {
        this.createStack(context, zoneStackName, "vpc/zone-legacy.yaml", new Parameter().withParameterKey("HostedZoneName").withParameterValue(Config.get(Config.Key.DOMAIN_SUFFIX)), new Parameter().withParameterKey("HostedZoneId").withParameterValue(Config.get(Config.Key.HOSTED_ZONE_ID)));
        try {
            this.createStack(context, stackName, "static-website/static-website.yaml", new Parameter().withParameterKey("ParentZoneStack").withParameterValue(zoneStackName), new Parameter().withParameterKey("SubDomainNameWithDot").withParameterValue(subDomainName + "."), new Parameter().withParameterKey("EnableRedirectSubDomainName").withParameterValue("true"), new Parameter().withParameterKey("RedirectSubDomainNameWithDot").withParameterValue(redirectSubDomainName + "."), new Parameter().withParameterKey("CertificateType").withParameterValue("CreateAcmCertificate"));
            final String url1 = "https://" + domainName + "/";
            final String url2 = "https://" + redirectDomainName + "/";
            try {
                this.createObject(domainName, "index.html", "hello");
                final Callable<HttpResponse> callable1 = () -> {
                    final HttpResponse response = WS.url(url1).timeout(10000).get();
                    // check HTTP response code
                    if (WS.getStatus(response) != 200) {
                        throw new RuntimeException("200 expected, but saw " + WS.getStatus(response));
                    }
                    return response;
                };
                final Callable<HttpResponse> callable2 = () -> {
                    final HttpResponse response = WS.url(url2).timeout(10000).followRedirect(false).get();
                    // check HTTP response code
                    if (WS.getStatus(response) != 200) {
                        throw new RuntimeException("200 expected, but saw " + WS.getStatus(response));
                    }
                    return response;
                };
                this.retry(context, callable1);
                this.retry(context, callable2);
            } finally {
                this.deleteObject(context, domainName, "index.html");
            }
        } finally {
            this.deleteStackAndRetryOnFailure(context, stackName);
        }
    } finally {
        this.deleteStack(context, zoneStackName);
    }
}
Also used : Context(de.widdix.awscftemplates.Context) Parameter(com.amazonaws.services.cloudformation.model.Parameter) HttpResponse(org.apache.http.HttpResponse) ACloudFormationTest(de.widdix.awscftemplates.ACloudFormationTest) Test(org.junit.Test)

Example 58 with Parameter

use of com.amazonaws.services.cloudformation.model.Parameter in project aws-cf-templates by widdix.

the class TestStaticWebsite method testWAF.

@Test
public void testWAF() {
    final Context context = new Context();
    final String zoneStackName = "zone-" + this.random8String();
    final String wafStackName = "waf-" + this.random8String();
    final String stackName = "static-website-" + this.random8String();
    final String subDomainName = stackName;
    final String redirectSubDomainName = "www-" + stackName;
    final String domainName = subDomainName + "." + Config.get(Config.Key.DOMAIN_SUFFIX);
    final String redirectDomainName = redirectSubDomainName + "." + Config.get(Config.Key.DOMAIN_SUFFIX);
    try {
        this.createStack(context, zoneStackName, "vpc/zone-legacy.yaml", new Parameter().withParameterKey("HostedZoneName").withParameterValue(Config.get(Config.Key.DOMAIN_SUFFIX)), new Parameter().withParameterKey("HostedZoneId").withParameterValue(Config.get(Config.Key.HOSTED_ZONE_ID)));
        try {
            this.createStack(context, wafStackName, "security/waf.yaml", new Parameter().withParameterKey("Scope").withParameterValue("CLOUDFRONT"));
            try {
                this.createStack(context, stackName, "static-website/static-website.yaml", new Parameter().withParameterKey("ParentZoneStack").withParameterValue(zoneStackName), new Parameter().withParameterKey("ParentWAFStack").withParameterValue(wafStackName), new Parameter().withParameterKey("SubDomainNameWithDot").withParameterValue(subDomainName + "."), new Parameter().withParameterKey("EnableRedirectSubDomainName").withParameterValue("true"), new Parameter().withParameterKey("RedirectSubDomainNameWithDot").withParameterValue(redirectSubDomainName + "."), new Parameter().withParameterKey("CertificateType").withParameterValue("CreateAcmCertificate"));
                final String url1 = "https://" + domainName + "/";
                final String url2 = "https://" + redirectDomainName + "/";
                try {
                    this.createObject(domainName, "index.html", "hello");
                    final Callable<HttpResponse> callable1 = () -> {
                        final HttpResponse response = WS.url(url1).timeout(10000).get();
                        // check HTTP response code
                        if (WS.getStatus(response) != 200) {
                            throw new RuntimeException("200 expected, but saw " + WS.getStatus(response));
                        }
                        return response;
                    };
                    final Callable<HttpResponse> callable2 = () -> {
                        final HttpResponse response = WS.url(url2).timeout(10000).followRedirect(false).get();
                        // check HTTP response code
                        if (WS.getStatus(response) != 200) {
                            throw new RuntimeException("200 expected, but saw " + WS.getStatus(response));
                        }
                        return response;
                    };
                    this.retry(context, callable1);
                    this.retry(context, callable2);
                } finally {
                    this.deleteObject(context, domainName, "index.html");
                }
            } finally {
                this.deleteStackAndRetryOnFailure(context, stackName);
            }
        } finally {
            this.deleteStackAndRetryOnFailure(context, wafStackName);
        }
    } finally {
        this.deleteStack(context, zoneStackName);
    }
}
Also used : Context(de.widdix.awscftemplates.Context) Parameter(com.amazonaws.services.cloudformation.model.Parameter) HttpResponse(org.apache.http.HttpResponse) ACloudFormationTest(de.widdix.awscftemplates.ACloudFormationTest) Test(org.junit.Test)

Example 59 with Parameter

use of com.amazonaws.services.cloudformation.model.Parameter in project aws-cf-templates by widdix.

the class TestVPC2AZsLegacy method test.

@Test
public void test() {
    final Context context = new Context();
    final String vpcStackName = "vpc-2azs-" + this.random8String();
    final String stackName = "vpc-2azs-legacy-" + this.random8String();
    try {
        this.createStack(context, vpcStackName, "vpc/vpc-2azs.yaml", new Parameter().withParameterKey("ClassB").withParameterValue("10"));
        final Map<String, String> vpcOutputs = this.getStackOutputs(vpcStackName);
        try {
            this.createStack(context, stackName, "vpc/vpc-2azs-legacy.yaml", new Parameter().withParameterKey("AZA").withParameterValue(vpcOutputs.get("AZA")), new Parameter().withParameterKey("AZB").withParameterValue(vpcOutputs.get("AZB")), new Parameter().withParameterKey("CidrBlock").withParameterValue(vpcOutputs.get("CidrBlock")), new Parameter().withParameterKey("CidrBlockIPv6").withParameterValue(vpcOutputs.get("CidrBlockIPv6")), new Parameter().withParameterKey("VPC").withParameterValue(vpcOutputs.get("VPC")), new Parameter().withParameterKey("InternetGateway").withParameterValue(vpcOutputs.get("InternetGateway")), new Parameter().withParameterKey("SubnetAPublic").withParameterValue(vpcOutputs.get("SubnetAPublic")), new Parameter().withParameterKey("RouteTableAPublic").withParameterValue(vpcOutputs.get("RouteTableAPublic")), new Parameter().withParameterKey("SubnetBPublic").withParameterValue(vpcOutputs.get("SubnetBPublic")), new Parameter().withParameterKey("RouteTableBPublic").withParameterValue(vpcOutputs.get("RouteTableBPublic")), new Parameter().withParameterKey("SubnetAPrivate").withParameterValue(vpcOutputs.get("SubnetAPrivate")), new Parameter().withParameterKey("RouteTableAPrivate").withParameterValue(vpcOutputs.get("RouteTableAPrivate")), new Parameter().withParameterKey("SubnetBPrivate").withParameterValue(vpcOutputs.get("SubnetBPrivate")), new Parameter().withParameterKey("RouteTableBPrivate").withParameterValue(vpcOutputs.get("RouteTableBPrivate")));
            this.testVPCSubnetInternetAccess(context, stackName, "SubnetAPublic");
            this.testVPCSubnetInternetAccess(context, stackName, "SubnetBPublic");
        } finally {
            this.deleteStack(context, stackName);
        }
    } finally {
        this.deleteStack(context, vpcStackName);
    }
}
Also used : Context(de.widdix.awscftemplates.Context) Parameter(com.amazonaws.services.cloudformation.model.Parameter) Test(org.junit.Test)

Example 60 with Parameter

use of com.amazonaws.services.cloudformation.model.Parameter in project aws-cf-templates by widdix.

the class TestVPC3AZsLegacy method test.

@Test
public void test() {
    final Context context = new Context();
    final String vpcStackName = "vpc-3azs-" + this.random8String();
    final String stackName = "vpc-3azs-legacy-" + this.random8String();
    try {
        this.createStack(context, vpcStackName, "vpc/vpc-3azs.yaml", new Parameter().withParameterKey("ClassB").withParameterValue("10"));
        final Map<String, String> vpcOutputs = this.getStackOutputs(vpcStackName);
        try {
            this.createStack(context, stackName, "vpc/vpc-3azs-legacy.yaml", new Parameter().withParameterKey("AZA").withParameterValue(vpcOutputs.get("AZA")), new Parameter().withParameterKey("AZB").withParameterValue(vpcOutputs.get("AZB")), new Parameter().withParameterKey("AZC").withParameterValue(vpcOutputs.get("AZC")), new Parameter().withParameterKey("CidrBlock").withParameterValue(vpcOutputs.get("CidrBlock")), new Parameter().withParameterKey("CidrBlockIPv6").withParameterValue(vpcOutputs.get("CidrBlockIPv6")), new Parameter().withParameterKey("VPC").withParameterValue(vpcOutputs.get("VPC")), new Parameter().withParameterKey("InternetGateway").withParameterValue(vpcOutputs.get("InternetGateway")), new Parameter().withParameterKey("SubnetAPublic").withParameterValue(vpcOutputs.get("SubnetAPublic")), new Parameter().withParameterKey("RouteTableAPublic").withParameterValue(vpcOutputs.get("RouteTableAPublic")), new Parameter().withParameterKey("SubnetBPublic").withParameterValue(vpcOutputs.get("SubnetBPublic")), new Parameter().withParameterKey("RouteTableBPublic").withParameterValue(vpcOutputs.get("RouteTableBPublic")), new Parameter().withParameterKey("SubnetCPublic").withParameterValue(vpcOutputs.get("SubnetCPublic")), new Parameter().withParameterKey("RouteTableCPublic").withParameterValue(vpcOutputs.get("RouteTableCPublic")), new Parameter().withParameterKey("SubnetAPrivate").withParameterValue(vpcOutputs.get("SubnetAPrivate")), new Parameter().withParameterKey("RouteTableAPrivate").withParameterValue(vpcOutputs.get("RouteTableAPrivate")), new Parameter().withParameterKey("SubnetBPrivate").withParameterValue(vpcOutputs.get("SubnetBPrivate")), new Parameter().withParameterKey("RouteTableBPrivate").withParameterValue(vpcOutputs.get("RouteTableBPrivate")), new Parameter().withParameterKey("SubnetCPrivate").withParameterValue(vpcOutputs.get("SubnetCPrivate")), new Parameter().withParameterKey("RouteTableCPrivate").withParameterValue(vpcOutputs.get("RouteTableCPrivate")));
            this.testVPCSubnetInternetAccess(context, stackName, "SubnetAPublic");
            this.testVPCSubnetInternetAccess(context, stackName, "SubnetBPublic");
            this.testVPCSubnetInternetAccess(context, stackName, "SubnetCPublic");
        } finally {
            this.deleteStack(context, stackName);
        }
    } finally {
        this.deleteStack(context, vpcStackName);
    }
}
Also used : Context(de.widdix.awscftemplates.Context) Parameter(com.amazonaws.services.cloudformation.model.Parameter) Test(org.junit.Test)

Aggregations

Parameter (com.amazonaws.services.cloudformation.model.Parameter)85 Test (org.junit.Test)79 Context (de.widdix.awscftemplates.Context)66 ACloudFormationTest (de.widdix.awscftemplates.ACloudFormationTest)60 HttpResponse (org.apache.http.HttpResponse)19 KeyPair (com.amazonaws.services.ec2.model.KeyPair)5 StringInputStream (com.amazonaws.util.StringInputStream)4 ArrayList (java.util.ArrayList)4 DescribeContainerInstancesRequest (com.amazonaws.services.ecs.model.DescribeContainerInstancesRequest)3 DescribeContainerInstancesResult (com.amazonaws.services.ecs.model.DescribeContainerInstancesResult)3 ListContainerInstancesRequest (com.amazonaws.services.ecs.model.ListContainerInstancesRequest)3 ListContainerInstancesResult (com.amazonaws.services.ecs.model.ListContainerInstancesResult)3 ParameterProvider (de.taimos.pipeline.aws.cloudformation.ParameterProvider)3 FilePath (hudson.FilePath)3 AmazonCloudFormation (com.amazonaws.services.cloudformation.AmazonCloudFormation)2 TaskListener (hudson.model.TaskListener)2 CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)2 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 Change (com.amazonaws.services.cloudformation.model.Change)1