Use variable in Terraform remote backend

后端 未结 2 1203
广开言路
广开言路 2020-12-11 23:15
# Using a single workspace:
terraform {
  backend \"remote\" {
    hostname = \"app.terraform.io\"
    organization = \"company\"

    workspaces {
      name = \"my         


        
相关标签:
2条回答
  • 2020-12-11 23:55

    I had the same problems and was very disappointed with the need of additional init/wrapper scripts. Some time ago I started to use Terragrunt.

    It's worth taking a look at Terragrunt because it closes the gap between Terraform and the lack of using variables at some points, e.g. for the remote backend configuration: https://terragrunt.gruntwork.io/docs/getting-started/quick-start/#keep-your-backend-configuration-dry

    0 讨论(0)
  • 2020-12-12 00:07

    The backend configuration documentation goes into this in some detail. The main point to note is this:

    Only one backend may be specified and the configuration may not contain interpolations. Terraform will validate this.

    If you want to make this easily configurable then you can use partial configuration for the static parts (eg the type of backend such as S3) and then provide config at run time interactively, via environment variables or via command line flags.

    I personally wrap Terraform actions in a small shell script that runs terraform init with command line flags that uses an appropriate S3 bucket (eg a different one for each project and AWS account) and makes sure the state file location matches the path to the directory I am working on.

    0 讨论(0)
提交回复
热议问题