Skip to content
This repository has been archived by the owner on Oct 14, 2022. It is now read-only.

Feature Request: Support Multiple Environment Deployments with Terraform #106

Open
Aghassi opened this issue Aug 22, 2018 · 0 comments
Open

Comments

@Aghassi
Copy link

Aghassi commented Aug 22, 2018

I've been trying to set this up for the last few days at our company, and I've found that this repo may need a major overhaul to accomplish this. We already have a prod environment, and I went down this road because I tried to setup a staging environment for testing. I've got a working PoC internally that I can base a PR on, but essentially here is what is necessary:

  1. Terraform keeps state of the current directory. As such, adding a prefix will not change anything when deploying infrastructure. In fact, it will cause some of the resources to be destroyed and recreated. We don't want this at scale if I want to have both a staging and a prod environment. Nor do I want this if I want to do something like run a CI integration that vets I can always deploy a new version to an environment by creating a test environment and then tearing it down.
  2. To solve for this, all resources need to be moved from circleci.tf to modules/ folder, with each subfolder having one module per resource grouping. So, the way I have organized it in my PoC is
modules
├── aws_alb
├── aws_sqs
├── iam_instances
├── legacy-builder
├── legacy-builder-cloudinit-ubuntu-docker-v1
├── nomad
├── nomad-cloudinit-ubuntu-v1
├── s3_bucket
├── services_machine
└── vm_machine

The reason for this is so I can accomplish the next step.

  1. Make variables.tf, circleci.tf, terraform.tfvars, files/, and templates/ all "templates" so to speak. Add a section to the Makefile that would allow make environment staging for example. This would then copy all of the afformentioned files to a folder structure like:
environments
├── prod
└── staging

and the sub folder structure would look like

environments/staging
├── files
├── main.tf
├── templates
├── terraform.tfstate
├── terraform.tfstate.backup
├── terraform.tfvars
└── variables.tf

And so on. This allows for me as a consumer to run terraform init/terraform plan on any environment of my choosing in the same AWS infrastructure without colliding or breaking existing infrastructure.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant