Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Provisioning customer accounts with Terraform (workspaces, Modules, ?) Best Practice?

I have the need to create and manage multiple customer environments in AWS and I'm wanting to leverage Terraform to deploy all of the necessary resources. Each customer environment is basically the same with the exception of the URL they use to access one of the servers.

I have put together a Terraform configuration that deploys all of the resources for a given customer. BUT... How do I take that same configuration and apply it to the next customer without copying the entire Terraform directory and duplicating that for every customer. (I could have 100's of these)

I've heard workspaces and modules or both. Anyone seen a best-practice article out there on this?

Thx

like image 818
user4109728 Avatar asked Sep 17 '17 16:09

user4109728


1 Answers

You should modulerize your code, then you can easily reuse that module(from a git repository) with different variables to be used for that customer. In this case for each customer, you will end up with only a file that configures the main module.

Have one directory for each customer, with a terraform file that loads up the module(s) and configures it. If you use terraform apply in that directory then the state will also be in that directory. To make sure your team can also deploy and make changes it is suggested to use a backend such as S3, so the state will be written there. Note that you have to configure a backend for each customer in their respective directory. Make sure the backend for each customer don't clash(For example use a different path in S3).

Nicki Watt gave a good presentation on this. You can view the video here and slides at here.

like image 99
Farid Nouri Neshat Avatar answered Nov 11 '22 04:11

Farid Nouri Neshat