Data Source

How to consume env0 remote state as a data source

Terraform allows you to utilize the remote state as a data source. This is particularly useful for retrieving dependent information from a parent resource.

env0's remote state can be used with Terraform Remote State Data Source.

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:

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
}