Skip to main content
Terraform allows you to utilize the remote state as a data source. This is particularly useful for retrieving dependent information from a parent resource. env zeroโ€™s remote state can be used with Terraform Remote State Data Source.
hcl
data "terraform_remote_state" "example" {
  backend = "remote"

  config = {
    hostname     = "backend.api.env0.com"
    organization = "[ORGANIZATION_ID]"
    workspaces = {
      name = "[WORKSPACE_NAME]"
    }
  }
}
The WORKSPACE_NAME is unique per organization.
Hereโ€™s an example of how its used:
hcl
provider "aws" {
  region = "us-west-2"
}

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

  config = {
    hostname     = "backend.api.env0.com"
    organization = "aaaaaaaa-bbbb-cccc-dddd-8f43fe49db92"
    workspaces = {
      name = "acme-fitness-agent-vpc"
    }
  }
}

output "vpc_id" {
  value = data.terraform_remote_state.vpc.outputs.vpc_id
}

Suggested Blog Content

Terraform Modules Guide Terraform Plan Examples Managing Terraform Variable Hierarchy Manage Terraform Remote State with a Remote Backend
โŒ˜I