Search in sources :

Example 56 with Context

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

the class TestAL2MutablePublic method test.

@Test
public void test() {
    final Context context = new Context();
    final String vpcStackName = "vpc-2azs-" + this.random8String();
    final String stackName = "al2-mutable-public-" + this.random8String();
    final String classB = "10";
    final String keyName = "key-" + this.random8String();
    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, stackName, "ec2/al2-mutable-public.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName), new Parameter().withParameterKey("KeyName").withParameterValue(keyName), new Parameter().withParameterKey("BackupRetentionPeriod").withParameterValue("0"));
                final String host = this.getStackOutputValue(stackName, "PublicIPAddress");
                this.probeSSH(context, host, key);
            } finally {
                this.deleteStack(context, stackName);
            }
        } 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) ACloudFormationTest(de.widdix.awscftemplates.ACloudFormationTest) Test(org.junit.Test)

Example 57 with Context

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

the class TestECSService method testClusterAlbPathPattern.

@Test
public void testClusterAlbPathPattern() {
    final Context context = new Context();
    final String vpcStackName = "vpc-2azs-" + this.random8String();
    final String clusterStackName = "ecs-cluster-" + this.random8String();
    final String stackName = "ecs-service-" + this.random8String();
    final String classB = "10";
    final String keyName = "key-" + this.random8String();
    try {
        this.createKey(keyName);
        try {
            this.createStack(context, vpcStackName, "vpc/vpc-2azs.yaml", new Parameter().withParameterKey("ClassB").withParameterValue(classB));
            try {
                this.createStack(context, clusterStackName, "ecs/cluster.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName), new Parameter().withParameterKey("KeyName").withParameterValue(keyName));
                final String cluster = this.getStackOutputValue(clusterStackName, "Cluster");
                try {
                    this.createStack(context, stackName, "ecs/service-cluster-alb.yaml", new Parameter().withParameterKey("ParentClusterStack").withParameterValue(clusterStackName), new Parameter().withParameterKey("Image").withParameterValue("nginx:1.11.5"));
                    final String url = this.getStackOutputValue(stackName, "URL");
                    final Callable<Boolean> callable = () -> {
                        final HttpResponse response = WS.url(url).timeout(10000).get();
                        // check HTTP response code
                        if (WS.getStatus(response) != 404) {
                            throw new RuntimeException("404 expected, but saw " + WS.getStatus(response));
                        }
                        return true;
                    };
                    Assert.assertTrue("http response code is 404", this.retry(context, callable));
                } finally {
                    this.deleteStack(context, stackName);
                }
            } finally {
                this.deleteStack(context, clusterStackName);
            }
        } finally {
            this.deleteStack(context, vpcStackName);
        }
    } 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 58 with Context

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

the class TestAccessLogsAnonymizer method cloudfront.

@Test
public void cloudfront() {
    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("CloudFrontAccessLogWrite"));
        try {
            this.createStack(context, anonymizerStackName, "operations/cloudfront-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 59 with Context

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

the class TestTerraformState method test.

@Test
public void test() {
    final Context context = new Context();
    final String kmsStackName = "kms-" + this.random8String();
    final String terraformStateStackName = "tf-state-" + this.random8String();
    try {
        this.createStack(context, kmsStackName, "security/kms-key.yaml", new Parameter().withParameterKey("Service").withParameterValue("s3"));
        try {
            this.createStack(context, terraformStateStackName, "operations/terraform-state.yaml", new Parameter().withParameterKey("ParentKmsKeyStack").withParameterValue(kmsStackName), new Parameter().withParameterKey("TerraformStateIdentifier").withParameterValue(terraformStateStackName), new Parameter().withParameterKey("TerraformStateAdminARNs").withParameterValue("arn:aws:iam::" + this.getAccount() + ":root," + System.getenv("IAM_ROLE_ARN") + "," + this.getCallerIdentityArn()));
        } finally {
            this.deleteStack(context, terraformStateStackName);
        }
    } finally {
        this.deleteStack(context, kmsStackName);
    }
}
Also used : Context(de.widdix.awscftemplates.Context) Parameter(com.amazonaws.services.cloudformation.model.Parameter) ACloudFormationTest(de.widdix.awscftemplates.ACloudFormationTest) Test(org.junit.Test)

Example 60 with Context

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

the class TestCloudtrail method test.

@Test
public void test() {
    final Context context = new Context();
    final String stackName = "cloudtrail-" + this.random8String();
    final String bucketName = "cloudtrail-" + this.random8String();
    final String bucketPolicy = "{\n" + "  \"Version\": \"2012-10-17\",\n" + "  \"Statement\": [{\n" + "    \"Sid\": \"AWSCloudTrailAclCheck\",\n" + "    \"Effect\": \"Allow\",\n" + "    \"Principal\": {\n" + "      \"Service\": \"cloudtrail.amazonaws.com\"\n" + "    },\n" + "    \"Action\": \"s3:GetBucketAcl\",\n" + "    \"Resource\": \"arn:aws:s3:::" + bucketName + "\"\n" + "  }, {\n" + "    \"Sid\": \"AWSCloudTrailWrite\",\n" + "    \"Effect\": \"Allow\",\n" + "    \"Principal\": {\n" + "      \"Service\": \"cloudtrail.amazonaws.com\"\n" + "    },\n" + "    \"Action\": \"s3:PutObject\",\n" + "    \"Resource\": [\n" + "      \"arn:aws:s3:::" + bucketName + "/AWSLogs/" + this.getAccount() + "/*\"\n" + "    ],\n" + "    \"Condition\": {\n" + "      \"StringEquals\": {\n" + "        \"s3:x-amz-acl\": \"bucket-owner-full-control\"\n" + "      }\n" + "    }\n" + "  }]\n" + "}";
    try {
        this.createBucket(bucketName, bucketPolicy);
        try {
            this.createStack(context, stackName, "security/cloudtrail.yaml", new Parameter().withParameterKey("ExternalTrailBucket").withParameterValue(bucketName));
        // TODO how can we check if this stack works?
        } finally {
            this.deleteStack(context, stackName);
        }
    } finally {
        this.deleteBucket(context, bucketName);
    }
}
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