Search in sources :

Example 6 with Context

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

the class TestFargateService method testCloudMap.

@Test
public void testCloudMap() throws JSchException {
    final Context context = new Context();
    final String vpcStackName = "vpc-2azs-" + this.random8String();
    final String keyName = "key-" + this.random8String();
    final String bastionStackName = "bastion-" + this.random8String();
    final String clientStackName = "client-" + this.random8String();
    final String cloudmapStackName = "cloudmap-" + this.random8String();
    final String clusterStackName = "fargate-cluster-" + this.random8String();
    final String stackName = "fargate-service-" + this.random8String();
    final String classB = "10";
    try {
        final KeyPair key = this.createKey(keyName);
        try {
            this.createStack(context, vpcStackName, "vpc/vpc-2azs.yaml", new Parameter().withParameterKey("ClassB").withParameterValue(classB));
            try {
                this.createStack(context, bastionStackName, "vpc/vpc-ssh-bastion.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName), new Parameter().withParameterKey("KeyName").withParameterValue(keyName));
                try {
                    this.createStack(context, clientStackName, "state/client-sg.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName));
                    try {
                        this.createStack(context, cloudmapStackName, "vpc/cloudmap-private.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName), new Parameter().withParameterKey("Name").withParameterValue("local"));
                        try {
                            this.createStack(context, clusterStackName, "fargate/cluster.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName));
                            try {
                                this.createStack(context, stackName, "fargate/service-cloudmap.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName), new Parameter().withParameterKey("ParentClusterStack").withParameterValue(clusterStackName), new Parameter().withParameterKey("ParentCloudMapStack").withParameterValue(cloudmapStackName), new Parameter().withParameterKey("ParentClientStack").withParameterValue(clientStackName), new Parameter().withParameterKey("ParentSSHBastionStack").withParameterValue(bastionStackName), new Parameter().withParameterKey("Name").withParameterValue("test"), new Parameter().withParameterKey("AppImage").withParameterValue("nginx:1.11.5"));
                                final String host = this.getStackOutputValue(bastionStackName, "IPAddress");
                                final Session session = this.tunnelSSH(host, key, 8811, "test.local", 80);
                                final String url = "http://localhost:8811";
                                final Callable<String> callable = () -> {
                                    final HttpResponse response = WS.url(url).timeout(10000).get();
                                    // check HTTP response code
                                    if (WS.getStatus(response) != 200) {
                                        throw new RuntimeException("200 expected, but saw " + WS.getStatus(response));
                                    }
                                    return WS.getResponseAsString(response);
                                };
                                final String response = this.retry(context, callable);
                                // check if nginx page appears
                                Assert.assertTrue("http response body contains \"Welcome to nginx!\"", response.contains("Welcome to nginx!"));
                                session.disconnect();
                            } finally {
                                this.deleteStack(context, stackName);
                            }
                        } finally {
                            this.deleteStack(context, clusterStackName);
                        }
                    } finally {
                        this.deleteStack(context, cloudmapStackName);
                    }
                } finally {
                    this.deleteStack(context, clientStackName);
                }
            } finally {
                this.deleteStack(context, bastionStackName);
            }
        } finally {
            this.deleteStack(context, vpcStackName);
        }
    } finally {
        this.deleteKey(context, keyName);
    }
}
Also used : Context(de.widdix.awscftemplates.Context) KeyPair(com.amazonaws.services.ec2.model.KeyPair) Parameter(com.amazonaws.services.cloudformation.model.Parameter) HttpResponse(org.apache.http.HttpResponse) Session(com.jcraft.jsch.Session) ACloudFormationTest(de.widdix.awscftemplates.ACloudFormationTest) Test(org.junit.Test)

Example 7 with Context

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

the class TestFargateService method testClusterAlbHostPattern.

@Test
public void testClusterAlbHostPattern() {
    final Context context = new Context();
    final String zoneStackName = "zone-" + this.random8String();
    final String vpcStackName = "vpc-2azs-" + this.random8String();
    final String clusterStackName = "fargate-cluster-" + this.random8String();
    final String stackName = "fargate-service-" + this.random8String();
    final String classB = "10";
    final String keyName = "key-" + this.random8String();
    final String subDomainName = stackName;
    try {
        this.createKey(keyName);
        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, vpcStackName, "vpc/vpc-2azs.yaml", new Parameter().withParameterKey("ClassB").withParameterValue(classB));
                try {
                    this.createStack(context, clusterStackName, "fargate/cluster.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName));
                    try {
                        final String domain = subDomainName + "." + Config.get(Config.Key.DOMAIN_SUFFIX);
                        this.createStack(context, stackName, "fargate/service-cluster-alb.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName), new Parameter().withParameterKey("ParentClusterStack").withParameterValue(clusterStackName), new Parameter().withParameterKey("ParentZoneStack").withParameterValue(zoneStackName), new Parameter().withParameterKey("SubDomainNameWithDot").withParameterValue(subDomainName + "."), new Parameter().withParameterKey("AppImage").withParameterValue("nginx:1.11.5"), new Parameter().withParameterKey("LoadBalancerPathPattern").withParameterValue(""), new Parameter().withParameterKey("LoadBalancerHostPattern").withParameterValue(domain));
                        final String url = "http://" + domain;
                        final Callable<String> callable = () -> {
                            final HttpResponse response = WS.url(url).timeout(10000).get();
                            // check HTTP response code
                            if (WS.getStatus(response) != 200) {
                                throw new RuntimeException("200 expected, but saw " + WS.getStatus(response));
                            }
                            return WS.getResponseAsString(response);
                        };
                        final String response = this.retry(context, callable);
                        // check if nginx page appears
                        Assert.assertTrue("http response body contains \"Welcome to nginx!\"", response.contains("Welcome to nginx!"));
                    } finally {
                        this.deleteStack(context, stackName);
                    }
                } finally {
                    this.deleteStack(context, clusterStackName);
                }
            } finally {
                this.deleteStack(context, vpcStackName);
            }
        } finally {
            this.deleteStack(context, zoneStackName);
        }
    } finally {
        this.deleteKey(context, keyName);
    }
}
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 8 with Context

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

the class TestFargateService method testWaf.

@Test
public void testWaf() {
    final Context context = new Context();
    final String vpcStackName = "vpc-2azs-" + this.random8String();
    final String wafStackName = "waf-" + this.random8String();
    final String clusterStackName = "fargate-cluster-" + this.random8String();
    final String stackName = "fargate-service-" + 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, wafStackName, "security/waf.yaml");
            try {
                this.createStack(context, clusterStackName, "fargate/cluster.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName), new Parameter().withParameterKey("ParentWAFStack").withParameterValue(wafStackName));
                try {
                    this.createStack(context, stackName, "fargate/service-dedicated-alb.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName), new Parameter().withParameterKey("ParentClusterStack").withParameterValue(clusterStackName), new Parameter().withParameterKey("ParentWAFStack").withParameterValue(wafStackName), new Parameter().withParameterKey("AppImage").withParameterValue("nginx:1.11.5"), new Parameter().withParameterKey("Spot").withParameterValue("true"));
                    final String url = this.getStackOutputValue(stackName, "URL");
                    final Callable<String> callable = () -> {
                        final HttpResponse response = WS.url(url).timeout(10000).get();
                        // check HTTP response code
                        if (WS.getStatus(response) != 200) {
                            throw new RuntimeException("200 expected, but saw " + WS.getStatus(response));
                        }
                        return WS.getResponseAsString(response);
                    };
                    final String response = this.retry(context, callable);
                    // check if nginx page appears
                    Assert.assertTrue("http response body contains \"Welcome to nginx!\"", response.contains("Welcome to nginx!"));
                } finally {
                    this.deleteStack(context, stackName);
                }
            } finally {
                this.deleteStack(context, clusterStackName);
            }
        } finally {
            this.deleteStack(context, wafStackName);
        }
    } finally {
        this.deleteStack(context, vpcStackName);
    }
}
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 9 with Context

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

the class TestAccessLogsAnonymizer method alb.

@Test
public void alb() {
    final Context context = new Context();
    final String s3StackName = "s3-" + this.random8String();
    final String anonymizerStackName = "anonymizer-" + this.random8String();
    try {
        this.createStack(context, s3StackName, "state/s3.yaml", new Parameter().withParameterKey("Access").withParameterValue("ElbAccessLogWrite"));
        try {
            this.createStack(context, anonymizerStackName, "operations/alb-access-logs-anonymizer.yaml", new Parameter().withParameterKey("ParentS3Stack").withParameterValue(s3StackName));
            final String functionARN = this.getStackOutputValue(anonymizerStackName, "FunctionARN");
            this.updateStack(context, s3StackName, "state/s3.yaml", new Parameter().withParameterKey("Access").withParameterValue("CloudFrontAccessLogWrite"), new Parameter().withParameterKey("LambdaFunctionArn").withParameterValue(functionARN));
        // TODO upload file and test if IP addresses are anonymized
        } finally {
            this.deleteStack(context, anonymizerStackName);
        }
    } finally {
        this.deleteStack(context, s3StackName);
    }
}
Also used : Context(de.widdix.awscftemplates.Context) Parameter(com.amazonaws.services.cloudformation.model.Parameter) ACloudFormationTest(de.widdix.awscftemplates.ACloudFormationTest) Test(org.junit.Test)

Example 10 with Context

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

the class TestKmsKey method test.

@Test
public void test() {
    final Context context = new Context();
    final String stackName = "kms-key-" + this.random8String();
    try {
        this.createStack(context, stackName, "security/kms-key.yaml");
    // TODO how can we check if this stack works?
    } finally {
        this.deleteStack(context, stackName);
    }
}
Also used : Context(de.widdix.awscftemplates.Context) 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