-
Notifications
You must be signed in to change notification settings - Fork 9.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support multiple isolated deployments per one TF root #1295
Comments
btw. I know I can always use options like |
Just thinking that there could be a very simple, minimal and IMO nice solution... the remote config could just use the provided ENV name as a suffix in Atlas state name or elsewhere, but it really depends on what the common use-case for this is => do people have separate Atlas accounts for each environment like in AWS?
connect to the right AWS account provider "aws" {
credentials_file_profile = "radeksimko-${terraform.env}"
} use asg_size = 3
instance_size = t2.medium and overwrite it in asg_size = 1
instance_size = t2.small or in asg_size = 9
instance_size = t2.large so expect a pattern-based filenames like Whoever doesn't want to use these environments will just keep using the same naming convention with no harm. What do you think? |
+1 |
I've been thinking about this as well recently, but I was thinking I could make this work now by making my entire environment a module and then still having a separate tf file for each environment that simply pulls that module in. |
In some cases, the environment is just an identifier that provides namespace in the real world, over the same formula. Right now I have a couple of projects with separate terraform paths for dev/production as separate deployments, and this is an anti-pattern (which is ok for now, because dev and production are significantly different). In all cases, I'm nearly losing my mind with the need to keep track of the TF state files. I realize this can be alleviated with consul and Atlas. Either way.. Ideally, multiple environments from the same TF root is just about helping the user manage vars and state |
Is there any update regarding managing different environments @mitchellh? We're also currently using different Would be nice for a builtin clean solution to manage multiple environments with the same terraform configurations (but optionally different variables). |
What are the current workarounds people are using for this? I feel like remote configuration is not currently feasible when deploying to multiple regions. We can store terraform state in github however this does not seem as ideal as S3 or Atlas. |
It seems like a few workarounds have been documented above in #2824. I will check those out. |
@radeksimko so, I hate being that guy who can't actually contribute code, BUT, here's an idea. When working with |
@radeksimko I was able to work around that, so no worries there! |
+1! I'm currently deploying the same code multiple times using different -var-file and -state files to keep management of different environments separate. This works fine UNTIL I want to share the states to other groups with S3. |
+1 Same problem as mentioned by pII. |
+1 – especially with respect to remote state. |
I'd like it so that I could reference other variables within variables. For example, in my
.. I'd like to be able to switch environments by only changing
|
@2rs2ts & @danshao - I've worked around these flaws in terraform in a couple of different ways. My basic approach can be seen here: https://github.com/pll/terraform_infrastructure I'm frequently on #terraform-tool on freenode if you have questions. |
I am also trying to get my head around this problem. We have multiple AWS accounts to manage, and each account might include one or several environments. We want to be able to update each environment individually, and I'd even say, parts of an environment. I must maximize flexibility and reduce repetitions, so I have created configurable modules that are shared between my environment definitions. My terraform folder looks a bit like this:
This is how I can apply the dev and prod plans separately. Unfortunately, it doesn't allow me to apply the dev and qa plans separately. I thought about adding more folders, but then it makes it more difficult to interpolate to shared elements. It's not a solution at all, but it's the method that seems to work best. And i'm not even talking about that moment when a major change is initiated in dev, that we must apply, but that should not be applied in QA (then we must shelve our changes until dev is merged in QA, it's a pita). I like the idea of naming files according to environments, and it's pretty much what we've been doing in our non-terraform deployments so far. We have a default infrastructure definition that contains the whole thing, which is then overriden by environment-specific configurations. I know it's technically possible to do this in terraform, for instance by using terraform init to isolate into a separate directory, but it's kinda clunky and error-prone. Ideally, I'd like my hierarchy to look a bit like this:
And ideally, I see multiple tfstate files, or the ability to separate my definition in logical entities (a bit like modules) and be able to run just the entities i'm interested in updating. This is probably more complicated than it has to be, and sorry for the long post, I guess I had to vent a bit ;) congrats if you made it through! |
@muikrad if you're interested, my script should solve that quite nicely: https://gist.github.com/nathanielks/5bd4de708e831bbc170f. As long as you use S3 to back your remote state, it'll work great 👍. Been using it in production the last few months. |
Thanks @nathanielks - you're right, this should do the trick! I wanted to avoid moving files around, but this is a clean way to put it. |
@muikrad I've symlink'd the script to |
I just got bitten by this as well. It's a huge pain because you don't really see that it's happening until TerraForm's created some convoluted mess of resources on the account you just switched to. All that's really missing is a way to specify the path to the local cached copy of the tfstate file. If that were possible...the rest would be easy! |
Here's my attempt at isolated multi-env,multi-region terraform deployments using env/region-specific remote state files: https://github.com/bkc1/terraform-multi-env |
Is that something that was solved by version 0.9 State Environments (https://www.terraform.io/docs/state/environments.html)? Should this maybe be closed now? |
Yep! Thanks for reminding us. :) |
I think https://www.terraform.io/docs/state/environments.html is not linked in the State section in the website. |
Sorry for the noise, since it's been deprecated in favor of workspaces makes sense. |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
There's currently assumption that each TF root/codebase will be deployed once.
In simple terms 1 codebase = 1
terraform.tfvars
= 1.terraform/
= 1terraform.tfstate
= 1terraform remote config
= 1 Atlas config.I think that Terraform should support multiple isolated deployments of the same code. I can see use cases for isolated environments for testing purposes. Many people maintain separate/isolated infrastructure for testing things before going live.
It could work like RVM or Virtualenv:
which is bringing another question - potential differences between these environments (i.e. deploying the same infrastructure in its less scalable & less fault-tolerant version for testing purposes).
I like that Terraform doesn't support conditionals as it's making it a simple & straightforward DSL exactly as it should be, but how to solve this problem using the DSL approach?
The text was updated successfully, but these errors were encountered: