Search in sources :

Example 41 with Context

use of de.widdix.awscftemplates.Context 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 42 with Context

use of de.widdix.awscftemplates.Context 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 43 with Context

use of de.widdix.awscftemplates.Context 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)

Example 44 with Context

use of de.widdix.awscftemplates.Context in project aws-cf-templates by widdix.

the class TestVPC4AZsLegacy method test.

@Test
public void test() {
    final Context context = new Context();
    final String vpcStackName = "vpc-4azs-" + this.random8String();
    final String stackName = "vpc-4azs-legacy-" + this.random8String();
    try {
        this.createStack(context, vpcStackName, "vpc/vpc-4azs.yaml", new Parameter().withParameterKey("ClassB").withParameterValue("10"));
        final Map<String, String> vpcOutputs = this.getStackOutputs(vpcStackName);
        try {
            this.createStack(context, stackName, "vpc/vpc-4azs-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("AZD").withParameterValue(vpcOutputs.get("AZD")), 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("SubnetDPublic").withParameterValue(vpcOutputs.get("SubnetDPublic")), new Parameter().withParameterKey("RouteTableDPublic").withParameterValue(vpcOutputs.get("RouteTableDPublic")), 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")), new Parameter().withParameterKey("SubnetDPrivate").withParameterValue(vpcOutputs.get("SubnetDPrivate")), new Parameter().withParameterKey("RouteTableDPrivate").withParameterValue(vpcOutputs.get("RouteTableDPrivate")));
            this.testVPCSubnetInternetAccess(context, stackName, "SubnetAPublic");
            this.testVPCSubnetInternetAccess(context, stackName, "SubnetBPublic");
            this.testVPCSubnetInternetAccess(context, stackName, "SubnetCPublic");
            this.testVPCSubnetInternetAccess(context, stackName, "SubnetDPublic");
        } 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 45 with Context

use of de.widdix.awscftemplates.Context in project aws-cf-templates by widdix.

the class TestVPCEndpointS3 method test.

@Test
public void test() {
    final Context context = new Context();
    final String vpcStackName = "vpc-2azs-" + this.random8String();
    final String endpointStackName = "vpc-endpoint-s3-" + this.random8String();
    final String classB = "10";
    try {
        this.createStack(context, vpcStackName, "vpc/vpc-2azs.yaml", new Parameter().withParameterKey("ClassB").withParameterValue(classB));
        try {
            this.createStack(context, endpointStackName, "vpc/vpc-endpoint-s3.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName));
        // TODO how can we check if this stack works?
        } finally {
            this.deleteStack(context, endpointStackName);
        }
    } finally {
        this.deleteStack(context, vpcStackName);
    }
}
Also used : Context(de.widdix.awscftemplates.Context) Parameter(com.amazonaws.services.cloudformation.model.Parameter) ACloudFormationTest(de.widdix.awscftemplates.ACloudFormationTest) Test(org.junit.Test)

Aggregations

Context (de.widdix.awscftemplates.Context)70 Test (org.junit.Test)70 Parameter (com.amazonaws.services.cloudformation.model.Parameter)66 ACloudFormationTest (de.widdix.awscftemplates.ACloudFormationTest)62 HttpResponse (org.apache.http.HttpResponse)19 KeyPair (com.amazonaws.services.ec2.model.KeyPair)4 DescribeContainerInstancesRequest (com.amazonaws.services.ecs.model.DescribeContainerInstancesRequest)2 DescribeContainerInstancesResult (com.amazonaws.services.ecs.model.DescribeContainerInstancesResult)2 ListContainerInstancesRequest (com.amazonaws.services.ecs.model.ListContainerInstancesRequest)2 ListContainerInstancesResult (com.amazonaws.services.ecs.model.ListContainerInstancesResult)2 Session (com.jcraft.jsch.Session)1 Ignore (org.junit.Ignore)1