{"id":13505885,"url":"https://github.com/minamijoyo/tfupdate","last_synced_at":"2025-05-14T03:07:38.461Z","repository":{"id":35188716,"uuid":"201781630","full_name":"minamijoyo/tfupdate","owner":"minamijoyo","description":"Update version constraints in your Terraform configurations","archived":false,"fork":false,"pushed_at":"2025-03-31T09:48:44.000Z","size":455,"stargazers_count":581,"open_issues_count":12,"forks_count":23,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-03T10:07:14.356Z","etag":null,"topics":["go","hcl","terraform"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/minamijoyo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-08-11T15:23:10.000Z","updated_at":"2025-03-31T09:48:46.000Z","dependencies_parsed_at":"2024-01-03T02:29:32.750Z","dependency_job_id":"13fb02ba-e787-49d4-8aa0-e0093be7e250","html_url":"https://github.com/minamijoyo/tfupdate","commit_stats":{"total_commits":318,"total_committers":9,"mean_commits":"35.333333333333336","dds":"0.10062893081761004","last_synced_commit":"6619e6c069b22ea2766e5867adf17b3389cdce01"},"previous_names":[],"tags_count":43,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/minamijoyo%2Ftfupdate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/minamijoyo%2Ftfupdate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/minamijoyo%2Ftfupdate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/minamijoyo%2Ftfupdate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/minamijoyo","download_url":"https://codeload.github.com/minamijoyo/tfupdate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248368358,"owners_count":21092343,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","hcl","terraform"],"created_at":"2024-08-01T00:01:16.238Z","updated_at":"2025-05-14T03:07:38.453Z","avatar_url":"https://github.com/minamijoyo.png","language":"Go","funding_links":[],"categories":["Tools","Go"],"sub_categories":["Miscellaneous","Community providers","Helpers"],"readme":"# tfupdate\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)\n[![GitHub release](https://img.shields.io/github/release/minamijoyo/tfupdate.svg)](https://github.com/minamijoyo/tfupdate/releases/latest)\n[![GoDoc](https://godoc.org/github.com/minamijoyo/tfupdate/tfupdate?status.svg)](https://godoc.org/github.com/minamijoyo/tfupdate)\n\n## Features\n\n- Update version constraints of Terraform core, OpenTofu core, providers, and modules\n- Update dependency lock files (.terraform.lock.hcl) without Terraform / OpenTofu CLI\n- Update all your Terraform / OpenTofu configurations and lock files recursively under a given directory\n- Get the latest release version from the GitHub, GitLab, Terraform Registry, or OpenTofu Registry\n- Terraform v0.12+ / OpenTofu v1.6+ support\n\nIf you integrate tfupdate with your favorite CI or job scheduler, you can check the latest release daily and create a Pull Request automatically.\n\n## Why?\nIt is a best practice to break your Terraform configuration and state into small pieces to minimize the impact of an accident.\nIt is also recommended to lock versions of Terraform core, providers and modules to avoid unexpected breaking changes.\nIf you decided to lock version constraints, you probably want to keep them up-to-date frequently to reduce the risk of version upgrade failures.\nIt's easy to update a single directory, but what if they are scattered across multiple directories?\n\nThat is why I wrote a tool which parses Terraform configurations and updates all version constraints at once.\n\n## Install\n\n### macOS\n\nIf you are a macOS user, you can install `tfupdate` via either [Homebrew](https://brew.sh) or [MacPorts](https://www.macports.org):\n\n#### Homebrew\n\n```bash\n$ brew install minamijoyo/tfupdate/tfupdate\n```\n\n#### MacPorts\n\n```bash\n$ sudo port install tfupdate\n```\n\n### Download\n\nDownload the latest compiled binaries and put it anywhere in your executable path.\n\nhttps://github.com/minamijoyo/tfupdate/releases\n\n### Source\n\nIf you have Go 1.24+ development environment:\n\n```\n$ go install github.com/minamijoyo/tfupdate@latest\n$ tfupdate --version\n```\n\n### Docker\n\nYou can also run it with Docker:\n\n```\n$ docker run -it --rm minamijoyo/tfupdate --version\n```\n\n## Usage\n\n```\n$ tfupdate --help\nUsage: tfupdate [--version] [--help] \u003ccommand\u003e [\u003cargs\u003e]\n\nAvailable commands are:\n    lock         Update dependency lock files\n    module       Update version constraints for module\n    opentofu     Update version constraints for opentofu\n    provider     Update version constraints for provider\n    release      Get release version information\n    terraform    Update version constraints for terraform\n```\n\n### terraform\n\n```\n$ tfupdate terraform --help\nUsage: tfupdate terraform [options] \u003cPATH\u003e\n\nArguments\n  PATH               A path of file or directory to update\n\nOptions:\n  -v  --version      A new version constraint (default: latest)\n                     If the version is omitted, the latest version is automatically checked and set.\n  -r  --recursive    Check a directory recursively (default: false)\n  -i  --ignore-path  A regular expression for path to ignore\n                     If you want to ignore multiple directories, set the flag multiple times.\n```\n\nIf you have `main.tf` like the following:\n\n```\n$ cat main.tf\nterraform {\n  required_version = \"0.12.15\"\n}\n```\n\nExecute the following command:\n\n```\n$ tfupdate terraform -v 0.12.16 main.tf\n```\n\n```\n$ cat main.tf\nterraform {\n  required_version = \"0.12.16\"\n}\n```\n\nA value of version flag accepts any string literal. You can also pass a [version constraint](https://www.terraform.io/language/expressions/version-constraints):\n\n```\n$ tfupdate terraform -v \"~\u003e 1.0\" main.tf\n\n$ cat main.tf\nterraform {\n  required_version = \"~\u003e 1.0\"\n}\n```\n\nIf you want to update all your Terraform configurations under the current directory recursively,\nuse `-r (--recursive)` option:\n\n```\n$ tfupdate terraform -v 0.12.16 -r ./\n```\n\nYou can also ignore some path patterns with `-i (--ignore-path)` option:\n\n```\n$ tfupdate terraform -v 0.12.16 -i modules/ -r ./\n```\n\nIf the version is omitted, the latest version is automatically checked and set.\n\n```\n$ tfupdate terraform -r ./\n```\n\n### opentofu\n\n```\n$ tfupdate opentofu --help\nUsage: tfupdate opentofu [options] \u003cPATH\u003e\n\nArguments\n  PATH               A path of file or directory to update\n\nOptions:\n  -v  --version      A new version constraint (default: latest)\n                     If the version is omitted, the latest version is automatically checked and set.\n  -r  --recursive    Check a directory recursively (default: false)\n  -i  --ignore-path  A regular expression for path to ignore\n                     If you want to ignore multiple directories, set the flag multiple times.\n```\n\nIf you have `main.tf` like the following:\n\n```\n$ cat main.tf\nterraform {\n  required_version = \"1.8.0\"\n}\n```\n\nExecute the following command:\n\n```\n$ tfupdate opentofu -v 1.9.0 main.tf\n```\n\n```\n$ cat main.tf\nterraform {\n  required_version = \"1.9.0\"\n}\n```\n\n### provider\n\n```\n$ tfupdate provider --help\nUsage: tfupdate provider [options] \u003cPROVIDER_NAME\u003e \u003cPATH\u003e\n\nArguments\n  PROVIDER_NAME      A name of provider (e.g. aws or integrations/github)\n  PATH               A path of file or directory to update\n\nOptions:\n  -v  --version      A new version constraint (default: latest)\n                     If the version is omitted, the latest version is automatically checked and set.\n  -r  --recursive    Check a directory recursively (default: false)\n  -i  --ignore-path  A regular expression for path to ignore\n                     If you want to ignore multiple directories, set the flag multiple times.\n```\n\n```\n$ cat main.tf\nterraform {\n  required_providers {\n    aws = {\n      source  = \"hashicorp/aws\"\n      version = \"3.70.0\"\n    }\n  }\n}\n\n$ tfupdate provider aws -v 3.74.0 main.tf\n\n$ cat main.tf\nterraform {\n  required_providers {\n    aws = {\n      source  = \"hashicorp/aws\"\n      version = \"3.74.0\"\n    }\n  }\n}\n```\n\nA value of version flag accepts any string literal. You can also pass a [version constraint](https://www.terraform.io/language/expressions/version-constraints):\n\n```\n$ tfupdate provider aws -v \"~\u003e 3.0\" main.tf\n\n$ cat main.tf\nterraform {\n  required_providers {\n    aws = {\n      source  = \"hashicorp/aws\"\n      version = \"~\u003e 3.0\"\n    }\n  }\n}\n```\n\nFor updating the dependency lock file (.terraform.lock.hcl), use the `tfupdate lock` command.\n\n### module\n\n```\n$ tfupdate module --help\nUsage: tfupdate module [options] \u003cMODULE_NAME\u003e \u003cPATH\u003e\n\nArguments\n  MODULE_NAME        A name of module or a regular expression in RE2 syntax\n                     e.g.\n                       terraform-aws-modules/vpc/aws\n                       git::https://example.com/vpc.git\n                       git::https://example\\.com/.+\n  PATH               A path of file or directory to update\n\nOptions:\n  -v  --version       A new version constraint (required)\n                      Automatic latest version resolution is not currently supported for modules.\n  -r  --recursive     Check a directory recursively (default: false)\n  -i  --ignore-path   A regular expression for path to ignore\n                      If you want to ignore multiple directories, set the flag multiple times.\n  --source-match-type Define how to match MODULE_NAME to the module source URLs. Valid values are \"full\" or \"regex\". (default: full)\n```\n\n```\n$ cat main.tf\nmodule \"s3_bucket\" {\n  source  = \"terraform-aws-modules/s3-bucket/aws\"\n  version = \"2.14.0\"\n\n  bucket = \"my-s3-bucket\"\n  acl    = \"private\"\n\n  versioning = {\n    enabled = true\n  }\n}\n\n$ tfupdate module -v 2.14.1 terraform-aws-modules/s3-bucket/aws main.tf\n\n$ cat main.tf\nmodule \"s3_bucket\" {\n  source  = \"terraform-aws-modules/s3-bucket/aws\"\n  version = \"2.14.1\"\n\n  bucket = \"my-s3-bucket\"\n  acl    = \"private\"\n\n  versioning = {\n    enabled = true\n  }\n}\n```\n\nA value of version flag accepts any string literal. You can also pass a [version constraint](https://www.terraform.io/language/expressions/version-constraints):\n\n```\n$ tfupdate module -v \"~\u003e 2.14.1\" terraform-aws-modules/s3-bucket/aws main.tf\n\n$ cat main.tf\nmodule \"s3_bucket\" {\n  source  = \"terraform-aws-modules/s3-bucket/aws\"\n  version = \"~\u003e 2.14.1\"\n\n  bucket = \"my-s3-bucket\"\n  acl    = \"private\"\n\n  versioning = {\n    enabled = true\n  }\n}\n```\n\n### release\n\n```\n$ tfupdate release --help\nUsage: tfupdate release \u003csubcommand\u003e [options] [args]\n\n  This command has subcommands for release version information.\n\nSubcommands:\n    latest    Get the latest release version\n    list      Get a list of release versions\n```\n\n```\n$ tfupdate release latest --help\nUsage: tfupdate release latest [options] \u003cSOURCE\u003e\n\nArguments\n  SOURCE             A path of release data source.\n                     Valid format depends on --source-type option.\n                       - github or gitlab:\n                         owner/repo\n                         e.g. terraform-providers/terraform-provider-aws\n                       - tfregistryModule:\n                         namespace/name/provider\n                         e.g. terraform-aws-modules/vpc/aws\n                       - tfregistryProvider:\n                         namespace/type\n                         e.g. hashicorp/aws\n\nOptions:\n  -s  --source-type  A type of release data source.\n                     Valid values are\n                       - github (default)\n                       - gitlab\n                       - tfregistryModule\n                       - tfregistryProvider\n```\n\n```\n$ tfupdate release latest terraform-providers/terraform-provider-aws\n2.40.0\n```\n\nIf you want to access private repositories on GitHub, export your access token to the `GITHUB_TOKEN` environment variable.\n\nIf you want to access public or private repositories on GitLab, export your access token with api permissions to the `GITLAB_TOKEN` environment variable. If you are using an instance that is not `https://gitlab.com`, set the correct base URL to the `GITLAB_BASE_URL` environment variable (defaults to `https://gitlab.com/api/v4/`).\n\nIf you want to use the public OpenTofu registry, set the `TFREGISTRY_BASE_URL` environment variable to `https://registry.opentofu.org/`.\n\n```\n$ tfupdate release list --help\nUsage: tfupdate release list [options] \u003cSOURCE\u003e\n\nArguments\n  SOURCE             A path of release data source.\n                     Valid format depends on --source-type option.\n                       - github or gitlab:\n                         owner/repo\n                         e.g. terraform-providers/terraform-provider-aws\n                       - tfregistryModule:\n                         namespace/name/provider\n                         e.g. terraform-aws-modules/vpc/aws\n                       - tfregistryProvider:\n                         namespace/type\n                         e.g. hashicorp/aws\n\nOptions:\n  -s  --source-type  A type of release data source.\n                     Valid values are\n                       - github (default)\n                       - gitlab\n                       - tfregistryModule\n                       - tfregistryProvider\n  -n  --max-length   The maximum length of list.\n```\n\n```\n$ tfupdate release list -n 5 hashicorp/terraform\n0.12.17\n0.12.18\n0.12.19\n0.12.20\n0.12.21\n```\n\n### lock\n\nThe tfupdate lock command updates the dependency lock file (.terraform.lock.hcl).\nFor more information on the dependency lock file, see the official Terraform documentation:\nhttps://developer.hashicorp.com/terraform/language/files/dependency-lock\n\n```\n$ tfupdate lock --help\nUsage: tfupdate lock [options] \u003cPATH\u003e\n\nArguments\n  PATH               A relative path of directory to update\n\nOptions:\n      --platform     Specify a platform to update dependency lock files.\n                     At least one or more --platform flags must be specified.\n                     Use this option multiple times to include checksums for multiple target systems.\n                     Target platform names consist of an operating system and a CPU architecture.\n                     (e.g. linux_amd64, darwin_amd64, darwin_arm64)\n  -r  --recursive    Check a directory recursively (default: false)\n  -i  --ignore-path  A regular expression for path to ignore\n                     If you want to ignore multiple directories, set the flag multiple times.\n```\n\nIf you want to use the public OpenTofu registry, set the `TFREGISTRY_BASE_URL` environment variable to `https://registry.opentofu.org/`.\n\n```\n$ export TFREGISTRY_BASE_URL=https://registry.opentofu.org/\n```\n\nGiven the following configuration:\n\n```\n$ cat test-fixtures/lock/simple/main.tf\nterraform {\n  required_providers {\n    null = {\n      source  = \"hashicorp/null\"\n      version = \"3.1.1\"\n    }\n  }\n}\n```\n\nAs you know, you can generate the dependency lock file by the terraform providers lock command:\n\n```\n$ terraform -chdir=test-fixtures/lock/simple providers lock -platform=linux_amd64 -platform=darwin_amd64 -platform=darwin_arm64\n```\n\n```\n$ cat test-fixtures/lock/simple/.terraform.lock.hcl\n# This file is maintained automatically by \"terraform init\".\n# Manual edits may be lost in future updates.\n\nprovider \"registry.terraform.io/hashicorp/null\" {\n  version     = \"3.1.1\"\n  constraints = \"3.1.1\"\n  hashes = [\n    \"h1:71sNUDvmiJcijsvfXpiLCz0lXIBSsEJjMxljt7hxMhw=\",\n    \"h1:Pctug/s/2Hg5FJqjYcTM0kPyx3AoYK1MpRWO0T9V2ns=\",\n    \"h1:YvH6gTaQzGdNv+SKTZujU1O0bO+Pw6vJHOPhqgN8XNs=\",\n    \"zh:063466f41f1d9fd0dd93722840c1314f046d8760b1812fa67c34de0afcba5597\",\n    \"zh:08c058e367de6debdad35fc24d97131c7cf75103baec8279aba3506a08b53faf\",\n    \"zh:73ce6dff935150d6ddc6ac4a10071e02647d10175c173cfe5dca81f3d13d8afe\",\n    \"zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3\",\n    \"zh:8fdd792a626413502e68c195f2097352bdc6a0df694f7df350ed784741eb587e\",\n    \"zh:976bbaf268cb497400fd5b3c774d218f3933271864345f18deebe4dcbfcd6afa\",\n    \"zh:b21b78ca581f98f4cdb7a366b03ae9db23a73dfa7df12c533d7c19b68e9e72e5\",\n    \"zh:b7fc0c1615dbdb1d6fd4abb9c7dc7da286631f7ca2299fb9cd4664258ccfbff4\",\n    \"zh:d1efc942b2c44345e0c29bc976594cb7278c38cfb8897b344669eafbc3cddf46\",\n    \"zh:e356c245b3cd9d4789bab010893566acace682d7db877e52d40fc4ca34a50924\",\n    \"zh:ea98802ba92fcfa8cf12cbce2e9e7ebe999afbf8ed47fa45fc847a098d89468b\",\n    \"zh:eff8872458806499889f6927b5d954560f3d74bf20b6043409edf94d26cd906f\",\n  ]\n}\n```\n\nWhen updating provider version, the lock file must also be updated:\n\n```\n$ tfupdate provider null -v 3.2.1 ./test-fixtures/lock/simple/\n```\n\n```\n$ cat test-fixtures/lock/simple/main.tf\nterraform {\n  required_providers {\n    null = {\n      source  = \"hashicorp/null\"\n      version = \"3.2.1\"\n    }\n  }\n}\n```\n\nYou can update the lock file by the tfupdate lock command without Terraform CLI:\n\n```\n$ tfupdate lock --platform=linux_amd64 --platform=darwin_amd64 --platform=darwin_arm64 ./test-fixtures/lock/simple/\n```\n\nNote that unlike the terraform providers lock command, the `--platform` flag requires two hyphens.\n\n```\n$ cat test-fixtures/lock/simple/.terraform.lock.hcl\n# This file is maintained automatically by \"terraform init\".\n# Manual edits may be lost in future updates.\n\nprovider \"registry.terraform.io/hashicorp/null\" {\n  version     = \"3.2.1\"\n  constraints = \"3.2.1\"\n  hashes = [\n    \"h1:FbGfc+muBsC17Ohy5g806iuI1hQc4SIexpYCrQHQd8w=\",\n    \"h1:tSj1mL6OQ8ILGqR2mDu7OYYYWf+hoir0pf9KAQ8IzO8=\",\n    \"h1:ydA0/SNRVB1o95btfshvYsmxA+jZFRZcvKzZSB+4S1M=\",\n    \"zh:58ed64389620cc7b82f01332e27723856422820cfd302e304b5f6c3436fb9840\",\n    \"zh:62a5cc82c3b2ddef7ef3a6f2fedb7b9b3deff4ab7b414938b08e51d6e8be87cb\",\n    \"zh:63cff4de03af983175a7e37e52d4bd89d990be256b16b5c7f919aff5ad485aa5\",\n    \"zh:74cb22c6700e48486b7cabefa10b33b801dfcab56f1a6ac9b6624531f3d36ea3\",\n    \"zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3\",\n    \"zh:79e553aff77f1cfa9012a2218b8238dd672ea5e1b2924775ac9ac24d2a75c238\",\n    \"zh:a1e06ddda0b5ac48f7e7c7d59e1ab5a4073bbcf876c73c0299e4610ed53859dc\",\n    \"zh:c37a97090f1a82222925d45d84483b2aa702ef7ab66532af6cbcfb567818b970\",\n    \"zh:e4453fbebf90c53ca3323a92e7ca0f9961427d2f0ce0d2b65523cc04d5d999c2\",\n    \"zh:e80a746921946d8b6761e77305b752ad188da60688cfd2059322875d363be5f5\",\n    \"zh:fbdb892d9822ed0e4cb60f2fedbdbb556e4da0d88d3b942ae963ed6ff091e48f\",\n    \"zh:fca01a623d90d0cad0843102f9b8b9fe0d3ff8244593bd817f126582b52dd694\",\n  ]\n}\n```\n\nThe tfupdate lock command parses the `required_providers` block in your configuration, downloads provider packages and calculates hash values under the hood. The most important point is that it caches calculated hash values in memory, which gives us a huge performance advantage when updating multiple directories at once using the `-r (--recursive)` option.\n\nTo skip terraform init, we assume that all dependencies are pinned to a specific version in the required_providers block of the root module. Note that version constraint expressions or indirect dependencies via modules are not supported and ignored.\n\n## Keep your dependencies up-to-date\n\nIf you integrate tfupdate with your favorite CI or job scheduler, you can check the latest release daily and create a Pull Request automatically.\n\nAn example for tfupdate with CircleCI is available:\n\nhttps://github.com/minamijoyo/tfupdate-circleci-example\n\nYou can also use a CircleCI orb:\n\nhttps://github.com/masutaka/circleci-tfupdate-orb\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fminamijoyo%2Ftfupdate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fminamijoyo%2Ftfupdate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fminamijoyo%2Ftfupdate/lists"}