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 hcl file path to interact with. compatible: * source * condition * target remark: * “file” and “files” are mutually exclusive * protocols “https://”, “http://”, and “file://” are supported in path for source and condition | |
| files | array | “files” defines the list of hcl files path to interact with. compatible: * source * condition * target remark: * file and files are mutually exclusive * when using as a source only one file is supported * protocols “https://”, “http://”, and “file://” are supported in file path for source and condition | |
| path | string | “path” defines the hcl attribute path. compatible: * source * condition * target example: * path: resource.aws_instance.app_server.ami * path: resource.helm_release.prometheus.version * path: plugin.aws.version | |
| value | string | “value” is the value associated with a hcl path. compatible: * condition * target default: When used from a condition or a target, the default value is set to linked source output. |
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