From 4919faf27b58287d5c6e7b28be48f9e565a3ac19 Mon Sep 17 00:00:00 2001 From: David Bishop Date: Tue, 3 Feb 2015 11:03:39 -0500 Subject: [PATCH] add testing, update README and CHANGELOG --- .travis.yml | 5 ++ CHANGELOG.md | 7 +- Makefile | 6 +- README.md | 2 +- scripts/testPlan | 42 ++++++++++ terraform.tfvars.example | 7 ++ test-fixtures/terraform.testplan | 136 +++++++++++++++++++++++++++++++ 7 files changed, 202 insertions(+), 3 deletions(-) create mode 100644 .travis.yml create mode 100755 scripts/testPlan create mode 100644 test-fixtures/terraform.testplan diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..28ee89b --- /dev/null +++ b/.travis.yml @@ -0,0 +1,5 @@ +language: c +before_install: + - wget https://dl.dropboxusercontent.com/u/1917556/terraform.tgz -O /tmp/terraform.tgz + - sudo tar -C /usr/local -zxf /tmp/terraform.tgz +script: make test diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e1d30e..16f7b23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ -## 0.1.0 +Change Log +========== + +v0.1.0 +----- - Initial release. - Setup a VPC with public and private subnets. - Add NAT and bastion instances with appropriate security groups. +- Add testing [v0.1.1] diff --git a/Makefile b/Makefile index 3085102..60710ce 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ all: plan apply plan: terraform get -update - terraform plan -var-file terraform.tfvars -out terraform.tfplan + terraform plan -module-depth=-1 -var-file terraform.tfvars -out terraform.tfplan apply: terraform apply -var-file terraform.tfvars @@ -16,3 +16,7 @@ destroy: clean: rm -f terraform.tfplan rm -f terraform.tfstate + rm -fR .terraform/ + +test: + ./scripts/testPlan diff --git a/README.md b/README.md index fc4e319..2253b02 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ NOTE: **If you are looking to deploy Cloud Foundry into AWS VPC, visit https://g This repository is a submodule of the project above that aims to create one click deploy for Cloud Foundry on AWS VPC. You *probably* don't want to use this repo directly. -This terraform module creates a VPC, a set of public/private subnets and a NAT for outbound traffic. +This terraform module creates the networks and security groups that are needed to deploy CloudFoundry within an existing VPC (specifically, a VPC that was created using [https://github.com/cloudfoundry-community/terraform-aws-vpc], but any VPC will do). Architecture ------------ diff --git a/scripts/testPlan b/scripts/testPlan new file mode 100755 index 0000000..39ea447 --- /dev/null +++ b/scripts/testPlan @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +exitcode=0 +TFILE=`mktemp` +GREEN="\e[1;34m" +RED="\e[0;31m" +RESET="\e[0m" + +# $1 = exit code (will exit testing if non-zero) +# $2 = description of the test +# $3 = output of the test +CLEANUP () { + rm -f $TFILE + if [ $1 -ne 0 ]; then + echo -e "$RED test '$2' failed: $RESET\n $3" + exit $1 + fi +} + +# Pre-testing cleanup +rm -fR .terraform/modules/ + +desc="Can we find the terraform binary?" +OUTPUT=$(which terraform) +CLEANUP "$?" "$desc" "Couldn't find terraform. Is it in your PATH?" + +desc="Can we fetch the dependencies?" +OUTPUT=$(terraform get -update) +CLEANUP "$?" "$desc" "Unable to fetch the modules we depend on" + +desc="Does the plan compile?" +OUTPUT=$(terraform plan -var-file terraform.tfvars.example) +CLEANUP "$?" "$desc" "$OUTPUT" + +desc="Did the baseline terraform plan change?" +terraform plan -var-file terraform.tfvars.example &> $TFILE +OUTPUT=$(diff test-fixtures/terraform.testplan $TFILE) +CLEANUP "$?" "$desc" "$OUTPUT" + +# If we got here, all the tests passed +echo -e "$GREEN All tests passed $RESET" +exit 0 diff --git a/terraform.tfvars.example b/terraform.tfvars.example index 7fb8f2b..22b1f5f 100644 --- a/terraform.tfvars.example +++ b/terraform.tfvars.example @@ -4,3 +4,10 @@ aws_key_path = "~/.ssh/bosh.pem" aws_key_name = "bosh" aws_region = "us-east-1" network = "10.10" + +# These most often come from terraform-aws-vpc, but can be manually set +# if you don't want to or can't use that module. +aws_route_table_private_id = "X" +aws_internet_gateway_id = "X" +aws_route_table_public_id = "X" +aws_vpc_id = "X" diff --git a/test-fixtures/terraform.testplan b/test-fixtures/terraform.testplan new file mode 100644 index 0000000..64a5ef3 --- /dev/null +++ b/test-fixtures/terraform.testplan @@ -0,0 +1,136 @@ +Refreshing Terraform state prior to plan... + + +The Terraform execution plan has been generated and is shown below. +Resources are shown in alphabetical order for quick scanning. Green resources +will be created (or destroyed and then created if an existing resource +exists), yellow resources are being changed in-place, and red resources +will be destroyed. + +Note: You didn't specify an "-out" parameter to save this plan, so when +"apply" is called, Terraform can't guarantee this is what will execute. + ++ aws_eip.cf + allocation_id: "" => "" + association_id: "" => "" + domain: "" => "" + private_ip: "" => "" + public_ip: "" => "" + vpc: "" => "1" + ++ aws_route_table.public + route.#: "" => "1" + route.3901018052.cidr_block: "" => "0.0.0.0/0" + route.3901018052.gateway_id: "" => "X" + route.3901018052.instance_id: "" => "" + tags.#: "" => "" + vpc_id: "" => "X" + ++ aws_route_table_association.cfruntime-2a-private + route_table_id: "" => "X" + subnet_id: "" => "${aws_subnet.cfruntime-2a.id}" + ++ aws_route_table_association.cfruntime-2b-private + route_table_id: "" => "X" + subnet_id: "" => "${aws_subnet.cfruntime-2b.id}" + ++ aws_route_table_association.docker + route_table_id: "" => "X" + subnet_id: "" => "${aws_subnet.docker.id}" + ++ aws_route_table_association.lb-public + route_table_id: "" => "X" + subnet_id: "" => "${aws_subnet.lb.id}" + ++ aws_security_group.cf + description: "" => "CF security groups" + ingress.#: "" => "8" + ingress.1325011704.cidr_blocks.#: "" => "1" + ingress.1325011704.cidr_blocks.0: "" => "0.0.0.0/0" + ingress.1325011704.from_port: "" => "4443" + ingress.1325011704.protocol: "" => "tcp" + ingress.1325011704.security_groups.#: "" => "0" + ingress.1325011704.self: "" => "0" + ingress.1325011704.to_port: "" => "4443" + ingress.1663094005.cidr_blocks.#: "" => "0" + ingress.1663094005.from_port: "" => "0" + ingress.1663094005.protocol: "" => "udp" + ingress.1663094005.security_groups.#: "" => "0" + ingress.1663094005.self: "" => "1" + ingress.1663094005.to_port: "" => "65535" + ingress.219953956.cidr_blocks.#: "" => "1" + ingress.219953956.cidr_blocks.0: "" => "0.0.0.0/0" + ingress.219953956.from_port: "" => "22" + ingress.219953956.protocol: "" => "tcp" + ingress.219953956.security_groups.#: "" => "0" + ingress.219953956.self: "" => "0" + ingress.219953956.to_port: "" => "22" + ingress.2261450965.cidr_blocks.#: "" => "1" + ingress.2261450965.cidr_blocks.0: "" => "0.0.0.0/0" + ingress.2261450965.from_port: "" => "4222" + ingress.2261450965.protocol: "" => "tcp" + ingress.2261450965.security_groups.#: "" => "0" + ingress.2261450965.self: "" => "0" + ingress.2261450965.to_port: "" => "25777" + ingress.2603706321.cidr_blocks.#: "" => "1" + ingress.2603706321.cidr_blocks.0: "" => "0.0.0.0/0" + ingress.2603706321.from_port: "" => "80" + ingress.2603706321.protocol: "" => "tcp" + ingress.2603706321.security_groups.#: "" => "0" + ingress.2603706321.self: "" => "0" + ingress.2603706321.to_port: "" => "80" + ingress.32090245.cidr_blocks.#: "" => "1" + ingress.32090245.cidr_blocks.0: "" => "0.0.0.0/0" + ingress.32090245.from_port: "" => "-1" + ingress.32090245.protocol: "" => "icmp" + ingress.32090245.security_groups.#: "" => "0" + ingress.32090245.self: "" => "0" + ingress.32090245.to_port: "" => "-1" + ingress.3738418453.cidr_blocks.#: "" => "0" + ingress.3738418453.from_port: "" => "0" + ingress.3738418453.protocol: "" => "tcp" + ingress.3738418453.security_groups.#: "" => "0" + ingress.3738418453.self: "" => "1" + ingress.3738418453.to_port: "" => "65535" + ingress.4089093546.cidr_blocks.#: "" => "1" + ingress.4089093546.cidr_blocks.0: "" => "0.0.0.0/0" + ingress.4089093546.from_port: "" => "443" + ingress.4089093546.protocol: "" => "tcp" + ingress.4089093546.security_groups.#: "" => "0" + ingress.4089093546.self: "" => "0" + ingress.4089093546.to_port: "" => "443" + name: "" => "cf-0-X" + owner_id: "" => "" + tags.#: "" => "1" + tags.Name: "" => "cf-0-X" + vpc_id: "" => "X" + ++ aws_subnet.cfruntime-2a + availability_zone: "" => "" + cidr_block: "" => "10.10.03.0/24" + tags.#: "" => "1" + tags.Name: "" => "cf1" + vpc_id: "" => "X" + ++ aws_subnet.cfruntime-2b + availability_zone: "" => "us-west-2a" + cidr_block: "" => "10.10.04.0/24" + tags.#: "" => "1" + tags.Name: "" => "cf2" + vpc_id: "" => "X" + ++ aws_subnet.docker + availability_zone: "" => "us-west-2a" + cidr_block: "" => "10.10.05.0/24" + tags.#: "" => "1" + tags.Name: "" => "docker" + vpc_id: "" => "X" + ++ aws_subnet.lb + availability_zone: "" => "us-west-2a" + cidr_block: "" => "10.10.02.0/24" + tags.#: "" => "1" + tags.Name: "" => "lb" + vpc_id: "" => "X" + +