# Terraform File<no value>
// <!-- Required for asciidoctor -->
:toc:
// Set toclevels to be at least your hugo [markup.tableOfContents.endLevel] config key
:toclevels: 4

[cols="1^,1^,1^",options=header]
|===
| source | condition | target
| &#10004; | &#10004; | &#10004;
|===

== Description

`terraform/file` is an **alias** for link:{{< ref "hcl" >}}[`hcl`] - the same spec, backed by the same implementation. Use whichever name reads better in your manifest; there is no behavioural difference.

**source**::
Retrieves an attribute from a Terraform file at the configured path. A source accepts only one file.

**condition**::
Tests that the attribute at that path matches the value.

**target**::
Ensures the attribute is set to a specific value, editing in place so comments and formatting survive.

== Parameters

{{< resourceparameters "sources" "terraform/file" >}}

`file` or `files` is mandatory, as is `path`; missing either aborts the run with `wrong spec content`. `file` and `files` are mutually exclusive.

`path` walks the block labels joined with dots, so

[source,hcl]
----
resource "aws_instance" "app_server" {
  ami = "ami-830c94e3"
}
----

is addressed as `resource.aws_instance.app_server.ami`. It points at an attribute, never at a block.

TIP: To bump a provider version, reach for link:{{< ref "provider" >}}[`terraform/provider`] instead (it understands `required_providers` blocks directly, rather than needing the exact attribute path).

== Remote files

For a source and a condition, `file` accepts `https://`, `http://` and `file://`. A target refuses a URL with `URL scheme is not supported for HCL target`.

== Example

The example uses an additional resource plugin: link:{{< ref "registry" >}}[`terraform/registry`].

[source,yaml]
----
# updatecli.yaml
{{<include "assets/code_example/docs/plugins/resources/terraform/file/updatecli.d/default.yaml">}}
----

== Links

* link:{{< ref "hcl" >}}[The `hcl` resource] - the same plugin under its generic name
* link:https://github.com/minamijoyo/hcledit[hcledit] - the library doing the editing
