# HCL<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

The `hcl` resource reads and writes a single attribute in an link:https://github.com/hashicorp/hcl[HCL] document, addressed by its dotted path. It handles any HCL file (Terraform, Packer, Consul, Nomad) through link:https://github.com/minamijoyo/hcledit[hcledit], which edits the file in place and preserves comments and formatting.

**source**::
Returns the attribute value. A source accepts only one file.

**condition**::
Checks that the attribute holds `value`, or the source output when `value` is unset.

**target**::
Writes the value at that path. Files already holding it are reported as up to date and left untouched.

NOTE: `kind: terraform/file` is an alias for this resource (same spec, same implementation, documented on the link:/docs/plugins/resource/terraform/file/["Terraform File" page]).

== Parameters

{{< resourceparameters "sources" "hcl" >}}

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

== Attribute paths

`path` addresses an attribute by walking the block labels, joined with dots:

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

is addressed as `resource.aws_instance.app_server.ami`. Other common shapes:

* `resource.helm_release.prometheus.version`
* `plugin.aws.version`

The path points at an *attribute*, not a block (there is no syntax for adding a block or for iterating over several).

== Remote files

`file` accepts `https://`, `http://` and `file://` for a source and a condition. A target refuses a URL:

[source,text]
----
URL scheme is not supported for HCL target
----

== Example

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

== Links

* link:https://github.com/minamijoyo/hcledit[hcledit] - the library doing the editing
* link:/docs/plugins/resource/terraform/file/["Terraform File" page] - the alias
* link:/docs/plugins/resource/terraform/lock/["Terraform Lock" page] and link:/docs/plugins/resource/terraform/provider/["Terraform Provider" page] for the Terraform-specific resources
