Demo Infrastructure as Code for Cloud Talk series
This project demonstrates Infrastructure as Code principles using Terraform and Salt. The Terraform modules will create and manage the following resources:
- IAM Instance Role
- S3 Bucket
- Application Load Balancer
- Security Groups (1 for the load balancer and 1 for EC2 instances)
- Autoscaling Group and Launch Config
Salt is used within the EC2 instances (deployed by the Autscaling Group) to install and configure an Apache web server. The web server will serve cat or dog images from the S3 bucket. One Availability Zone will be designated as the "cats AZ", and any EC2 instance running in that AZ will only serve cat images. Instances in any other AZ will serve only dog images. This is intended to help demonstrate the failover and recovery capabilities of the architecture.
-
Create a
main.auto.tfvars
file in themain
module. Seemain/variables.tf
for the required and optional variables. This file is ignored intentionally by source control so it is not committed to the project. -
The first time the project is deployed, execute the following
make
targets in the listed order. For subsequent executions, execute the targets as needed depending on the changes being evaluated. See [Make Targets][#make-targets] for more info on the available targets.make test
make apply/iam
make apply/bucket
make apply/main
All resources are deployed using Terraform. The project consists of 3 Terraform modules:
- iam
- Manages the IAM Instance Role
- bucket
- Manages the S3 bucket
- main
- Manages all other resources, including the objects in the S3 bucket
- Utilizes the
lx-autoscale
module fromterraform-aws-watchmaker
NOTE: The
iam
andbucket
modules must be deployed first, as their resources must exist when themain
module is deployed.
There is a Makefile
that helps manage the project workflow.. The following
make
targets are supported:
make test
- Runs
terraform fmt
to standardize format of all Terraform files. - Runs
terraform validate
on all modules to check for syntax errors.
- Runs
make <tf_command>/<module>
- Executes the
<tf_command>
in the specified<module>
. The commandinit
supports an additional argumentupgrade=<true|false (default)>
, which controls whether to force terraform to re-download all providers and modules (seeterraform init -help
).
- Executes the
make <tf_command>/all
- Executes the
<tf_command>
in all Terraform modules. This target does not account for dependencies between modules, so should not be used forplan
,apply
, ordestroy
commands.init
andvalidate
are safe.
- Executes the