CLI tool that checks Terraform code for module updates. Single binary, no dependencies. linux, osx, windows. #golang #cli #terraform
terraform-module-versions
Checks for updates of external terraform modules referenced in given Terraform source. Outputs Markdown tables by default, as well as JSONL (-o jsonl, one JSON object per line), JSON (-o json), and JUnit XML (-o junit).
Supported module sources:
- Git with SemVer tags
git::...
- github.com/...
- git@github.com:...
- Terraform Registry
<NAMESPACE>/<NAME>/<SYSTEM>
- private <HOSTNAME>/<NAMESPACE>/<NAME>/<SYSTEM>
Example
$ terraform-module-versions check examples
| UPDATE? | NAME | CONSTRAINT | VERSION | LATEST MATCHING | LATEST |
|---------|----------------------------------|------------|---------|-----------------|---------|
| (Y) | consul | ~0.7.3 | | 0.7.11 | 0.11.0 |
| (Y) | consulgithubhttps | 0.8.0 | v0.8.0 | | v0.11.0 |
| (Y) | consulgithubhttpsmissingref | 0.7.3 | | v0.7.3 | v0.11.0 |
| (Y) | consulgithubhttpsnoref | | | | v0.11.0 |
| Y | consulgithubssh | ~0.1.0 | 0.1.0 | v0.1.2 | v0.11.0 |
| (Y) | examplegitscp | ~> 0.12 | 0.12.0 | | v3.3.4 |
| (Y) | examplegitssh_branch | | master | | v3.3.4 |
| (Y) | examplewithprerelease_versions | | v0.22.2 | | v0.32.1 |
Contents
- Example - Contents - Examples - List modules with their current versions - Check for module updates - Check for module updates using Github Token authentication - Check for updates of specific modules - Get it - Usage -list
- check
Examples
$ cat examples/main.tf
module "consul" {
source = "hashicorp/consul/aws"
version = "~0.7.3"
}
module "consulgithubhttpsmissingref" { source = "github.com/hashicorp/terraform-aws-consul" version = "0.7.3" }
module "consulgithubhttpsnoref" { source = "github.com/hashicorp/terraform-aws-consul" }
module "consulgithubhttps" { source = "github.com/hashicorp/terraform-aws-consul?ref=v0.8.0" version = "0.8.0" }
module "consulgithubssh" { source = "git@github.com:hashicorp/terraform-aws-consul?ref=0.1.0" version = "~0.1.0" }
module "examplegitssh_branch" { source = "git::ssh://git@github.com/keilerkonzept/terraform-module-versions?ref=master" }
module "examplegitscp" { source = "git::git@github.com:keilerkonzept/terraform-module-versions?ref=0.12.0" version = "~> 0.12" }
module "examplewithprerelease_versions" { source = "git@github.com:kubernetes/api.git?ref=v0.22.2" }
module "local" { source = "./local" }
variable "015sensitiveexample" { type = string sensitive = true }
output "015sensitive_example" { value = "foo-${var.015sensitiveexample}" sensitive = true }
output "015nonsensitive_example" { value = nonsensitive(var.015sensitiveexample) }
List modules with their current versions
# list modules with their current versions and version constraints (if specified)
$ terraform-module-versions list examples
| TYPE | NAME | CONSTRAINT | VERSION | SOURCE | |----------|----------------------------------|------------|---------|------------------------------------------------------------------------------| | registry | consul | ~0.7.3 | | hashicorp/consul/aws | | local | local | | | ./local | | git | examplewithprerelease_versions | | v0.22.2 | git@github.com:kubernetes/api.git?ref=v0.22.2 | | git | examplegitssh_branch | | master | git::ssh://git@github.com/keilerkonzept/terraform-module-versions?ref=master | | git | examplegitscp | ~> 0.12 | 0.12.0 | git::git@github.com:keilerkonzept/terraform-module-versions?ref=0.12.0 | | git | consulgithubssh | ~0.1.0 | 0.1.0 | git@github.com:hashicorp/terraform-aws-consul?ref=0.1.0 | | git | consulgithubhttpsnoref | | | github.com/hashicorp/terraform-aws-consul | | git | consulgithubhttpsmissingref | 0.7.3 | | github.com/hashicorp/terraform-aws-consul | | git | consulgithubhttps | 0.8.0 | v0.8.0 | github.com/hashicorp/terraform-aws-consul?ref=v0.8.0 |
with -o json:
[
{
"path": "examples/main.tf",
"name": "consul",
"type": "registry",
"source": "hashicorp/consul/aws",
"constraint": "~0.7.3"
},
{
"path": "examples/main.tf",
"name": "consulgithubhttps",
"type": "git",
"source": "github.com/hashicorp/terraform-aws-consul?ref=v0.8.0",
"constraint": "0.8.0",
"version": "v0.8.0"
},
{
"path": "examples/main.tf",
"name": "consulgithubhttpsmissingref",
"type": "git",
"source": "github.com/hashicorp/terraform-aws-consul",
"constraint": "0.7.3"
},
{
"path": "examples/main.tf",
"name": "consulgithubhttpsnoref",
"type": "git",
"source": "github.com/hashicorp/terraform-aws-consul"
},
{
"path": "examples/main.tf",
"name": "consulgithubssh",
"type": "git",
"source": "git@github.com:hashicorp/terraform-aws-consul?ref=0.1.0",
"constraint": "~0.1.0",
"version": "0.1.0"
},
{
"path": "examples/main.tf",
"name": "examplegitscp",
"type": "git",
"source": "git::git@github.com:keilerkonzept/terraform-module-versions?ref=0.12.0",
"constraint": "~> 0.12",
"version": "0.12.0"
},
{
"path": "examples/main.tf",
"name": "examplegitssh_branch",
"type": "git",
"source": "git::ssh://git@github.com/keilerkonzept/terraform-module-versions?ref=master",
"version": "master"
},
{
"path": "examples/main.tf",
"name": "examplewithprerelease_versions",
"type": "git",
"source": "git@github.com:kubernetes/api.git?ref=v0.22.2",
"version": "v0.22.2"
},
{
"path": "examples/main.tf",
"name": "local",
"type": "local",
"source": "./local"
}
]
Check for module updates
# check: check for module updates from (usually) remote sources
$ terraform-module-versions check examples
| UPDATE? | NAME | CONSTRAINT | VERSION | LATEST MATCHING | LATEST | |---------|----------------------------------|------------|---------|-----------------|---------| | (Y) | consul | ~0.7.3 | | 0.7.11 | 0.11.0 | | (Y) | consulgithubhttps | 0.8.0 | v0.8.0 | | v0.11.0 | | (Y) | consulgithubhttpsmissingref | 0.7.3 | | v0.7.3 | v0.11.0 | | (Y) | consulgithubhttpsnoref | | | | v0.11.0 | | Y | consulgithubssh | ~0.1.0 | 0.1.0 | v0.1.2 | v0.11.0 | | (Y) | examplegitscp | ~> 0.12 | 0.12.0 | | v3.3.4 | | (Y) | examplegitssh_branch | | master | | v3.3.4 | | (Y) | examplewithprerelease_versions | | v0.22.2 | | v0.32.1 |
with -o json:
[
{
"path": "examples/main.tf",
"name": "consul",
"source": "hashicorp/consul/aws",
"constraint": "~0.7.3",
"latestMatching": "0.7.11",
"latestOverall": "0.11.0",
"nonMatchingUpdate": true
},
{
"path": "examples/main.tf",
"name": "consulgithubhttps",
"source": "github.com/hashicorp/terraform-aws-consul?ref=v0.8.0",
"constraint": "0.8.0",
"version": "v0.8.0",
"latestOverall": "v0.11.0",
"nonMatchingUpdate": true
},
{
"path": "examples/main.tf",
"name": "consulgithubhttpsmissingref",
"source": "github.com/hashicorp/terraform-aws-consul",
"constraint": "0.7.3",
"latestMatching": "v0.7.3",
"latestOverall": "v0.11.0",
"nonMatchingUpdate": true
},
{
"path": "examples/main.tf",
"name": "consulgithubhttpsnoref",
"source": "github.com/hashicorp/terraform-aws-consul",
"latestOverall": "v0.11.0",
"nonMatchingUpdate": true
},
{
"path": "examples/main.tf",
"name": "consulgithubssh",
"source": "git@github.com:hashicorp/terraform-aws-consul?ref=0.1.0",
"constraint": "~0.1.0",
"version": "0.1.0",
"latestMatching": "v0.1.2",
"latestOverall": "v0.11.0",
"matchingUpdate": true,
"nonMatchingUpdate": true
},
{
"path": "examples/main.tf",
"name": "examplegitscp",
"source": "git::git@github.com:keilerkonzept/terraform-module-versions?ref=0.12.0",
"constraint": "~> 0.12",
"version": "0.12.0",
"latestOverall": "v3.3.4",
"nonMatchingUpdate": true
},
{
"path": "examples/main.tf",
"name": "examplegitssh_branch",
"source": "git::ssh://git@github.com/keilerkonzept/terraform-module-versions?ref=master",
"version": "master",
"latestOverall": "v3.3.4",
"nonMatchingUpdate": true
},
{
"path": "examples/main.tf",
"name": "examplewithprerelease_versions",
"source": "git@github.com:kubernetes/api.git?ref=v0.22.2",
"version": "v0.22.2",
"latestOverall": "v0.32.1",
"nonMatchingUpdate": true
}
]
# check -all: check for updates, include up-to-date-modules in output
$ terraform-module-versions check -all examples
| UPDATE? | NAME | CONSTRAINT | VERSION | LATEST MATCHING | LATEST | |---------|----------------------------------|------------|---------|-----------------|---------| | (Y) | consul | ~0.7.3 | | 0.7.11 | 0.11.0 | | (Y) | consulgithubhttps | 0.8.0 | v0.8.0 | | v0.11.0 | | (Y) | consulgithubhttpsmissingref | 0.7.3 | | v0.7.3 | v0.11.0 | | (Y) | consulgithubhttpsnoref | | | | v0.11.0 | | Y | consulgithubssh | ~0.1.0 | 0.1.0 | v0.1.2 | v0.11.0 | | (Y) | examplegitscp | ~> 0.12 | 0.12.0 | | v3.3.4 | | (Y) | examplegitssh_branch | | master | | v3.3.4 | | (Y) | examplewithprerelease_versions | | v0.22.2 | | v0.32.1 | | ? | local | | | | |
Check for module updates using Github Token authentication
$ export GITHUB_TOKEN="<your Github PAT>"
$ terraform-module-versions check examples
Check for updates of specific modules
# check -module: check for updates of specific modules
$ terraform-module-versions check -all -module=consulgithubhttps -module=consulgithubssh examples
| UPDATE? | NAME | CONSTRAINT | VERSION | LATEST MATCHING | LATEST | |---------|---------------------|------------|---------|-----------------|---------| | (Y) | consulgithubhttps | 0.8.0 | v0.8.0 | | v0.11.0 | | Y | consulgithubssh | ~0.1.0 | 0.1.0 | v0.1.2 | v0.11.0 |
# check -module: check for updates of specific modules
$ terraform-module-versions check -module=consulgithubhttps -module=consulgithubssh examples
| UPDATE? | NAME | CONSTRAINT | VERSION | LATEST MATCHING | LATEST | |---------|---------------------|------------|---------|-----------------|---------| | (Y) | consulgithubhttps | 0.8.0 | v0.8.0 | | v0.11.0 | | Y | consulgithubssh | ~0.1.0 | 0.1.0 | v0.1.2 | v0.11.0 |
with -o json:
[
{
"path": "examples/main.tf",
"name": "consulgithubhttps",
"source": "github.com/hashicorp/terraform-aws-consul?ref=v0.8.0",
"constraint": "0.8.0",
"version": "v0.8.0",
"latestOverall": "v0.11.0",
"nonMatchingUpdate": true
},
{
"path": "examples/main.tf",
"name": "consulgithubssh",
"source": "git@github.com:hashicorp/terraform-aws-consul?ref=0.1.0",
"constraint": "~0.1.0",
"version": "0.1.0",
"latestMatching": "v0.1.2",
"latestOverall": "v0.11.0",
"matchingUpdate": true,
"nonMatchingUpdate": true
}
]
Get it
Using go get:
go install github.com/keilerkonzept/terraform-module-versions/v3@latest
Or download the binary for your platform from the releases page.
Usage
USAGE
terraform-module-versions [options] <subcommand>
SUBCOMMANDS list List referenced terraform modules with their detected versions check Check referenced terraform modules' sources for newer versions version Print version and exit
FLAGS -o markdown (alias for -output) -output markdown output format, one of [json jsonl junit markdown markdown-wide] -q=false (alias for -quiet) -quiet=false suppress log output (stderr)
list
DESCRIPTION
List referenced terraform modules with their detected versions
USAGE terraform-module-versions list [options] [<path> ...]
List referenced terraform modules with their detected versions
FLAGS -module value include this module (may be specified repeatedly. by default, all modules are included) -o markdown (alias for -output) -output markdown output format, one of [json jsonl junit markdown markdown-wide]
check
DESCRIPTION
Check referenced terraform modules' sources for newer versions
USAGE terraform-module-versions check [options] [<path> ...]
Check referenced terraform modules' sources for newer versions
FLAGS -H value (alias for -registry-header) -a=false (alias for -all) -all=false include modules without updates -any-updates-found-nonzero-exit=false exit with a nonzero code when modules with updates are found (ignoring version constraints) -e=false (alias for -updates-found-nonzero-exit) -module value include this module (may be specified repeatedly. by default, all modules are included) -n=false (alias for -any-updates-found-nonzero-exit) -o markdown (alias for -output) -output markdown output format, one of [json jsonl junit markdown markdown-wide] -pre-release=false include pre-release versions -registry-header value extra HTTP headers for requests to Terraform module registries (a key/value pair KEY:VALUE, may be specified repeatedly) -sed=false generate sed statements for upgrade -updates-found-nonzero-exit=false exit with a nonzero code when modules with updates matching are found (respecting version constraints)