Hi All,
How can I use the same terraform tf file, with resource entries, to create different stacks for different applications?
For eg: lets say I have two application, App1 and App2 which need to be deployed to AWS. My terraform file is in /infra/aws/AppStack.tf
AppStack.tf file constains ec2 and elb resource with all parameters passed through variables. While provisioning the stack for App1, I would change the input variables and call Terraform apply in /infra/aws/AppStack.tf. I want to do same for App2. However because of the TFState file already in /infra/aws folder, it will not allow me to do so and it will actually update the App1 Stack. Note that even remote Terraform state wont help here because it will also point to same resource.
How these types of tasks are normally done in Terraform where the need is to use the same TF file but provision different stacks for different applications. Here each application like App1 and App2 keep their own config in some format which just needs to be translated to the terraform input variables. After that Terraform should just create the Stack.
I can think of 2 ways to achieve this:
1) Delete TF state file after each run, so that in the folder we do not have TFState and each apply will create a new Stack for the different App.
2) Read App config files and generate (programmatically) TF files in respective folders. For eg: TF file each in Applications/App1 and Applications/App2 and than run apply by giving DIR.
but both these approaches have issues and they don't seem very natural. Am i missing something obvious?
thanks
Amit