Search in sources :

Example 71 with Parameter

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

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

Example 72 with Parameter

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

the class TestAL2MutablePublic method testWithIAMUserSSHAccess.

@Test
public void testWithIAMUserSSHAccess() throws Exception {
    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 userName = "user-" + this.random8String();
    try {
        final User user = this.createUser(userName);
        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("IAMUserSSHAccess").withParameterValue("true"));
                final String host = this.getStackOutputValue(stackName, "PublicIPAddress");
                this.probeSSH(context, host, user);
            } finally {
                this.deleteStack(context, stackName);
            }
        } finally {
            this.deleteStack(context, vpcStackName);
        }
    } finally {
        this.deleteUser(context, userName);
    }
}
Also used : Context(de.widdix.awscftemplates.Context) Parameter(com.amazonaws.services.cloudformation.model.Parameter) ACloudFormationTest(de.widdix.awscftemplates.ACloudFormationTest) Test(org.junit.Test)

Example 73 with Parameter

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

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

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

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