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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations