sourceconditiontarget

✔

✔

✔

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 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 "Terraform File" page).

Parameters

NameTypeDescriptionRequired
filestring

“file” defines the path of the hcl file to use.

compatible:

  • source
  • condition
  • target

remark:

  • “file” and “files” are mutually exclusive.
  • the schemes “https://”, “http://” and “file://” are supported in a source or a condition.

example:

  • file: main.tf
filesarray

“files” defines the list of hcl file paths to use.

compatible:

  • source
  • condition
  • target

remark:

  • “file” and “files” are mutually exclusive.
  • in a source or a condition, “files” accepts only one entry.
  • the schemes “https://”, “http://” and “file://” are supported in a source or a condition.
pathstring

“path” defines the hcl attribute path.

compatible:

  • source
  • condition
  • target

remark:

  • “path” is required.

example:

  • path: resource.aws_instance.app_server.ami
  • path: resource.helm_release.prometheus.version
  • path: plugin.aws.version
valuestring

“value” defines the value associated with the hcl path.

compatible:

  • condition
  • target

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.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:

URL scheme is not supported for HCL target

Example

# 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