github.com/darmach/terratest@v0.34.8-0.20210517103231-80931f95e3ff/examples/terraform-http-example/README.md (about) 1 # Terraform HTTP Example 2 3 This folder contains a simple Terraform module that deploys resources in [AWS](https://aws.amazon.com/) to demonstrate 4 how you can use Terratest to write automated tests for your AWS Terraform code. This module deploys an [EC2 5 Instance](https://aws.amazon.com/ec2/) in the AWS region specified in the `aws_region` variable. The EC2 Instance runs 6 a simple web server that listens for HTTP requests on the port specified by the `instance_port` variable and returns 7 the text specified by the `instance_text` variable. 8 9 Check out [test/terraform_http_example_test.go](/test/terraform_http_example_test.go) to see how you can write 10 automated tests for this module. 11 12 Note that the example in this module is still fairly simplified, as the "web server" we run just servers up a static 13 `index.html`, and not in a particularly production-ready manner! For a more complicated, real-world, end-to-end 14 example of a Terraform module and web server, see [terraform-packer-example](/examples/terraform-packer-example). 15 16 **WARNING**: This module and the automated tests for it deploy real resources into your AWS account which can cost you 17 money. The resources are all part of the [AWS Free Tier](https://aws.amazon.com/free/), so if you haven't used that up, 18 it should be free, but you are completely responsible for all AWS charges. 19 20 21 22 23 24 ## Running this module manually 25 26 1. Sign up for [AWS](https://aws.amazon.com/). 27 1. Configure your AWS credentials using one of the [supported methods for AWS CLI 28 tools](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html), such as setting the 29 `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environment variables. If you're using the `~/.aws/config` file for profiles then export `AWS_SDK_LOAD_CONFIG` as "True". 30 1. Install [Terraform](https://www.terraform.io/) and make sure it's on your `PATH`. 31 1. Run `terraform init`. 32 1. Run `terraform apply`. 33 1. The `instance_url` output variable shows you the URL of the web server. Try opening it in your browser! 34 1. When you're done, run `terraform destroy`. 35 36 37 38 39 ## Running automated tests against this module 40 41 1. Sign up for [AWS](https://aws.amazon.com/). 42 1. Configure your AWS credentials using one of the [supported methods for AWS CLI 43 tools](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html), such as setting the 44 `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environment variables. If you're using the `~/.aws/config` file for profiles then export `AWS_SDK_LOAD_CONFIG` as "True". 45 1. Install [Terraform](https://www.terraform.io/) and make sure it's on your `PATH`. 46 1. Install [Golang](https://golang.org/) and make sure this code is checked out into your `GOPATH`. 47 1. `cd test` 48 1. `dep ensure` 49 1. `go test -v -run TestTerraformHttpExample`