0
votes

I am building a terraform for my production infrastructure. My module directory structure is like below main.tf
variable.tf
terraform.tfvars
|----->AKS/main.tf
|----->Mysql/main.tf
|----->Kafka/main.tf

I am facing issues to design state files for the above structure. While building AKS we have to run manually/script to create state file ("We cannot create this storage account and blob container using Terraform itself since).

is there any way to define state file at all module-level while deploying complete stack without running below command in child module.

az storage container create --name terraform-state --account-name mytf --account-key xxxxx

1
I don't think so this is possible..terraform backend doesn't supports vars.....but you can check terraform workspace..terraform.io/docs/state/workspaces.htmlerror404

1 Answers

0
votes

Creating storage container for each state file is not the right thing to do.

Two solutions I can think of:

  • User terraform workspace -h : It's a logical way to organize.
  • Pass the backend key dynamically while doing terraform init something like below, in this way you can create state file by specific name.

    terraform init backend-config=backend.tfvars backend-config="key=${AKS|Mysql|Kafka|any-variable}.{any-variable}.tfstate"