1
votes

Not sure there is going to be a right or wrong answer for this one, but I am just interested how people manage Terraform in the real world? In terms of do you use modules, different environments and collaborations.

At the moment we are planning on having a production, dev and test environments. All similar.

Now at the moment I have made my terraform files in a way that define individual components of AWS, so say one for, VPC, IAM, EC2, Monitoring (CloudWatch + CloudTrail + CloudConfig) etc. And there is one variable file and .tfvars for the above, so the files are portable (all environments will be the same). So if you need to change something its all in one place. Also means if we have a specific project running I can create a tf file defining all the resource for the project and drop it in, then once its completed remove it.

Each environment has its own folder structure on our Terraform server.

Is this too simplistic? I keep looking at module.

Also does anyone have experience of collaboration with Terraform, as in different teams? I have been looking at things like Atlantis to tie into GitHub, so any changes need to be approved. But also at the sametime with the correct IAM role I can limit what Terraform can change.

Like I said may not be a wrong of right answer just interested in how people are managing terraform and their experiences.

Thanks

1
It's probably not an exact duplicate but this question shares a lot in common with stackoverflow.com/q/43201497/2291321 so some of the answers suggested there might be useful around structuring your code. Also your question seems to be 2 questions so it might be worth splitting it into "Best practices on structuring a Terraform code base" (potentially a duplicate of the above linked question so maybe not needed) and "Best practices around collaboration in a Terraform code base"ydaetskcoR
Thanks ydaetskcoR - that's actually really helpful, I'll have a read of that article and perhaps follow your idea and look to break down the above a bit further if I need to. Thanks for pointing me in the right directionStevieHyperB

1 Answers

0
votes

My answer is just an use case...

We are using terraform for an application deployed for several customers each having small specific configuration features.

We have only one CVS repository. We don't use CVS branches mechanism.

For each folder, we have remote states at least to share states between developers.

  • We are using one global folder having remote states also to share states between customers configurations
  • We are using one folder per customer and using workspaces (former environment) for each context for each customer (prod:blue/green, stage)
  • For common infrastructure chunks shared by all customers, we use module

We mainly use variables to reduce the number of specific files in each customer folders.

Hope this will help you...