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

From wikieduonline
Jump to navigation Jump to search
(Created page with " terraform_remote_state == See also == * {{Terraform}} Category:Terraform")
 
 
(27 intermediate revisions by 6 users not shown)
Line 1: Line 1:
terraform_remote_state
+
<code>terraform_remote_state</code>
 +
* https://developer.hashicorp.com/terraform/language/state/remote-state-data
  
 +
* <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) ==
  
 +
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)==
 +
 +
<pre>
 +
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}"
 +
}
 +
</pre>
 +
 +
== Errors ==
 +
* <code>[[Error: AccessDenied: Access Denied]]</code>
 +
* <code>[[Error: Unable to find remote state]]</code>
 +
 +
== Activities ==
 +
* [[Explain the benefits of state]]
 +
 +
== Related ==
 +
* <code>[[terraform.tfstate]]</code>
 +
* Buildin [[provider]]
  
 
== See also ==
 
== See also ==
* {{Terraform}}
+
* {{tf state}}
 +
* {{terraform state cmd}}
 +
* {{Terraform data sources}}
 +
* {{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: