HCL
| source | condition | target |
|---|---|---|
✔ | ✔ | ✔ |
Description
The hcl resource reads and writes a single attribute in an HCL document, addressed by its dotted path. It handles any HCL file (Terraform, Packer, Consul, Nomad) through 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 whenvalueis 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 "Terraform File" page). |
Parameters
| Name | Type | Description | Required |
|---|---|---|---|
| file | string | “file” defines the path of the hcl file to use. compatible:
remark:
example:
| |
| files | array | “files” defines the list of hcl file paths to use. compatible:
remark:
| |
| path | string | “path” defines the hcl attribute path. compatible:
remark:
example:
| |
| value | string | “value” defines the value associated with the hcl path. compatible:
default: the output of the associated source. |
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:
resource "aws_instance" "app_server" {
ami = "ami-830c94e3"
}is addressed as resource.aws_instance.app_server.ami. Other common shapes:
resource.helm_release.prometheus.versionplugin.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:
URL scheme is not supported for HCL targetExample
# updatecli.yaml
name: Basic HCL Example
scms:
default:
kind: git
spec:
url: https://github.com/updatecli/updatecli.git
sources:
local:
name: Get value from hcl
kind: hcl
scmid: default
spec:
file: pkg/plugins/resources/hcl/testdata/data.hcl
path: resource.person.john.first_name
http:
name: Get value from hcl
kind: hcl
spec:
file: https://raw.githubusercontent.com/updatecli/updatecli/master/pkg/plugins/resources/hcl/testdata/data.hcl
path: resource.person.john.first_name
conditions:
local:
name: Test value from hcl
kind: hcl
sourceid: local
scmid: default
spec:
file: pkg/plugins/resources/hcl/testdata/data.hcl
path: resource.person.john.first_name
http:
name: Test value from hcl
kind: hcl
disablesourceinput: true
spec:
file: https://raw.githubusercontent.com/updatecli/updatecli/master/pkg/plugins/resources/hcl/testdata/data.hcl
path: resource.person.john.first_name
value: John
targets:
local:
name: Test value from hcl
kind: hcl
sourceid: local
scmid: default
spec:
file: pkg/plugins/resources/hcl/testdata/data.hcl
path: resource.person.john.first_name
value: John
Links
hcledit - the library doing the editing
"Terraform File" page - the alias
"Terraform Lock" page and "Terraform Provider" page for the Terraform-specific resources