Terraform AWS EC2 & S3 Deployment with IAC Testing using Terratest, and Github Actions for Code Validation
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 S3
Bucket - and an EC2 Instance. This module gives both Bucket and Instance a Name
& Owner
tag with the value
specified as Flugel
and InfraTeam
, respectively. This module also contains a terraform variable
that will create a basic bucket policy that will restrict the "origin" bucket to only accept SSL connections.
Note that the S3 Buckets in this module will not contain any actual objects/files after creation; they will only contain a versioning and logging configuration, as well as tags.
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". - Set the AWS region you want to use as the environment variable
AWS_DEFAULT_REGION
. - Install Terraform and make sure it's on your
PATH
. - Run
terraform init
. - Run
terraform apply
. - 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
go mod init github.com/bobaddey/Terraform-test-using-terratest .
go mod tidy
go test -v -run TestTerraformAwsS3Example
go test -v -run estTerraformAwsHelloWorldExample
T