Terraform Blue-Green Deploy example
Note: Use Terraform Modules as functions!!!
This will allow you to create a "networking" module, and use those outputs to populate the security groups, access zones, and subnet id's for your other modules.
Using autoscaling groups with a fixed size will protect you from AWs bugs or instance outages. This way an instance that dies, will be replaced so you always maintain the expected amount of instances for that service.
Workflow:
Given that 'blue-ami-id' = 2; green-ami-id = 1; blue-nodes = 3; and green-nodes = 0
- Create a new AMI using Packer (pretend this has an ami-id = 3
- Update green-ami-id to equal 3
- Slowly scale up green-nodes, using green-nodes as a canary for the new service version
- Once health checks (whatever user requires: consul, sensu, nagios, etc) pass
- Slowly scale down blud-nodes to 0.
If everything checks out, you've just rolled instances with Terraform using a Blue-Green deploy!