Search in sources :

Example 76 with Parameter

use of com.amazonaws.services.cloudformation.model.Parameter 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 77 with Parameter

use of com.amazonaws.services.cloudformation.model.Parameter 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)

Example 78 with Parameter

use of com.amazonaws.services.cloudformation.model.Parameter in project aws-cf-templates by widdix.

the class TestDocumentDB 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 = "documentdb-" + 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 {
                try {
                    this.createStack(context, secretStackName, "state/secretsmanager-dbsecret.yaml");
                    this.createStack(context, stackName, "state/documentdb.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName), new Parameter().withParameterKey("ParentClientStack").withParameterValue(clientStackName), new Parameter().withParameterKey("ParentSecretStack").withParameterValue(secretStackName));
                // 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)

Example 79 with Parameter

use of com.amazonaws.services.cloudformation.model.Parameter in project aws-cf-templates by widdix.

the class TestElasticsearch 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 = "elasticsearch-" + 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/elasticsearch.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName), new Parameter().withParameterKey("ParentClientStack").withParameterValue(clientStackName), new Parameter().withParameterKey("DomainName").withParameterValue(stackName));
            // 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 80 with Parameter

use of com.amazonaws.services.cloudformation.model.Parameter in project aws-cf-templates by widdix.

the class TestWordpressHA method testAurora.

@Test
public void testAurora() {
    final Context context = new Context();
    final String zoneStackName = "zone-" + this.random8String();
    final String vpcStackName = "vpc-3azs-" + this.random8String();
    final String stackName = "wordpress-ha-aurora-" + this.random8String();
    final String classB = "10";
    final String keyName = "key-" + this.random8String();
    final String subDomainName = stackName;
    final String blogTitle = "Stay-AWSome";
    final String blogPassword = this.random8String();
    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-3azs.yaml", new Parameter().withParameterKey("ClassB").withParameterValue(classB));
                try {
                    this.createStack(context, stackName, "wordpress/wordpress-ha-aurora.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName), new Parameter().withParameterKey("ParentZoneStack").withParameterValue(zoneStackName), new Parameter().withParameterKey("WebServerKeyName").withParameterValue(keyName), new Parameter().withParameterKey("SubDomainNameWithDot").withParameterValue(subDomainName + "."), new Parameter().withParameterKey("CloudFrontAcmCertificate").withParameterValue(Config.get(Config.Key.CLOUDFRONT_ACM_CERTIFICATE_ARN)), new Parameter().withParameterKey("ElbAcmCertificate").withParameterValue(Config.get(Config.Key.ACM_CERTIFICATE_ARN)), new Parameter().withParameterKey("BlogTitle").withParameterValue(blogTitle), new Parameter().withParameterKey("BlogAdminUsername").withParameterValue("admin"), new Parameter().withParameterKey("BlogAdminPassword").withParameterValue(blogPassword), new Parameter().withParameterKey("BlogAdminEMail").withParameterValue("no-reply@widdix.de"), new Parameter().withParameterKey("EFSBackupRetentionPeriod").withParameterValue("0"));
                    final String url = "https://" + subDomainName + "." + Config.get(Config.Key.DOMAIN_SUFFIX);
                    final Callable<Boolean> 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));
                        }
                        if (!WS.getResponseAsString(response).contains(blogTitle)) {
                            throw new RuntimeException("http response body contains \"" + blogTitle + "\"");
                        }
                        return true;
                    };
                    Assert.assertTrue("WordPress ready", this.retry(context, callable));
                } finally {
                    this.deleteStackAndRetryOnFailure(context, stackName);
                }
            } 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)

Aggregations

Parameter (com.amazonaws.services.cloudformation.model.Parameter)85 Test (org.junit.Test)79 Context (de.widdix.awscftemplates.Context)66 ACloudFormationTest (de.widdix.awscftemplates.ACloudFormationTest)60 HttpResponse (org.apache.http.HttpResponse)19 KeyPair (com.amazonaws.services.ec2.model.KeyPair)5 StringInputStream (com.amazonaws.util.StringInputStream)4 ArrayList (java.util.ArrayList)4 DescribeContainerInstancesRequest (com.amazonaws.services.ecs.model.DescribeContainerInstancesRequest)3 DescribeContainerInstancesResult (com.amazonaws.services.ecs.model.DescribeContainerInstancesResult)3 ListContainerInstancesRequest (com.amazonaws.services.ecs.model.ListContainerInstancesRequest)3 ListContainerInstancesResult (com.amazonaws.services.ecs.model.ListContainerInstancesResult)3 ParameterProvider (de.taimos.pipeline.aws.cloudformation.ParameterProvider)3 FilePath (hudson.FilePath)3 AmazonCloudFormation (com.amazonaws.services.cloudformation.AmazonCloudFormation)2 TaskListener (hudson.model.TaskListener)2 CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)2 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 Change (com.amazonaws.services.cloudformation.model.Change)1