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

From wikieduonline
Jump to navigation Jump to search
Line 64: Line 64:
 
== See also ==
 
== See also ==
 
* {{tf state}}
 
* {{tf state}}
* {{terraform state}}
 
 
* {{Terraform data sources}}
 
* {{Terraform data sources}}
 
* {{Terraform state}}
 
* {{Terraform state}}
  
 
[[Category:Terraform]]
 
[[Category:Terraform]]

Revision as of 16:56, 19 April 2023

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}"
}

Example Usage (local Backend)

data "terraform_remote_state" "vpc" {
  backend = "local"

  config = {
    path = "..."
  }
}

# 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}"
}

Errors

Related

See also

Advertising: