Terraform Version control
A CLI tool for managing Terraform module and provider versions in .tf files.
cargo install --path .Get the value of a module attribute:
tv get 'module.example.source["ref"]' --file example.tfGet a value with a default if not found:
tv get 'module.example.variable' default_value --file example.tfSet the value of a module attribute:
tv set 'module.example.source["ref"]' v1.0.1 --file example.tfSet a simple attribute value:
tv set 'module.example.variable' new_value --file example.tfScan for .tf files that match a query pattern:
tv scan 'module.*' --dir .Scan for files with specific attributes:
tv scan 'terraform.required_providers.aws' --dir .Scan with filters:
tv scan 'module.*.source[url=="git::https://github.com/example/repo.git"]' --dir .Queries follow the pattern: block_type.block_label.attribute["index"]
Examples:
module.example.source["ref"]- Get/set therefparameter in thesourceattribute of theexamplemodulemodule.example.source["url"]- Get/set the URL part of thesourceattributemodule.example.source["path"]- Get/set the path part of thesourceattribute (for git sources with subdirectories)module.example.variable- Get/set thevariableattribute of theexamplemodule
Scan queries support wildcards (*) and filters:
Examples:
module.*- Find all files with any module blockmodule.vpc- Find files with a specific module named "vpc"module.*.source- Find files with modules that have asourceattributemodule.*.version- Find files with modules that have aversionattributeterraform.required_providers.*- Find files with any required provider in terraform blockterraform.required_providers.aws- Find files with AWS provider requirementmodule.*.source[url=="git::https://github.com/example/repo.git"]- Find modules with specific source URLmodule.*.source[ref=="v1.0.0"]- Find modules with specific version refmodule.*.source[path=="modules/vpc"]- Find modules with specific subdirectory path
Given a Terraform file main.tf:
module "example" {
source = "git::https://github.com/example/repo.git//modules/vpc?ref=v1.0.0"
variable1 = "value1"
}$ tv get 'module.example.source["ref"]' --file main.tf
v1.0.0
$ tv set 'module.example.source["ref"]' v1.0.1 --file main.tf
$ tv get 'module.example.source["ref"]' --file main.tf
v1.0.1$ tv get 'module.example.source["url"]' --file main.tf
https://github.com/example/repo.git
$ tv set 'module.example.source["url"]' github.com/example/new-repo.git --file main.tf
$ tv get 'module.example.source["url"]' --file main.tf
github.com/example/new-repo.git$ tv get 'module.example.source["path"]' --file main.tf
modules/vpc
$ tv set 'module.example.source["path"]' modules/rds --file main.tf
$ tv get 'module.example.source["path"]' --file main.tf
modules/rds$ tv get 'module.example.source' --file main.tf
git::github.com/example/new-repo.git//modules/rds?ref=v1.0.1For registry modules, use version instead of ref:
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "5.0.0"
}$ tv get 'module.vpc.source' --file main.tf
terraform-aws-modules/vpc/aws
$ tv get 'module.vpc.version' --file main.tf
5.0.0The scan command helps you find .tf files that match specific patterns across your codebase.
$ tv scan 'module.*' --dir .
./modules/networking/main.tf
./modules/compute/main.tf
./main.tf$ tv scan 'terraform.required_providers.aws' --dir .
./main.tf
./modules/networking/main.tf$ tv scan 'terraform.required_providers.*' --dir .
./main.tf
./modules/networking/main.tf
./modules/compute/main.tf$ tv scan 'module.*.source[url=="git::https://github.com/example/repo.git"]' --dir .
./main.tf
./modules/vpc/main.tf$ tv scan 'module.*.source[ref=="v1.0.0"]' --dir .
./modules/vpc/main.tf$ tv scan 'module.*.version' --dir .
./modules/rds/main.tf