mirror of https://github.com/hashicorp/terraform
Merge pull request #32679 from hashicorp/jbardin/terraform-data-docs
initial terraform_data docssebasslash/sro-provisioner-logs
commit
55acdc6b31
@ -0,0 +1,82 @@
|
||||
---
|
||||
page_title: The terraform_data Managed Resource Type
|
||||
description: >-
|
||||
Retrieves the root module output values from a Terraform state snapshot stored
|
||||
in a remote backend.
|
||||
---
|
||||
|
||||
# The `terraform_data` Managed Resource Type
|
||||
|
||||
The `terraform_data` implements the standard resource lifecycle, but does not directly take any other actions.
|
||||
You can use the `terraform_data` resource without requiring or configuring a provider. It is always available through a built-in provider with the [source address](/language/providers/requirements#source-addresses) `terraform.io/builtin/terraform`.
|
||||
|
||||
The `terraform_data` resource is useful for storing values which need to follow a manage resource lifecycle, and for triggering provisioners when there is no other logical managed resource in which to place them.
|
||||
|
||||
|
||||
## Example Usage (data for `replace_triggered_by`)
|
||||
|
||||
|
||||
[The `replace_triggered_by` lifecycle argument](/language/meta-arguments/lifecycle#replace_triggered_by) requires all of the given addresses to be for resources, because the decision to force replacement is based on the planned actions for all of the mentioned resources.
|
||||
|
||||
Plain data values such as [Local Values](/language/values/locals) and [Input Variables](/language/values/variables) don't have any side-effects to plan against and so they aren't valid in `replace_triggered_by`. You can use `terraform_data`'s behavior of planning an action each time `input` changes to _indirectly_ use a plain value to trigger replacement.
|
||||
|
||||
|
||||
```hcl
|
||||
variable "revision" {
|
||||
default = 1
|
||||
}
|
||||
|
||||
resource "terraform_data" "replacement" {
|
||||
input = var.revision
|
||||
}
|
||||
|
||||
# This resource has no convenient attribute which forces replacement,
|
||||
# but can now be replaced by any change to the revision variable value.
|
||||
resource "example_database" "test" {
|
||||
lifecycle {
|
||||
replace_triggered_by = [terraform_data.replacement]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Example Usage (`null_resource` replacement)
|
||||
|
||||
```hcl
|
||||
resource "aws_instance" "web" {
|
||||
# ...
|
||||
}
|
||||
|
||||
resource "aws_instance" "database" {
|
||||
# ...
|
||||
}
|
||||
|
||||
# A use-case for terraform_data is as a do-nothing container
|
||||
# for arbitrary actions taken by a provisioner.
|
||||
resource "terraform_data" "bootstrap" {
|
||||
triggers_replace = [
|
||||
aws_instance.web.id,
|
||||
aws_instance.database.id
|
||||
]
|
||||
|
||||
provisioner "local-exec" {
|
||||
command = "bootstrap-hosts.sh"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
## Argument Reference
|
||||
|
||||
The following arguments are supported:
|
||||
|
||||
* `input` - (Optional) A value which will be stored in the instance state, and reflected in the `output` attribute after apply.
|
||||
|
||||
* `triggers_replace` - (Optional) A value which is stored in the instance state, and will force replacement when the value changes.
|
||||
|
||||
## Attributes Reference
|
||||
|
||||
In addition to the above, the following attributes are exported:
|
||||
|
||||
* `id` - A string value unique to the resource instance.
|
||||
|
||||
* `output` - The computed value derived from the `input` argument. During a plan where `output` is unknown, it will still be of the same type as `input`.
|
||||
Loading…
Reference in new issue