This folder contains a simple Terraform module that deploys resources in AWS to demonstrate
how you can use Terratest to write automated tests for your AWS Terraform code. This module deploys an EC2
Instance in the AWS region specified in the aws_region
variable. The EC2 Instance runs
a simple web server that listens for HTTP requests on the port specified by the instance_port
variable and returns
the text specified by the instance_text
variable.
Check out test/terraform_http_example_test.go to see how you can write automated tests for this module.
Note that the example in this module is still fairly simplified, as the "web server" we run just servers up a static
index.html
, and not in a particularly production-ready manner! For a more complicated, real-world, end-to-end
example of a Terraform module and web server, see terraform-packer-example.
WARNING: This module and the automated tests for it deploy real resources into your AWS account which can cost you money. The resources are all part of the AWS Free Tier, so if you haven't used that up, it should be free, but you are completely responsible for all AWS charges.
- Sign up for AWS.
- Configure your AWS credentials using one of the supported methods for AWS CLI
tools, such as setting the
AWS_ACCESS_KEY_ID
andAWS_SECRET_ACCESS_KEY
environment variables. If you're using the~/.aws/config
file for profiles then exportAWS_SDK_LOAD_CONFIG
as "True". - Install Terraform and make sure it's on your
PATH
. - Run
terraform init
. - Run
terraform apply
. - The
instance_url
output variable shows you the URL of the web server. Try opening it in your browser! - When you're done, run
terraform destroy
.
- Sign up for AWS.
- Configure your AWS credentials using one of the supported methods for AWS CLI
tools, such as setting the
AWS_ACCESS_KEY_ID
andAWS_SECRET_ACCESS_KEY
environment variables. If you're using the~/.aws/config
file for profiles then exportAWS_SDK_LOAD_CONFIG
as "True". - Install Terraform and make sure it's on your
PATH
. - Install Golang and make sure this code is checked out into your
GOPATH
. cd test
dep ensure
go test -v -run TestTerraformHttpExample