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

From wikieduonline
Jump to navigation Jump to search
Tags: Mobile web edit, Mobile edit
 
(5 intermediate revisions by 3 users not shown)
Line 6: Line 6:
 
== Example Usage (remote Backend) ==
 
== Example Usage (remote Backend) ==
  
<pre>data "terraform_remote_state" "vpc" {
+
data "terraform_remote_state" "vpc" {
  backend = "remote"
+
  [[backend]] = "remote"
 +
 +
  config = {
 +
    organization = "hashicorp"
 +
    workspaces = {
 +
      name = "vpc-prod"
 +
    }
 +
  }
 +
}
  
  config = {
+
# Terraform >= 0.12
    organization = "hashicorp"
+
resource "aws_instance" "foo" {
    workspaces = {
+
  # ...
      name = "vpc-prod"
+
  subnet_id = data.terraform_remote_state.vpc.outputs.subnet_id
    }
+
}  
  }
+
}
+
# Terraform <= 0.11
 
+
resource "aws_instance" "foo" {
# Terraform >= 0.12
+
  # ...
resource "aws_instance" "foo" {
+
  subnet_id = "${data.terraform_remote_state.vpc.subnet_id}"
  # ...
+
}
  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>
 
  
 
== Example Usage (local Backend)==
 
== Example Usage (local Backend)==
Line 57: Line 56:
 
* <code>[[Error: AccessDenied: Access Denied]]</code>
 
* <code>[[Error: AccessDenied: Access Denied]]</code>
 
* <code>[[Error: Unable to find remote state]]</code>
 
* <code>[[Error: Unable to find remote state]]</code>
 +
 +
== Activities ==
 +
* [[Explain the benefits of state]]
  
 
== Related ==
 
== Related ==
 
* <code>[[terraform.tfstate]]</code>
 
* <code>[[terraform.tfstate]]</code>
* [[Explain the benefits of state]]
 
 
* Buildin [[provider]]
 
* Buildin [[provider]]
  
 
== See also ==
 
== See also ==
* {{terraform state}}
+
* {{tf state}}
 +
* {{terraform state cmd}}
 
* {{Terraform data sources}}
 
* {{Terraform data sources}}
 
* {{Terraform state}}
 
* {{Terraform state}}
  
 
[[Category:Terraform]]
 
[[Category:Terraform]]

Latest revision as of 16:57, 19 April 2023

terraform_remote_state

Example Usage (remote Backend)[edit]

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)[edit]

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[edit]

Activities[edit]

Related[edit]

See also[edit]

Advertising: