I have a requirement to create a set of a same number of instances for each of our customers. Let us assume my customers Walmart, Apple, and eBay. Each customer has same number of Instances but configuration(subnet, number of disk and disk sizes, OS Images) changes. So I created a variable file for each customer and used it to launch the instances. Until now everything is working as expected. I am able to launch instances for each customer with their own configuration and also able to modify instances as required.
Now, I am trying to move statefile from my local to remote. In backend.tf
how do I take the key
as dynamic? Upon investigating backed.tf
can't accept any interpolations (variables) as it is loaded much before than the core of Terraform can be initialized. I saw a similar question and started using terragrunt. Even with terragrunt I am not able to have a separate state file for each customer
I am not using Terraform Enterprise or Terraform Cloud. Please let me know how to proceed. Thanks!
My Intial Question
Module Repo structure ( When state file was local)
├── main.tf
└── variables.tf
├── gcp_compute_disk
│ ├── gcp_compute_disk.tf
│ └── variables.tf
├── gcp_instance
│ ├── gcp_instance.tf
│ └── variables.tf
├── customers
│ ├── apple.tfvars
│ ├── ebay.tfvars
│ ├── walmart.tfvars
├── statefile
│ ├── apple.tfstate
│ ├── ebay.tfstate
│ ├── walmart.tfstate
With terragrunt, I separated my variable files and modules into two different repos
With terragrunt my Module Repo structure
├── main.tf
└── variables.tf
└── terragrunt.hcl
├── gcp_compute_disk
│ ├── gcp_compute_disk.tf
│ └── variables.tf
├── gcp_instance
│ ├── gcp_instance.tf
│ └── variables.tf
With terragrunt my variable Repo structure
.
├── apple-preprod
│ └── terragrunt.hcl
├── apple-prod
│ └── terragrunt.hcl
└── walmart-prod
| └── terragrunt.hcl
├── walmart-preprod
│ └── terragrunt.hcl
Now how do I make a separate state file for each customer? is it possible to use terragrunt to achieve this scenario?