Difference between revisions of "Terraform data source: terraform remote state"

From wikieduonline
Jump to navigation Jump to search
Line 3: Line 3:
 
* <code>[[Controlled Remote State Access]] feature in [[Terraform Cloud]] and Terraform Enterprise, users now have a new way to establish granular controls for state accessibility.</code>
 
* <code>[[Controlled Remote State Access]] feature in [[Terraform Cloud]] and Terraform Enterprise, users now have a new way to establish granular controls for state accessibility.</code>
  
 +
== Example Usage (remote Backend) ==
 +
 +
<pre>data "terraform_remote_state" "vpc" {
 +
  backend = "remote"
 +
 +
  config = {
 +
    organization = "hashicorp"
 +
    workspaces = {
 +
      name = "vpc-prod"
 +
    }
 +
  }
 +
}
 +
 +
# Terraform >= 0.12
 +
resource "aws_instance" "foo" {
 +
  # ...
 +
  subnet_id = data.terraform_remote_state.vpc.outputs.subnet_id
 +
}
 +
 +
# Terraform <= 0.11
 +
resource "aws_instance" "foo" {
 +
  # ...
 +
  subnet_id = "${data.terraform_remote_state.vpc.subnet_id}"
 +
}
 +
</pre>
  
 
== Related ==
 
== Related ==

Revision as of 04:48, 21 February 2022

terraform_remote_state

Example Usage (remote Backend)

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

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

# Terraform >= 0.12
resource "aws_instance" "foo" {
  # ...
  subnet_id = data.terraform_remote_state.vpc.outputs.subnet_id
}

# Terraform <= 0.11
resource "aws_instance" "foo" {
  # ...
  subnet_id = "${data.terraform_remote_state.vpc.subnet_id}"
}

Related

See also

Advertising: