Image auto-generated using the dancing gopher web server.
Credit: Valentin Deleplace
This folder contains an example Terraform configuration that deploys a simple Golang "Hello, World" application across a cluster of web servers (using EC2 and Auto Scaling in an Amazon Web Services (AWS) account.
This project will deploy the following AWS resources.
- Elastic Load Balancer (Also known as the Classic Load Balancer)
- Auto Scaling groups
- 2 x EC2 instances of Amazon Linux 2
- Security Groups for the Classic Load Balancer
- Security Groups for the EC2 instances
💡 Below are links to the examples and tests included in this repo.
- Complete Example - A complete example of the "Hello, World!" web app being deployed with all of the resources listed above.
- Test - Automatically deploy the example above, see if the ELB returns "Hello, World!", and then destroy the deployed resources.
main.tf
utilizes my two custom Terraform modules. These modules should be pinned to v1.0.0
.
Name | Version |
---|---|
smithlabs/terraform-aws-asg-rolling-deploy | v1.0.0 |
smithlabs/terraform-aws-elb | v1.0.0 |
Here is where these modules are used in main.tf
.
- You must have Terraform installed on your computer.
- You must have an Amazon Web Services (AWS) account.
- (Optional) - AWS CLI v2 is recommended if you want to deploy Terraform code using multiple AWS credentials.
Please note that this code was written for Terraform 0.13.x.
Name | Version |
---|---|
terraform | >= 0.13.0 |
aws | >= 2.35 |
Please note that this example will deploy real resources into your AWS account. We have made every effort to ensure all the resources qualify for the AWS Free Tier, but we are not responsible for any charges you may incur.
Configure your AWS access keys as environment variables:
export AWS_ACCESS_KEY_ID=(your access key id)
export AWS_SECRET_ACCESS_KEY=(your secret access key)
Deploy the code:
terraform init
terraform apply
When the apply
command completes, it will output the DNS name of the load balancer. To test the load balancer:
curl http://<elb_dns_name>/
Clean up when you're done:
terraform destroy
Name | Description | Type | Default | Required |
---|---|---|---|---|
environment | The environment name to add to the auto scaling group and ELB resources. | string |
test |
no |
name | The name to prepend to the auto scaling group and ELB resources. | string |
hello-world |
no |
server_port | The port the server will use for HTTP requests. | number |
8080 |
no |
Name | Description |
---|---|
elb_dns_name | The DNS name for the Elastic Load Balancer |
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests and examples as appropriate.
Please ⭐️ this repository if this project helped you!
- EmojiTerra - Copy and paste emojis into your README