Search in sources :

Example 16 with Context

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

the class TestFargateCluster method test.

@Test
public void test() {
    final Context context = new Context();
    final String vpcStackName = "vpc-2azs-" + this.random8String();
    final String stackName = "fargate-cluster-" + 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, stackName, "fargate/cluster.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName));
        } finally {
            this.deleteStack(context, stackName);
        }
    } 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 17 with Context

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

the class TestJenkins method testHA.

@Test
public void testHA() {
    final Context context = new Context();
    final String vpcStackName = "vpc-2azs-" + this.random8String();
    final String stackName = "jenkins-ha-" + this.random8String();
    final String classB = "10";
    final String keyName = "key-" + this.random8String();
    final String masterAdminPassword = 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, stackName, "jenkins/jenkins2-ha.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName), new Parameter().withParameterKey("MasterInstanceType").withParameterValue("t3a.small"), new Parameter().withParameterKey("KeyName").withParameterValue(keyName), new Parameter().withParameterKey("MasterAdminPassword").withParameterValue(masterAdminPassword), new Parameter().withParameterKey("EFSBackupRetentionPeriod").withParameterValue("0"));
                final String url = this.getStackOutputValue(stackName, "URL");
                final Callable<String> callable = () -> {
                    final HttpResponse response = WS.url(url).authBasic("admin", masterAdminPassword).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 Jenkins appears in HTML
                Assert.assertTrue("http response body contains \"Jenkins\"", response.contains("Jenkins"));
            } finally {
                this.deleteStack(context, stackName);
            }
        } 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 18 with Context

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

the class TestJenkins method testHAAgents.

@Test
public void testHAAgents() {
    final Context context = new Context();
    final String vpcStackName = "vpc-2azs-" + this.random8String();
    final String stackName = "jenkins-ha-agents-" + this.random8String();
    final String classB = "10";
    final String keyName = "key-" + this.random8String();
    final String masterAdminPassword = 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, stackName, "jenkins/jenkins2-ha-agents.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName), new Parameter().withParameterKey("MasterInstanceType").withParameterValue("t3a.small"), new Parameter().withParameterKey("KeyName").withParameterValue(keyName), new Parameter().withParameterKey("MasterAdminPassword").withParameterValue(masterAdminPassword), new Parameter().withParameterKey("EFSBackupRetentionPeriod").withParameterValue("0"));
                final String url = this.getStackOutputValue(stackName, "URL");
                final Callable<String> callable = () -> {
                    final HttpResponse response = WS.url(url).authBasic("admin", masterAdminPassword).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 Jenkins appears in HTML
                Assert.assertTrue("http response body contains \"Jenkins\"", response.contains("Jenkins"));
            } finally {
                this.deleteStack(context, stackName);
            }
        } 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 19 with Context

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

the class TestRDSAuroraServerless 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-" + 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.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)

Example 20 with Context

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

the class TestRDSMySQL method testWithSecret.

@Test
public void testWithSecret() {
    final Context context = new Context();
    final String vpcStackName = "vpc-2azs-" + this.random8String();
    final String clientStackName = "client-" + this.random8String();
    final String secretStackName = "secret-" + this.random8String();
    final String stackName = "rds-mysql-" + 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, secretStackName, "state/secretsmanager-dbsecret.yaml");
                try {
                    this.createStack(context, stackName, "state/rds-mysql.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName), new Parameter().withParameterKey("ParentClientStack").withParameterValue(clientStackName), new Parameter().withParameterKey("ParentSecretStack").withParameterValue(secretStackName), new Parameter().withParameterKey("DBName").withParameterValue("db1"));
                // 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, secretStackName);
            }
        } 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