DoSomething / infrastructure

🐄 DoSomething.org's infrastructure, managed by Terraform.
MIT License
3 stars 2 forks source link

Split into multiple Terraform workspaces. #225

Closed DFurnes closed 4 years ago

DFurnes commented 4 years ago

What's this PR do?

This pull request splits our current "monolithic" Terraform state into separate workspaces, which lets us safely apply changes to environments selectively (for example, testing a change to a shared module in dosomething-dev before applying in production).

This splits our single infrastructure workspace into 9 independent workspaces:

I have not updated the three dosomething- modules to import the pipeline variable from the shared pipeline yet, just to keep this a bit more contained (instead, these are just a variable for each workspace with the Pipeline ID).

How should this be reviewed?

Yikes!!! 🐳 This is not quite as overwhelming as it looks – the bulk of the diff comes from moving files that were referenced outside of the "module path" into each module where they're referenced (since you can't just grab files recklessly between workspaces anymore).

The other big change is moving backend & provider configuration into each module (e.g. from the single main top-level module into dosomething, dosomething-qa, etc). This is nice since it means we can test newer provider versions on dev/QA before using on production!

If you click to expand the "checks" at the bottom of this PR, you can see that this introduces no new changes:

Screen Shot 2020-01-24 at 2 59 48 PM

Any background context you want to provide?

Moving resources between workspaces is incredibly awkward (hopefully improvements are on the Terraform roadmap!): you can either terraform import each one from scratch, or you can terraform state pull the state down to a file & terraform state mv each resource into a "fresh" state file that you can then terraform state push to the new workspace.

I opted for the second approach, but it was still way more tedious than I'd have expected!

Relevant tickets

References Pivotal #170776057.

Checklist