Retrieves state meta data from a remote backend
data "terraform_remote_state" "vpc" { backend = "atlas" config { name = "hashicorp/vpc-prod" } } resource "aws_instance" "foo" { # ... subnet_id = "${data.terraform_remote_state.vpc.subnet_id}" }
The following arguments are supported:
backend
- (Required) The remote backend to use. environment
- (Optional) The Terraform environment to use. config
- (Optional) The configuration of the remote backend. defaults
- (Optional) default value for outputs in case state file is empty or it does not have the output. The following attributes are exported:
In addition, each output in the remote state appears as a top level attribute on the terraform_remote_state
resource.
Only the root level outputs from the remote state are accessible. Outputs from modules within the state cannot be accessed. If you want a module output to be accessible via a remote state, you must thread the output through to a root output.
An example is shown below:
module "app" { source = "..." } output "app_value" { value = "${module.app.value}" }
In this example, the output value
from the "app" module is available as "app_value". If this root level output hadn't been created, then a remote state resource wouldn't be able to access the value
output on the module.
© 2018 HashiCorpLicensed under the MPL 2.0 License.
https://www.terraform.io/docs/providers/terraform/d/remote_state.html