github.com/darmach/terratest@v0.34.8-0.20210517103231-80931f95e3ff/examples/terraform-ssh-password-example/README.md (about) 1 # Terraform SSH Password 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/) with a public IP in the AWS region specified in the `aws_region` variable. The 6 EC2 Instance allows SSH requests on the port specified by the `ssh_port` variable, and is configured with a user data 7 script so that it will accept passwords for authentication. 8 9 Please note that the Terraform deployment outlined in 10 [the example directory for this test](/examples/terraform-ssh-password-example) will expect a default VPC to exist in 11 the target region for deployments to go into. 12 13 If this default VPC has been deleted from your AWS account, it can be recreated with the following command: 14 15 ``` shell 16 $ aws ec2 create-default-vpc --region eu-west-2 17 { 18 "Vpc": { 19 "CidrBlock": "172.31.0.0/16", 20 "InstanceTenancy": "default", 21 "IsDefault": true, 22 "State": "pending", 23 ... 24 ``` 25 26 Check out [test/terraform_ssh_password_example_test.go](/test/terraform_ssh_password_example_test.go) to see how you 27 can write automated tests for this module. 28 29 Note that the example in this module is still fairly simplified, as the EC2 Instance doesn't do a whole lot! For a more 30 complicated, real-world, end-to-end example of a Terraform module and web server, see 31 [terraform-packer-example](/examples/terraform-packer-example). 32 33 **WARNING**: This module and the automated tests for it deploy real resources into your AWS account which can cost you 34 money. The resources are all part of the [AWS Free Tier](https://aws.amazon.com/free/), so if you haven't used that up, 35 it should be free, but you are completely responsible for all AWS charges. 36 37 ## Running this module manually 38 39 1. Sign up for [AWS](https://aws.amazon.com/). 40 1. Configure your AWS credentials using one of the [supported methods for AWS CLI 41 tools](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html), such as setting the 42 `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". 43 1. Install [Terraform](https://www.terraform.io/) and make sure it's on your `PATH`. 44 1. Run `terraform init`. 45 1. Run `terraform apply`. 46 1. When you're done, run `terraform destroy`. 47 48 ## Running automated tests against this module 49 50 1. Sign up for [AWS](https://aws.amazon.com/). 51 1. Configure your AWS credentials using one of the [supported methods for AWS CLI 52 tools](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html), such as setting the 53 `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". 54 1. Install [Terraform](https://www.terraform.io/) and make sure it's on your `PATH`. 55 1. Install [Golang](https://golang.org/) and make sure this code is checked out into your `GOPATH`. 56 1. `cd test` 57 1. `dep ensure` 58 1. `go test -v -run TestTerraformSshPasswordExample`