by LazyMans · 4y ago · 0 comments
It sounds like a lot, but it ends up being fewer files to manage and edit and your workflow can be captured in github/terraform rather than in some arbitrary file structure. It also helps prevent mistakes like updating dev and having prod rerun by accident which I've seen happen.
Exactly this. In $previous_client we had `snowflake_*.tf` files. Anything that couldn't be specialised using Terraform variable files should go on those. One advantage was that we started finding things that should be commoditised to get rid of the snowflakes. Everything else was very obviously out of shape and seen as generally undesirable - although many times necessary.
> control the creation or non-creation ENTIRELY thru env vars with either boolean or count.
I would also highly discourage this. Counts for different scales across environments, sure. Counts or bools to decide whether or not to deploy something depending on the environment are discouraged and should become a snowflake.
Workspaces:
- PROD-us-east-1-All-the-VPC-stuff
- NAT count = 3
- PROD-us-west-2-All-the-VPC-stuff - NAT count = 3
- PROD-us-east-1-Enterprise-Network-Tool - var instance count = 2
- PROD-us-west-2-Enterprise-Network-Tool - var instance count = 2
- STAGE-All-the-VPC-stuff (us-east-1) - NAT count = 3
- STAGE-Enterprise-Network-Tool (us-east-1) - var instance count = 1
- DEV-All-the-VPC-stuff (us-east-1) - NAT count = 0 (maybe since we don't have the network tool we're transit vpcing or something else in dev)
It's a little contrived but the idea is that normally workspaces align to these borders:- Env
- Cloud region (not always -- and the cross region ones are usually called out)
- Loosely de-coupled app border
Workspaces provide really easy "manholes" for servicing your IaC quickly when there's a mistake. They don't encourage you to manually change resources, but rather work in a smaller area and reduce blast radius. The issue I see with a lot of teams is when they're not sure how to handle cross-stack references or what they should output. I think that's an area for training and leveling up in TF.
> The issue I see with a lot of teams is when they're not sure how to handle cross-stack references or what they should output.
Very much agree. What I try to do as much as possible these days is to not cross-reference. I find terraform remote state resources a code smell. Data sources are a better way to go. No code coupling and no terraform versioning dependencies between stacks.