Terraform terraform_remote_state Partial Configuration

后端 未结 1 1757
误落风尘
误落风尘 2021-01-16 05:37

My team relies heavily on S3 remote state from within Terraform. We use the -backend-config feature of the CLI to specify the S3 configuration when initializin

相关标签:
1条回答
  • 2021-01-16 06:06

    The backend block is rather special because it gets processed so early in Terraform's workflow, and thus it doesn't have access to normal Terraform features such as variables. That's why it has its own special mechanism for configuring it.

    The terraform_remote_state data source, on the other hand, is just a regular data source and so any normal interpolation strategy can be used with it. To pass settings from the CLI, for example, you could use variables:

    variable "dns_state_region" {
    }
    
    variable "dns_state_key" {
    }
    
    data "terraform_remote_state" "dns" {
      backend = "s3"
      config {
        region = "${var.dns_state_region}"
        key    = "${var.dns_state_key}"
      }
    }
    

    You can then pass these to the terraform plan command:

    $ terraform plan \
        -var="dns_state_region=us-west-1" \
        -var="dns_state_key=configurations/production/dns/terraform.tfstate"
    
    0 讨论(0)
提交回复
热议问题