Search in sources :

Example 31 with Context

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

the class TestConfig method test.

@Ignore
// this test is disabled because only one ConfigurationRecorder is allowed and config is already active in all our AWS accounts
@Test
public void test() {
    final Context context = new Context();
    final String stackName = "config-" + this.random8String();
    final String bucketName = "config-" + this.random8String();
    final String bucketPolicy = "{\n" + "  \"Version\": \"2012-10-17\",\n" + "  \"Statement\": [\n" + "    {\n" + "      \"Sid\": \"AWSConfigBucketPermissionsCheck\",\n" + "      \"Effect\": \"Allow\",\n" + "      \"Principal\": {\n" + "        \"Service\": [\n" + "         \"config.amazonaws.com\"\n" + "        ]\n" + "      },\n" + "      \"Action\": \"s3:GetBucketAcl\",\n" + "      \"Resource\": \"arn:aws:s3:::" + bucketName + "\"\n" + "    },\n" + "    {\n" + "      \"Sid\": \" AWSConfigBucketDelivery\",\n" + "      \"Effect\": \"Allow\",\n" + "      \"Principal\": {\n" + "        \"Service\": [\n" + "         \"config.amazonaws.com\"\n" + "        ]\n" + "      },\n" + "      \"Action\": \"s3:PutObject\",\n" + "      \"Resource\": [\n" + "        \"arn:aws:s3:::" + bucketName + "/AWSLogs/" + this.getAccount() + "/Config/*\"\n" + "      ],\n" + "      \"Condition\": {\n" + "        \"StringEquals\": {\n" + "          \"s3:x-amz-acl\": \"bucket-owner-full-control\"\n" + "        }\n" + "      }\n" + "    }\n" + "  ]\n" + "}";
    try {
        this.createBucket(bucketName, bucketPolicy);
        try {
            this.createStack(context, stackName, "security/config.yaml", new Parameter().withParameterKey("ExternalConfigBucket").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) Ignore(org.junit.Ignore) ACloudFormationTest(de.widdix.awscftemplates.ACloudFormationTest) Test(org.junit.Test)

Example 32 with Context

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

the class TestDynamoDB method testEncryption.

@Test
public void testEncryption() {
    final Context context = new Context();
    final String kmsKeyStackName = "key-" + this.random8String();
    final String stackName = "dynamodb-" + this.random8String();
    try {
        this.createStack(context, kmsKeyStackName, "security/kms-key.yaml");
        try {
            this.createStack(context, stackName, "state/dynamodb.yaml", new Parameter().withParameterKey("ParentKmsKeyStack").withParameterValue(kmsKeyStackName), new Parameter().withParameterKey("PartitionKeyName").withParameterValue("id"), new Parameter().withParameterKey("BackupRetentionPeriod").withParameterValue("0"));
        // TODO how can we check if this stack works?
        } finally {
            this.deleteStack(context, stackName);
        }
    } finally {
        this.deleteStack(context, kmsKeyStackName);
    }
}
Also used : Context(de.widdix.awscftemplates.Context) Parameter(com.amazonaws.services.cloudformation.model.Parameter) ACloudFormationTest(de.widdix.awscftemplates.ACloudFormationTest) Test(org.junit.Test)

Example 33 with Context

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

the class TestRDSAurora method testPostgres.

@Test
public void testPostgres() {
    final Context context = new Context();
    final String vpcStackName = "vpc-2azs-" + this.random8String();
    final String clientStackName = "client-" + this.random8String();
    final String stackName = "rds-aurora-" + this.random8String();
    final String password = this.random8String();
    try {
        this.createStack(context, vpcStackName, "vpc/vpc-2azs.yaml");
        try {
            this.createStack(context, clientStackName, "state/client-sg.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName));
            try {
                this.createStack(context, stackName, "state/rds-aurora.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName), new Parameter().withParameterKey("ParentClientStack").withParameterValue(clientStackName), new Parameter().withParameterKey("Engine").withParameterValue("aurora-postgresql-10.14"), new Parameter().withParameterKey("DBInstanceClass").withParameterValue("db.r4.large"), new Parameter().withParameterKey("DBName").withParameterValue("db1"), new Parameter().withParameterKey("DBMasterUserPassword").withParameterValue(password));
            // TODO how can we check if this stack works? start a bastion host and try to connect?
            } finally {
                this.deleteStack(context, stackName);
            }
        } finally {
            this.deleteStack(context, clientStackName);
        }
    } 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)

Example 34 with Context

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

the class TestRDSAurora method test.

@Test
public void test() {
    final Context context = new Context();
    final String vpcStackName = "vpc-2azs-" + this.random8String();
    final String clientStackName = "client-" + this.random8String();
    final String stackName = "rds-aurora-" + this.random8String();
    final String password = this.random8String();
    try {
        this.createStack(context, vpcStackName, "vpc/vpc-2azs.yaml");
        try {
            this.createStack(context, clientStackName, "state/client-sg.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName));
            try {
                this.createStack(context, stackName, "state/rds-aurora.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName), new Parameter().withParameterKey("ParentClientStack").withParameterValue(clientStackName), new Parameter().withParameterKey("DBName").withParameterValue("db1"), new Parameter().withParameterKey("DBMasterUserPassword").withParameterValue(password));
            // TODO how can we check if this stack works? start a bastion host and try to connect?
            } finally {
                this.deleteStack(context, stackName);
            }
        } finally {
            this.deleteStack(context, clientStackName);
        }
    } 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)

Example 35 with Context

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

the class TestRDSAuroraServerlessPostgres method test.

@Test
public void test() {
    final Context context = new Context();
    final String vpcStackName = "vpc-2azs-" + this.random8String();
    final String clientStackName = "client-" + this.random8String();
    final String kmsKeyStackName = "key-" + this.random8String();
    final String stackName = "rds-aurora-serverless-postgres-" + this.random8String();
    final String password = this.random8String();
    try {
        this.createStack(context, vpcStackName, "vpc/vpc-2azs.yaml");
        try {
            this.createStack(context, clientStackName, "state/client-sg.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName));
            try {
                this.createStack(context, kmsKeyStackName, "security/kms-key.yaml");
                try {
                    this.createStack(context, stackName, "state/rds-aurora-serverless-postgres.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName), new Parameter().withParameterKey("ParentClientStack").withParameterValue(clientStackName), new Parameter().withParameterKey("ParentKmsKeyStack").withParameterValue(kmsKeyStackName), new Parameter().withParameterKey("DBName").withParameterValue("db1"), new Parameter().withParameterKey("DBMasterUserPassword").withParameterValue(password));
                // TODO how can we check if this stack works? start a bastion host and try to connect?
                } finally {
                    this.deleteStack(context, stackName);
                }
            } finally {
                this.deleteStack(context, kmsKeyStackName);
            }
        } finally {
            this.deleteStack(context, clientStackName);
        }
    } 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