How to specify Terraform remote state backend config via CLI

Viewed 332

In Terraform you can specify a remote state data source to access output values from another terraform configuration.

This requires a backend configuration, as follows:

data "terraform_remote_state" "vpc" {
  backend = "remote"

  config = {
    organization = "hashicorp"
    workspaces = {
      name = "vpc-prod"
    }
  }
}

We do not commit backend configuration in the code, it is specified by CLI parameters. Is it possible to also specify the remote state backend configuration via CLI?

1 Answers

Yes it can be possible to specify the remote state backend configuration via CLI with Partial Configuration.

You do not need to specify every required argument in the backend configuration. Omitting certain arguments may be desirable if some arguments are provided automatically by an automation script running Terraform. When some or all of the arguments are omitted, we call this a partial configuration.

With a partial configuration, the remaining configuration arguments must be provided as part of the initialization process.

Please check the Command-line key/value pairs of this Document for how to pass the backend configuration content using CLI

Related