Description

The Terragrunt crawler looks recursively for all Terragrunt files (*.hcl) containing a module definition from a specific root directory. Then for each of them, it tries to automate its update.

It currently support two types of sources: - terraform/registry - gittag

It will parsed the module source and infer the source type.

It will update the file using the hcl target.

It supports the following module source definition and will update with prefixing accordingly

terraform {
  source = "tfr://someModule?version=1.2.3
}
terraform {
  source = local.base_url
}
terraform {
  source = "tfr://${local.module}?version=${local.module_version}"
}
terraform {
  source = "tfr://someModule?version=${local.module_version}"
}
terraform {
  source = "tfr://${local.module}?version=1.2.3"
}

This crawler is enabled by default, so it can be used either automatically by running updatecli diff from a directory containing the files to update, or by providing a manifest. The automatic discovery behavior can be tuned by providing a YAML manifest with a terragrunt crawler in top-level directive autodiscovery as explained in the "Autodiscovery" page.

Generated manifests

The source kind is inferred from the module source:

  • a tfr:// source resolves through terraform/registry,

  • a git:: source resolves through gittag, reading tags from the remote repository.

In both cases the version is written back with the hcl target.

Authentication

Git-hosted modules are queried over the network, so private repositories need credentials. Set username and token to authenticate against the git provider.

Manifest

Parameters

NameTypeDescriptionRequired
ignorearray

“ignore” defines rules to exclude matching Terraform modules from the autodiscovery.

remark:

  • a Terraform module is ignored when it matches at least one rule.
    modulesobject

“modules” defines the Terraform modules to match, keyed by module source as written in the Terragrunt files.

remark:

  • a Git source matches every module whose source starts with it.
  • a “tfr://” registry source can omit its trailing parts to match a whole registry or namespace.
  • an empty value matches any version.
  • otherwise the value is a semantic version constraint, such as “>=1.0.0”.
  • when the version or the constraint cannot be parsed, the value must equal the version.

example:

modules:
  # ignore every module from a registry
  tfr://registry.opentofu.org:
  # ignore a specific module
  tfr:///terraform-aws-modules/rdss/aws:
  # ignore the versions matching this constraint
  git@github.com:hashicorp/exampleLongNameForSorting.git: "1.x"
    pathstring

“path” defines a Terragrunt file path pattern.

remark:

  • the pattern must match the whole path, not just a substring.
  • the pattern follows the Go filepath.Match syntax, such as “*” or “?”.
onlyarray

“only” defines rules to restrict the autodiscovery to matching Terraform modules.

remark:

  • a Terraform module is kept only when it matches at least one rule.
    modulesobject

“modules” defines the Terraform modules to match, keyed by module source as written in the Terragrunt files.

remark:

  • a Git source matches every module whose source starts with it.
  • a “tfr://” registry source can omit its trailing parts to match a whole registry or namespace.
  • an empty value matches any version.
  • otherwise the value is a semantic version constraint, such as “>=1.0.0”.
  • when the version or the constraint cannot be parsed, the value must equal the version.

example:

modules:
  # ignore every module from a registry
  tfr://registry.opentofu.org:
  # ignore a specific module
  tfr:///terraform-aws-modules/rdss/aws:
  # ignore the versions matching this constraint
  git@github.com:hashicorp/exampleLongNameForSorting.git: "1.x"
    pathstring

“path” defines a Terragrunt file path pattern.

remark:

  • the pattern must match the whole path, not just a substring.
  • the pattern follows the Go filepath.Match syntax, such as “*” or “?”.
rootdirstring

“rootdir” defines the directory where the crawler starts searching for Terragrunt “.hcl” files.

default: the scm directory when “scmid” is set, otherwise the directory relative paths resolve from, by default the working directory.

remark:

  • a relative path is resolved from the default directory.
  • an absolute path is used as is, instead of the scm directory.
tokenstring

“token” defines the token used for Git authentication when accessing private module repositories.

default: empty, no authentication, which suits public repositories.

remark:

  • it works with any Git provider, such as GitHub, GitLab, Bitbucket or Gitea.
  • it must be set for private repositories.
  • it is only used for modules whose source is a Git repository.
  • use a template function to read it from the environment, such as {{ requiredEnv "GITLAB_TOKEN" }}.

example:

  • token: “ghp_xxxxxxxxxxxx”
  • token: “glpat-xxxxxxxxxxxx”
  • token: “{{ requiredEnv "GITLAB_TOKEN" }}”
usernamestring

“username” defines the username used for Git authentication when accessing private module repositories.

default: “oauth2”, which matches the GitHub scm plugin and is required for go-git HTTP basic authentication.

remark:

  • it works with any Git provider, such as GitHub, GitLab, Bitbucket or Gitea.
  • it is only used when “token” is set.
  • with a token, the username is usually a placeholder since the token identifies the user.
  • common values are “oauth2”, “x-access-token”, “git”, or a real username.
  • use a template function to read it from the environment, such as {{ requiredEnv "GIT_USERNAME" }}.

example:

  • username: “git”
  • username: “oauth2”
  • username: “{{ requiredEnv "GIT_USERNAME" }}”
versionfilterobject

“versionfilter” defines the version filter used by the generated manifests.

default: kind “semver” with pattern “*”, any version greater than or equal to the current one.

remark:

  • with kind “semver”, “pattern” accepts:
    • “prerelease”: the latest prerelease of the current version.
    • “patch”: patch updates only.
    • “minor”: patch and minor updates.
    • “minoronly”: minor updates only.
    • “major”: patch, minor and major updates.
    • “majoronly”: major updates only.
    • a version constraint, such as “>= 1.0.0”.
  • with kind “regex”, “pattern” accepts a regular expression.
  • more examples at https://www.updatecli.io/docs/core/versionfilter/

example:

versionfilter:
  kind: semver
  pattern: minor
    kindstring

“kind” defines the versioning scheme used to select a version.

default: latest

remark:

  • accepted values are “latest”, “semver”, “regex”, “regex/semver”, “time”, “regex/time”, “lex” and “pep440”.
  • “latest” returns the last version of the list.
  • “lex” sorts the versions lexicographically and returns the last one.
  • “pep440” follows https://peps.python.org/pep-0440/

example:

  • kind: semver
    patternstring

“pattern” defines the version pattern, according to “kind”.

default:

  • latest: “latest”
  • semver and pep440: “*”
  • regex: “.*”
  • time and regex/time: “2006-01-02”

remark:

  • for “latest”, “latest” returns the last version, any other value must match a version exactly.
  • for “semver” and “regex/semver”, it is a semantic versioning constraint.
  • for “pep440”, it is a pep440 version specifier.
  • for “regex”, it is a regular expression.
  • for “time” and “regex/time”, it is a Go date layout.
  • ignored by “lex”.

example:

  • pattern: ~1.2
  • pattern: “>=1.0.0 <2.0.0”
  • pattern: ^v\d+.\d+.\d+$
    regexstring

“regex” defines the regular expression extracting the version from each entry.

remark:

  • only used by the kinds “regex/semver” and “regex/time”.
  • the value of the first capture group is used as the version.

example:

  • regex: ^v(\d+.\d+.\d+)$
    replaceallobject

“replaceall” applies a regular expression replacement to each version before filtering.

remark:

  • only used by the kinds “regex”, “regex/semver” and “regex/time”.
  • the replacement runs before “pattern” or “regex” is evaluated.

example:

replaceall:
  pattern: "_"
  replacement: "."

turns “curl-8_15_0” into “curl-8.15.0”.

        patternstring

“pattern” defines the regular expression matching the text to replace.

example:

  • pattern: “_”
        replacementstring

“replacement” defines the text replacing each match of “pattern”.

remark:

  • capture groups can be referenced with $1, $2, and so on.

example:

  • replacement: “.”
    strictboolean

“strict” enforces strict semantic versioning rules when parsing versions.

default: false

remark:

  • only used by the kinds “semver” and “regex/semver”.
⚠ This table is generated from the Updatecli codebase and may contain inaccurate data. Feel free to report them on github.com/updatecli/updatecli

Example

# updatecli.d/default.yaml
name: "Terraform autodiscovery using git scm"
scms:
  default:
    kind: git
    spec:
      url: https://github.com/updatecli-test/jenkins-infra-aws.git
      branch: main

autodiscovery:
  # scmid is applied to all crawlers
  scmid: default
  crawlers:
    terraform:
      # platforms to request package checksums for, defaults to:
      platforms:
        - linux_amd64
        - linux_arm64
        - darwin_amd64
        - darwin_arm64
      # To ignore specific path
      #ignore:
      #  - path: <filepath relative to scm repository>
      #  - providers:
      #      # Ignoring provider updates for this provider
      #      registry.terraform.io/hashicorp/aws:
      #      # Ignore provider updates for this version
      #      registry.terraform.io/hashicorp/kubernetes: "1.x"

      ignore:
      #  - path: <filepath relative to scm repository>
      #  - providers:
      #      # Ignoring provider updates for this provider
      #      registry.terraform.io/hashicorp/aws:
      #      # Ignore provider updates for this version
      #      registry.terraform.io/hashicorp/kubernetes: "1.x"