### Build and Install Commands Source: https://github.com/minamijoyo/tfupdate/blob/master/CLAUDE.md Commands to build the binary or install the tool into the Go environment. ```bash make build # Build binary to bin/tfupdate make install # Install to $GOPATH/bin go install # Alternative install method ``` -------------------------------- ### Example Usage of Lock Index Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-reference/lock-index.md Demonstrates creating an index, retrieving a provider version, and accessing its hashes. This example shows how to initialize the index and fetch provider details for lock file generation. ```go import ( "context" "github.com/minamijoyo/tfupdate/lock" "github.com/minamijoyo/tfupdate/tfregistry" ) // Create index for Terraform Registry index, _ := lock.NewIndexFromConfig(tfregistry.Config{}) // Get or create provider version pv, _ := index.GetOrCreateProviderVersion( context.Background(), "hashicorp/null", "3.2.1", []string{"linux_amd64", "darwin_arm64"}, ) // Get hashes for lock file hashes := pv.AllHashes() for _, h := range hashes { println(h) } ``` -------------------------------- ### Install tfupdate from source using Go Source: https://github.com/minamijoyo/tfupdate/blob/master/README.md Install tfupdate from source if you have a Go development environment (version 1.26+). This also shows how to verify the installation. ```bash $ go install github.com/minamijoyo/tfupdate@latest $ tfupdate --version ``` -------------------------------- ### ReleaseLatestCommand Example: GitHub Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-reference/command-interface.md Retrieves the latest release version for a given GitHub repository. ```bash tfupdate release latest hashicorp/terraform ``` -------------------------------- ### Example Usage of NewTFRegistryProviderRelease Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-reference/release-interface.md Demonstrates how to create a TFRegistryProviderRelease for both official and custom provider namespaces. Ensure necessary imports are included. ```go import ( "github.com/minamijoyo/tfupdate/release" "github.com/minamijoyo/tfupdate/tfregistry" ) // Terraform Registry provider config := tfregistry.Config{} r, _ := release.NewTFRegistryProviderRelease("hashicorp/aws", config) // Custom provider namespace r, _ := release.NewTFRegistryProviderRelease("integrations/github", config) ``` -------------------------------- ### TerraformCommand Example Usage Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-reference/command-interface.md Examples demonstrate how to use the tfupdate terraform command to update version constraints, including specific versions, latest versions, and recursive updates with ignore patterns. ```bash # Update to specific version tfupdate terraform -v 1.5.0 ./ ``` ```bash # Update to latest version tfupdate terraform -v latest ./ ``` ```bash # Recursive update with ignore pattern tfupdate terraform -v 1.5.0 -r -i "vendor/" ./ ``` -------------------------------- ### Release Interface Usage Example Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-reference/release-interface.md Demonstrates how to use the Release interface and its helper functions to fetch the latest stable version and a list of recent versions including pre-releases. ```go import ( "context" "github.com/minamijoyo/tfupdate/release" ) // Get latest stable version r, _ := release.NewGitHubRelease("hashicorp/terraform", config) latest, _ := release.Latest(context.Background(), r) // Output: "1.5.0" // Get top 5 versions including pre-releases versions, _ := release.List(context.Background(), r, 5, true) // Output: ["1.5.0", "1.5.0-rc1", "1.4.6", "1.4.6-rc2", "1.4.5"] ``` -------------------------------- ### Programmatic Usage Example Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-overview.md Shows how to use the tfupdate Go API to create options, initialize a global context, and update files or directories. ```go import ( "context" "github.com/minamijoyo/tfupdate/tfupdate" "github.com/spf13/afero" ) // Create option option, _ := tfupdate.NewOption( "provider", "aws", "5.0.0", []string{}, true, []string{}, "", tfregistry.Config{}, ) // Create global context fs := afero.NewOsFs() gc, _ := tfupdate.NewGlobalContext(fs, option) // Update files or directories tfupdate.UpdateFileOrDir(context.Background(), gc, "./infrastructure") ``` -------------------------------- ### ReleaseLatestCommand Example: GitLab Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-reference/command-interface.md Retrieves the latest release version from a GitLab repository. Specify 'gitlab' as the source type. ```bash tfupdate release latest -s gitlab example/project ``` -------------------------------- ### Example Usage of NewGitHubRelease Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-reference/release-interface.md Demonstrates how to create GitHubRelease providers for both public and private repositories. For private repositories, a GITHUB_TOKEN environment variable is expected. ```go import ( "context" "github.com/minamijoyo/tfupdate/release" ) // Public repository config := release.GitHubConfig{} r, _ := release.NewGitHubRelease("minamijoyo/tfupdate", config) // Private repository with token configPrivate := release.GitHubConfig{ Token: os.Getenv("GITHUB_TOKEN"), } r, _ := release.NewGitHubRelease("org/private-repo", configPrivate) ``` -------------------------------- ### Example Usage of UpdateFileOrDir Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-reference/update-functions.md Demonstrates how to use the UpdateFileOrDir function with both files and directories. Ensure you have initialized the GlobalContext with appropriate options and filesystem. ```go import ( "context" "github.com/minamijoyo/tfupdate/tfupdate" "github.com/spf13/afero" ) func main() { fs := afero.NewOsFs() option, _ := tfupdate.NewOption( "provider", "aws", "5.0.0", []string{}, true, []string{}, "", tfregistry.Config{}, ) gc, _ := tfupdate.NewGlobalContext(fs, option) // Works with both files and directories tfupdate.UpdateFileOrDir(context.Background(), gc, "./infrastructure") } ``` -------------------------------- ### Example: Terraform Registry Module Release Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-reference/release-interface.md Demonstrates creating release providers for both the official Terraform Registry and the OpenTofu Registry using their respective base URLs. ```go import ( "github.com/minamijoyo/tfupdate/release" "github.com/minamijoyo/tfupdate/tfregistry" ) // Terraform Registry module config := tfregistry.Config{BaseURL: "https://registry.terraform.io/"} r, _ := release.NewTFRegistryModuleRelease("terraform-aws-modules/vpc/aws", config) // OpenTofu Registry module configOT := tfregistry.Config{BaseURL: "https://registry.opentofu.org/"} r, _ := release.NewTFRegistryModuleRelease("terraform-aws-modules/vpc/aws", configOT) ``` -------------------------------- ### Example Usage: Listing Providers in a Module Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-reference/module-context.md Demonstrates how to create a ModuleContext and retrieve a list of provider source addresses within a given directory. Requires a GlobalContext and the path to the module directory. ```go import ( "context" "github.com/minamijoyo/tfupdate/tfupdate" ) func listProvidersInModule(dirPath string, gc *GlobalContext) ([]string, error) { mc, err := tfupdate.NewModuleContext(dirPath, gc) if err != nil { return nil, err } providers := mc.SelecetedProviders() names := make([]string, len(providers)) for i, p := range providers { names[i] = p.Source } return names, nil } ``` -------------------------------- ### Display tfupdate provider command help Source: https://github.com/minamijoyo/tfupdate/blob/master/README.md Get detailed help for the 'provider' subcommand, including its options and arguments. ```bash $ tfupdate provider --help ``` -------------------------------- ### ModuleUpdater Usage Examples Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-reference/updaters.md Demonstrates creating a ModuleUpdater for exact module name matching and regex-based module name matching. Shows how the module source and version are updated. ```go // Exact match updater, _ := NewModuleUpdater( "terraform-aws-modules/vpc/aws", "5.0.0", nil, ) // Regex match regex := regexp.MustCompile(`git::https://example\.com/.+`) updater, _ := NewModuleUpdater( `git::https://example\.com/.+`, "2.0.0", regex, ) // Updates: // module "vpc" { // source = "terraform-aws-modules/vpc/aws?ref=v5.0.0" // } ``` -------------------------------- ### Example: Update Module with Regex Matching Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-reference/option.md Configures an Option to update a module using regex matching for the module source, recursively processing and setting a specific version. ```go moduleOpt, _ := tfupdate.NewOption( "module", "git::https://example\.com/.+", "2.0.0", []string{}, true, []string{}, "regex", tfregistry.Config{}, ) ``` -------------------------------- ### Example Usage of UpdateDir Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-reference/update-functions.md This example demonstrates how to use the UpdateDir function to update all Terraform files within a given base path. It initializes a ModuleContext and then calls UpdateDir. ```go import ( "context" "github.com/minamijoyo/tfupdate/tfupdate" ) func updateAllTerraform(basePath string, gc *GlobalContext) error { mc, _ := tfupdate.NewModuleContext(basePath, gc) return tfupdate.UpdateDir(context.Background(), mc, basePath) } ``` -------------------------------- ### Example: Update Terraform Version Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-reference/global-context.md Demonstrates how to use GlobalContext to update the Terraform version in a specified path. Requires setting up an afero filesystem and tfupdate options. ```go import ( "github.com/minamijoyo/tfupdate/tfupdate" "github.com/spf13/afero" ) func updateTerraformVersion(path string, newVersion string) error { fs := afero.NewOsFs() option, err := tfupdate.NewOption( "terraform", // updateType "", // name (not used for terraform) newVersion, // version []string{}, // platforms true, // recursive []string{}, // ignorePaths "", // sourceMatchType tfregistry.Config{}, ) if err != nil { return err } gc, err := tfupdate.NewGlobalContext(fs, option) if err != nil { return err } return tfupdate.UpdateFileOrDir(context.Background(), gc, path) } ``` -------------------------------- ### Display tfupdate opentofu command help Source: https://github.com/minamijoyo/tfupdate/blob/master/README.md Get detailed help for the 'opentofu' subcommand, including its options and arguments. ```bash $ tfupdate opentofu --help ``` -------------------------------- ### LockCommand Example: Specific Platforms Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-reference/command-interface.md Updates the lock file for specified platforms in the current directory. ```bash tfupdate lock --platform linux_amd64 --platform darwin_arm64 ./ ``` -------------------------------- ### CLI Usage Examples Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-overview.md Demonstrates various ways to use the tfupdate CLI for updating Terraform configurations, providers, modules, and lock files. ```bash tfupdate terraform -v 1.5.0 -r ./infrastructure tfupdate provider aws -v 5.0.0 ./ tfupdate module -v 2.0.0 terraform-aws-modules/vpc/aws ./ tfupdate lock --platform linux_amd64 ./ tfupdate release latest hashicorp/terraform ``` ```bash tfupdate terraform -v latest ./ # Auto-discovers latest Terraform tfupdate provider aws -v latest ./ # Auto-discovers latest AWS provider tfupdate release latest hashicorp/aws # Queries release source directly ``` ```bash # Exact match tfupdate module terraform-aws-modules/vpc/aws -v 5.0.0 ./ # Regex match tfupdate module --source-match-type regex 'git::https://example\.com/.+' -v 2.0.0 ./ ``` ```bash # Generate hashes for specific platforms tfupdate lock --platform linux_amd64 --platform darwin_arm64 ./ # Use registry h1 hashes (OpenTofu Registry supports this) export TFREGISTRY_BASE_URL=https://registry.opentofu.org/ tfupdate lock ./ ``` ```bash tfupdate provider aws -v 5.0.0 -r \ -i "vendor/" \ -i "test-fixtures/" \ ./infrastructure ``` -------------------------------- ### Install tfupdate via Homebrew on macOS Source: https://github.com/minamijoyo/tfupdate/blob/master/README.md Use this command to install tfupdate if you are a macOS user with Homebrew. ```bash $ brew install minamijoyo/tfupdate/tfupdate ``` -------------------------------- ### Example Usage of UpdateFile Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-reference/update-functions.md Demonstrates how to use the UpdateFile function to update the 'main.tf' file within a given base path and global context. Ensure the ModuleContext is properly initialized. ```go import ( "context" "github.com/minamijoyo/tfupdate/tfupdate" "github.com/spf13/afero" ) func updateMainTF(basePath string, gc *GlobalContext) error { mc, _ := tfupdate.NewModuleContext(basePath, gc) return tfupdate.UpdateFile(context.Background(), mc, "main.tf") } ``` -------------------------------- ### UpdateHCL Example Usage Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-reference/update-functions.md This example demonstrates how to use the UpdateHCL function to update a Terraform configuration string. It uses a bytes.Buffer as the writer and strings.NewReader for the input. ```go import ( "bytes" "strings" "github.com/minamijoyo/tfupdate/tfupdate" ) func updateConfigString(config string, mc *ModuleContext) (string, error) { reader := strings.NewReader(config) writer := &bytes.Buffer{} _, err := tfupdate.UpdateHCL(context.Background(), mc, reader, writer, "main.tf") if err != nil { return "", err } return writer.String(), nil } ``` -------------------------------- ### Display tfupdate terraform command help Source: https://github.com/minamijoyo/tfupdate/blob/master/README.md Get detailed help for the 'terraform' subcommand, including its options and arguments. ```bash $ tfupdate terraform --help ``` -------------------------------- ### LockUpdater Usage Example Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-reference/updaters.md Shows how to initialize a LockUpdater with specific platforms and a Terraform registry configuration. This updater manages provider versions and hashes in lock files. ```go updater, _ := NewLockUpdater( []string{"linux_amd64", "darwin_arm64"}, tfregistry.Config{BaseURL: "https://registry.terraform.io/"}, ) // Updates or creates: // provider "registry.terraform.io/hashicorp/null" { // version = "3.2.1" // constraints = "3.2.1" // hashes = [ // "h1:...", // "h1:...", // ] // } ``` -------------------------------- ### Example: Update Lock File for Specific Platforms Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-reference/option.md Configures an Option to update the dependency lock file for specific platforms, recursively processing and using a custom OpenTofu Registry URL. ```go lockOpt, _ := tfupdate.NewOption( "lock", "", "", []string{"linux_amd64", "darwin_arm64"}, // platforms true, []string{}, // recursive, ignorePaths "", tfregistry.Config{BaseURL: "https://registry.opentofu.org/"}, ) ``` -------------------------------- ### Get a list of release versions Source: https://github.com/minamijoyo/tfupdate/blob/master/README.md Retrieves a list of the latest 5 release versions for the specified Terraform provider. ```bash $ tfupdate release list -n 5 hashicorp/terraform 0.12.17 0.12.18 0.12.19 0.12.20 0.12.21 ``` -------------------------------- ### Example: Update Terraform Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-reference/option.md Configures an Option to update Terraform to a specific version, ignoring specified paths and processing recursively. ```go import ( "github.com/minamijoyo/tfupdate/tfupdate" "github.com/minamijoyo/tfupdate/tfregistry" ) // Update Terraform to a specific version terraformOpt, _ := tfupdate.NewOption( "terraform", "", "1.5.0", []string{}, true, []string{"vendor/", "\.terraform/"}, "", tfregistry.Config{}, ) ``` -------------------------------- ### ReleaseLatestCommand Example: Terraform Registry Provider Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-reference/command-interface.md Retrieves the latest release version for a Terraform Registry provider. Specify 'tfregistryProvider' as the source type. ```bash tfupdate release latest -s tfregistryProvider hashicorp/aws ``` -------------------------------- ### Get Latest Release Version via CLI Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/README.md Retrieve the latest release version for a given provider from a registry. ```bash # Get latest release version tfupdate release latest hashicorp/terraform ``` -------------------------------- ### tfupdate release latest --help Source: https://github.com/minamijoyo/tfupdate/blob/master/README.md Shows help for the 'latest' subcommand of tfupdate release, explaining how to get the latest release version from various sources. ```bash $ tfupdate release latest --help Usage: tfupdate release latest [options] Arguments SOURCE A path of release data source. Valid format depends on --source-type option. - github or gitlab: owner/repo e.g. terraform-providers/terraform-provider-aws - tfregistryModule: namespace/name/provider e.g. terraform-aws-modules/vpc/aws - tfregistryProvider: namespace/type e.g. hashicorp/aws Options: -s --source-type A type of release data source. Valid values are - github (default) - gitlab - tfregistryModule - tfregistryProvider ``` -------------------------------- ### Example Terraform Configuration Source: https://github.com/minamijoyo/tfupdate/blob/master/README.md A sample Terraform configuration file showing the required_providers block. This is used to demonstrate lock file generation. ```hcl terraform { required_providers { null = { source = "hashicorp/null" version = "3.1.1" } } } ``` -------------------------------- ### ReleaseLatestCommand Example: Terraform Registry Module Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-reference/command-interface.md Retrieves the latest release version for a Terraform Registry module. Specify 'tfregistryModule' as the source type. ```bash tfupdate release latest -s tfregistryModule terraform-aws-modules/vpc/aws ``` -------------------------------- ### Get latest release version from GitHub Source: https://github.com/minamijoyo/tfupdate/blob/master/README.md Fetches the latest release version for the specified GitHub repository. ```bash $ tfupdate release latest terraform-providers/terraform-provider-aws 2.40.0 ``` -------------------------------- ### ProviderUpdater Example Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-reference/updaters.md Shows how to use ProviderUpdater to update provider versions. It handles both object and legacy string syntaxes for 'required_providers' and updates matching 'provider' blocks, preserving comments and formatting. ```go updater, _ := NewProviderUpdater("aws", "5.0.0") // Updates both syntaxes: // Object syntax (preserves sort order): // terraform { // required_providers { // aws = { // source = "hashicorp/aws" // version = "5.0.0" // } // } // } // Legacy string syntax: // terraform { // required_providers { // aws = "5.0.0" // } // } ``` -------------------------------- ### LockCommand Example: Recursive Update Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-reference/command-interface.md Recursively checks and updates lock files in the current directory and its subdirectories for a specified platform. ```bash tfupdate lock --platform linux_amd64 -r ./ ``` -------------------------------- ### TerraformUpdater Example Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-reference/updaters.md Demonstrates updating the 'required_version' in a terraform block. This updater targets all terraform blocks and skips lock files. ```go updater, _ := NewTerraformUpdater("1.5.0") // File contains: terraform { required_version = "1.4.0" } // After update: terraform { required_version = "1.5.0" } ``` -------------------------------- ### LockCommand Example: H1 Hashes (OpenTofu Registry) Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-reference/command-interface.md Updates the lock file using h1 hashes, typically for the OpenTofu Registry. Ensure the TFREGISTRY_BASE_URL environment variable is set. ```bash export TFREGISTRY_BASE_URL=https://registry.opentofu.org/ tfupdate lock ./ ``` -------------------------------- ### Terraform Registry Client Configuration Examples Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-reference/tfregistry-client.md Configure the Terraform Registry client for default, OpenTofu, or custom registries. Use a custom http.Client for proxies or TLS configurations. ```go import ( "github.com/minamijoyo/tfupdate/tfregistry" "net/http" "time" ) // Terraform Registry (default) config := tfregistry.Config{} // OpenTofu Registry configOT := tfregistry.Config{ BaseURL: "https://registry.opentofu.org/", } // Custom registry with client customHTTP := &http.Client{Timeout: 30 * time.Second} configCustom := tfregistry.Config{ HTTPClient: customHTTP, BaseURL: "https://my-registry.example.com/", } ``` -------------------------------- ### Example Terraform Lock File Source: https://github.com/minamijoyo/tfupdate/blob/master/README.md This snippet shows the structure of a `.terraform.lock.hcl` file, which is automatically maintained by `terraform init`. It specifies provider versions and their corresponding hash values for different platforms. ```hcl # This file is maintained automatically by "terraform init". # Manual edits may be lost in future updates. provider "registry.terraform.io/hashicorp/null" { version = "3.2.1" constraints = "3.2.1" hashes = [ "h1:FbGfc+muBsC17Ohy5g806iuI1hQc4SIexpYCrQHQd8w=", "h1:tSj1mL6OQ8ILGqR2mDu7OYYYWf+hoir0pf9KAQ8IzO8=", "h1:ydA0/SNRVB1o95btfshvYsmxA+jZFRZcvKzZSB+4S1M=", "zh:58ed64389620cc7b82f01332e27723856422820cfd302e304b5f6c3436fb9840", "zh:62a5cc82c3b2ddef7ef3a6f2fedb7b9b3deff4ab7b414938b08e51d6e8be87cb", "zh:63cff4de03af983175a7e37e52d4bd89d990be256b16b5c7f919aff5ad485aa5", "zh:74cb22c6700e48486b7cabefa10b33b801dfcab56f1a6ac9b6624531f3d36ea3", "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", "zh:79e553aff77f1cfa9012a2218b8238dd672ea5e1b2924775ac9ac24d2a75c238", "zh:a1e06ddda0b5ac48f7e7c7d59e1ab5a4073bbcf876c73c0299e4610ed53859dc", "zh:c37a97090f1a82222925d45d84483b2aa702ef7ab66532af6cbcfb567818b970", "zh:e4453fbebf90c53ca3323a92e7ca0f9961427d2f0ce0d2b65523cc04d5d999c2", "zh:e80a746921946d8b6761e77305b752ad188da60688cfd2059322875d363be5f5", "zh:fbdb892d9822ed0e4cb60f2fedbdbb556e4da0d88d3b942ae963ed6ff091e48f", "zh:fca01a623d90d0cad0843102f9b8b9fe0d3ff8244593bd817f126582b52dd694", ] } ``` -------------------------------- ### Example: Update AWS Provider with Regex Ignore Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-reference/option.md Configures an Option to update the AWS provider to a specific version, recursively processing and ignoring the vendor directory using a regex pattern. ```go providerOpt, _ := tfupdate.NewOption( "provider", "aws", "5.0.0", []string{}, true, []string{"vendor/.*"}, // ignore vendor directory "", tfregistry.Config{}, ) ``` -------------------------------- ### Install tfupdate via MacPorts on macOS Source: https://github.com/minamijoyo/tfupdate/blob/master/README.md Use this command to install tfupdate if you are a macOS user with MacPorts. ```bash $ sudo port install tfupdate ``` -------------------------------- ### Get Tool Version Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-overview.md The version of the tfupdate tool is defined as a constant in the main Go file. ```go var version = "0.10.0" ``` -------------------------------- ### Run tfupdate using Docker Source: https://github.com/minamijoyo/tfupdate/blob/master/README.md Execute tfupdate with Docker to check its version without local installation. ```bash $ docker run -it --rm minamijoyo/tfupdate --version ``` -------------------------------- ### tfupdate release list --help Source: https://github.com/minamijoyo/tfupdate/blob/master/README.md Displays help for the 'list' subcommand of tfupdate release, detailing how to retrieve a list of release versions from a given source. ```bash $ tfupdate release list --help Usage: tfupdate release list [options] Arguments SOURCE A path of release data source. Valid format depends on --source-type option. - github or gitlab: owner/repo e.g. terraform-providers/terraform-provider-aws - tfregistryModule: namespace/name/provider e.g. terraform-aws-modules/vpc/aws - tfregistryProvider: namespace/type e.g. hashicorp/aws Options: -s --source-type A type of release data source. Valid values are - github (default) - gitlab - tfregistryModule - tfregistryProvider -n --max-length The maximum length of list. ``` -------------------------------- ### ModuleContext Option Method Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-reference/module-context.md Returns the option/configuration instance from the global context. ```go func (mc *ModuleContext) Option() Option ``` -------------------------------- ### List Module Versions Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-reference/tfregistry-client.md Lists all versions of a module from the registry. Requires module namespace, name, and provider. ```go import ( "context" "github.com/minamijoyo/tfupdate/tfregistry" ) client, _ := tfregistry.NewClient(tfregistry.Config{}) req := &tfregistry.ListModuleVersionsRequest{ Namespace: "terraform-aws-modules", Name: "vpc", Provider: "aws", } resp, _ := client.ListModuleVersions(context.Background(), req) for _, mod := range resp.Modules { for _, ver := range mod.Versions { println(ver) } } ``` -------------------------------- ### Example .terraform.lock.hcl Content Source: https://github.com/minamijoyo/tfupdate/blob/master/README.md The content of a generated .terraform.lock.hcl file. This file stores checksums for providers across different platforms. ```hcl # This file is maintained automatically by "terraform init". # Manual edits may be lost in future updates. provider "registry.terraform.io/hashicorp/null" { version = "3.1.1" constraints = "3.1.1" hashes = [ "h1:71sNUDvmiJcijsvfXpiLCz0lXIBSsEJjMxljt7hxMhw=", "h1:Pctug/s/2Hg5FJqjYcTM0kPyx3AoYK1MpRWO0T9V2ns=", "h1:YvH6gTaQzGdNv+SKTZujU1O0bO+Pw6vJHOPhqgN8XNs=", "zh:063466f41f1d9fd0dd93722840c1314f046d8760b1812fa67c34de0afcba5597", "zh:08c058e367de6debdad35fc24d97131c7cf75103baec8279aba3506a08b53faf", "zh:73ce6dff935150d6ddc6ac4a10071e02647d10175c173cfe5dca81f3d13d8afe", "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", "zh:8fdd792a626413502e68c195f2097352bdc6a0df694f7df350ed784741eb587e", "zh:976bbaf268cb497400fd5b3c774d218f3933271864345f18deebe4dcbfcd6afa", "zh:b21b78ca581f98f4cdb7a366b03ae9db23a73dfa7df12c533d7c19b68e9e72e5", "zh:b7fc0c1615dbdb1d6fd4abb9c7dc7da286631f7ca2299fb9cd4664258ccfbff4", "zh:d1efc942b2c44345e0c29bc976594cb7278c38cfb8897b344669eafbc3cddf46", "zh:e356c245b3cd9d4789bab010893566acace682d7db877e52d40fc4ca34a50924", "zh:ea98802ba92fcfa8cf12cbce2e9e7ebe999afbf8ed47fa45fc847a098d89468b", "zh:eff8872458806499889f6927b5d954560f3d74bf20b6043409edf94d26cd906f", ] } ``` -------------------------------- ### Update Terraform version constraint Source: https://github.com/minamijoyo/tfupdate/blob/master/README.md Update the 'required_version' in a main.tf file to a specific version. This example shows updating to '0.12.16'. ```bash $ tfupdate terraform -v 0.12.16 main.tf ``` -------------------------------- ### tfupdate release --help Source: https://github.com/minamijoyo/tfupdate/blob/master/README.md Displays help information for the tfupdate release command, detailing its subcommands for managing release versions. ```bash $ tfupdate release --help Usage: tfupdate release [options] [args] This command has subcommands for release version information. Subcommands: latest Get the latest release version list Get a list of release versions ``` -------------------------------- ### Recursive Updates with Cached Hashes Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-reference/lock-index.md Demonstrates how to create an Index once and reuse it for updating multiple directories. This leverages the cached hashes for significant performance gains. ```go import ( "context" "github.com/minamijoyo/tfupdate/tfupdate" ) // Create index once index, _ := lock.NewIndexFromConfig(config) // Use same index for multiple directories for _, dir := range []string{"./dir1", "./dir2", "./dir3"} { // Hash calculations are cached across all directories mc, _ := tfupdate.NewModuleContext(dir, gc) tfupdate.UpdateDir(context.Background(), mc, dir) } // dir1: calculates hashes for hashicorp/null 3.2.1 // dir2: reuses cached hashes (fast) // dir3: reuses cached hashes (fast) ``` -------------------------------- ### Create OpenTofu Registry Config Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/configuration.md Configure tfregistry.Config to use the OpenTofu Registry by setting the BaseURL. ```go import ( "github.com/minamijoyo/tfupdate/tfregistry" ) // OpenTofu Registry config := tfregistry.Config{ BaseURL: "https://registry.opentofu.org/", } ``` -------------------------------- ### Lock File Handling Import Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/README.md Import the package for handling lock files. ```go // Lock file handling "github.com/minamijoyo/tfupdate/lock" ``` -------------------------------- ### Configure tfregistry Client for OpenTofu Registry Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-reference/tfregistry-client.md Shows how to configure the tfregistry client to use the OpenTofu Registry by setting the BaseURL in the client configuration. ```go config := tfregistry.Config{ BaseURL: "https://registry.opentofu.org/", } ``` -------------------------------- ### tfupdate module --help Source: https://github.com/minamijoyo/tfupdate/blob/master/README.md Displays help information for the tfupdate module command, outlining its usage, arguments, and options for updating module versions. ```bash $ tfupdate module --help Usage: tfupdate module [options] Arguments MODULE_NAME A name of module or a regular expression in RE2 syntax e.g. terraform-aws-modules/vpc/aws git::https://example.com/vpc.git git::https://example\.com/.+ PATH A path of file or directory to update Options: -v --version A new version constraint (required) Automatic latest version resolution is not currently supported for modules. -r --recursive Check a directory recursively (default: false) -i --ignore-path A regular expression for path to ignore If you want to ignore multiple directories, set the flag multiple times. --source-match-type Define how to match MODULE_NAME to the module source URLs. Valid values are "full" or "regex". (default: full) ``` -------------------------------- ### ModuleContext FS Method Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-reference/module-context.md Retrieves the filesystem instance from the global context associated with the ModuleContext. ```go func (mc *ModuleContext) FS() afero.Fs ``` -------------------------------- ### Release Version Management Import Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/README.md Import the package for managing release versions. ```go // Release version management "github.com/minamijoyo/tfupdate/release" ``` -------------------------------- ### Registry API Client Import Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/README.md Import the package for the registry API client. ```go // Registry API client "github.com/minamijoyo/tfupdate/tfregistry" ``` -------------------------------- ### NewOption Constructor Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-reference/option.md Creates and validates an Option instance. It compiles regex patterns and validates the configuration based on provided parameters. ```go func NewOption( updateType string, name string, version string, platforms []string, recursive bool, ignorePaths []string, sourceMatchType string, tfregistryConfig tfregistry.Config, ) (Option, error) ``` -------------------------------- ### Environment Variables Source: https://github.com/minamijoyo/tfupdate/blob/master/CLAUDE.md Configuration variables for authentication and registry endpoints. ```bash GITHUB_TOKEN= # For private GitHub repositories GITLAB_TOKEN= # For GitLab repositories (with api permissions) GITLAB_BASE_URL= # For GitLab instances (default: https://gitlab.com/api/v4/) TFREGISTRY_BASE_URL= # For OpenTofu registry (set to https://registry.opentofu.org/) ``` -------------------------------- ### CLI Commands Import Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/README.md Import the necessary packages for tfupdate CLI commands. ```go // CLI commands "github.com/minamijoyo/tfupdate/command" ``` -------------------------------- ### Get Provider Package Metadata Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-reference/tfregistry-client.md Retrieves metadata for a specific provider version package, including download URLs and checksums. Requires namespace, type, version, OS, and architecture. ```go import ( "context" "github.com/minamijoyo/tfupdate/tfregistry" ) client, _ := tfregistry.NewClient(tfregistry.Config{}) req := &tfregistry.ProviderPackageMetadataRequest{ Namespace: "hashicorp", Type: "aws", Version: "5.0.0", OS: "linux", Arch: "amd64", } resp, _ := client.ProviderPackageMetadata(context.Background(), req) println("Download URL:", resp.DownloadURL) println("Filename:", resp.Filename) ``` -------------------------------- ### List Provider Versions Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-reference/tfregistry-client.md Lists all versions of a provider from the registry. Requires provider namespace and type. ```go import ( "context" "github.com/minamijoyo/tfupdate/tfregistry" ) client, _ := tfregistry.NewClient(tfregistry.Config{}) req := &tfregistry.ListProviderVersionsRequest{ Namespace: "hashicorp", Type: "aws", } resp, _ := client.ListProviderVersions(context.Background(), req) for version := range resp.Versions { println(version) } ``` -------------------------------- ### Dependency Management Commands Source: https://github.com/minamijoyo/tfupdate/blob/master/CLAUDE.md Commands to manage Go module dependencies. ```bash make deps # Download Go modules go mod download # Alternative dependency download ``` -------------------------------- ### Testing Commands Source: https://github.com/minamijoyo/tfupdate/blob/master/CLAUDE.md Commands for running unit tests, acceptance tests, and linting. ```bash make test # Run unit tests make testacc # Run acceptance tests (requires install first) make testacc-all # Run all acceptance test suites make lint # Run golangci-lint make check # Run both lint and test ``` -------------------------------- ### tfupdate lock Command Help Source: https://github.com/minamijoyo/tfupdate/blob/master/README.md Displays the usage and options for the tfupdate lock command. Use this to understand available arguments and flags. ```bash $ tfupdate lock --help Usage: tfupdate lock [options] Arguments PATH A relative path of directory to update Options: --platform Specify a platform to update dependency lock files. Use this option multiple times to include checksums for multiple target systems. Target platform names consist of an operating system and a CPU architecture. (e.g. linux_amd64, darwin_amd64, darwin_arm64) If the registry supports h1 hash values, as in the public OpenTofu Registry, omitting the platform will record hash values for all platforms without downloading binaries. -r --recursive Check a directory recursively (default: false) -i --ignore-path A regular expression for path to ignore If you want to ignore multiple directories, set the flag multiple times. ``` -------------------------------- ### Create Module Update Option with Regex Matching Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/configuration.md Use NewOption to configure module updates, including regex matching for source. Specify the update type, module source pattern, version, and other relevant parameters. ```go import ( "github.com/minamijoyo/tfupdate/tfupdate" "github.com/minamijoyo/tfupdate/tfregistry" ) // Module update with regex matching option, err := tfupdate.NewOption( "module", "git::https://example\.com/.+", "2.0.0", []string{}, false, []string{}, "regex", // sourceMatchType: use regex matching tfregistry.Config{}, ) ``` -------------------------------- ### ListProviderVersionsResponse Struct Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/types.md Represents the response structure for listing provider versions, containing a map of available versions. ```go type ListProviderVersionsResponse struct { Versions map[string]struct{} } ``` -------------------------------- ### Display tfupdate help information Source: https://github.com/minamijoyo/tfupdate/blob/master/README.md View the main help message for tfupdate to see available commands and general usage. ```bash $ tfupdate --help ``` -------------------------------- ### Create Lock File Update Option Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/configuration.md Use NewOption to configure lock file updates. Specify the update type and desired platforms. Version and name are not used for lock file updates. ```go import ( "github.com/minamijoyo/tfupdate/tfupdate" "github.com/minamijoyo/tfupdate/tfregistry" ) // Lock file update option, err := tfupdate.NewOption( "lock", "", // name unused "", // version unused []string{"linux_amd64", "darwin_arm64"}, // platforms true, []string{}, "", tfregistry.Config{ BaseURL: "https://registry.opentofu.org/", }, ) ``` -------------------------------- ### Configure OpenTofu Registry Index Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-reference/lock-index.md Configure the Lock Index to use the OpenTofu registry with h1 hashes. This avoids downloading provider binaries. ```go config := tfregistry.Config{ BaseURL: "https://registry.opentofu.org/", } index, _ := lock.NewIndexFromConfig(config) // With empty platforms, uses h1 hashes (no downloads) pv, _ := index.GetOrCreateProviderVersion( ctx, "hashicorp/null", "3.2.1", []string{}, ) ``` -------------------------------- ### Create Provider Update Option Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/configuration.md Use NewOption to configure provider updates. Specify the update type, provider name, version, and optionally platforms, ignored paths, and registry configurations. ```go import ( "github.com/minamijoyo/tfupdate/tfupdate" "github.com/minamijoyo/tfupdate/tfregistry" ) // Provider update option, err := tfupdate.NewOption( "provider", "aws", "5.0.0", []string{}, true, []string{"test-fixtures/"}, "", tfregistry.Config{}, ) ``` -------------------------------- ### ListModuleVersionsResponse Struct Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/types.md Represents the response structure for listing module versions, containing a list of available versions. ```go type ListModuleVersionsResponse struct { Modules []struct { Versions []string } } ``` -------------------------------- ### ModuleContext SelectedProviders Method Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-reference/module-context.md Returns a list of providers inferred from `required_providers` block version constraints. Results are sorted alphabetically by source address and ignore providers with empty source or unparseable version constraints. ```go func (mc *ModuleContext) SelecetedProviders() []SelectedProvider ``` -------------------------------- ### ReleaseListCommand Structure Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/types.md Defines the structure for the ReleaseListCommand, used for listing release versions. ```go type ReleaseListCommand struct { Meta sourceType string source string maxLength int } ``` -------------------------------- ### Core Functionality Import Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/README.md Import the core tfupdate functionality for common operations. ```go // Core functionality "github.com/minamijoyo/tfupdate/tfupdate" ``` -------------------------------- ### Handle API Errors with tfregistry Client Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-reference/tfregistry-client.md Demonstrates how to catch and print API errors, such as 404 Not Found, when listing provider versions. ```go import ( "context" "github.com/minamijoyo/tfupdate/tfregistry" ) client, _ := tfregistry.NewClient(tfregistry.Config{}) req := &tfregistry.ListProviderVersionsRequest{ Namespace: "nonexistent", Type: "notfound", } _, err := client.ListProviderVersions(context.Background(), req) if err != nil { println("Error:", err.Error()) // 404 from API } ``` -------------------------------- ### OpenTofuUpdater Struct Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/types.md A concrete implementation of the Updater interface for managing OpenTofu version constraints. ```go type OpenTofuUpdater struct { version string } ``` -------------------------------- ### ListModuleVersionsRequest Struct Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/types.md Defines the request structure for listing module versions from the registry, requiring namespace, name, and provider. ```go type ListModuleVersionsRequest struct { Namespace string Name string Provider string } ``` -------------------------------- ### Initial main.tf content Source: https://github.com/minamijoyo/tfupdate/blob/master/README.md Shows the initial content of a Terraform main.tf file with an S3 bucket module. ```hcl module "s3_bucket" { source = "terraform-aws-modules/s3-bucket/aws" version = "2.14.0" bucket = "my-s3-bucket" acl = "private" versioning = { enabled = true } } ``` -------------------------------- ### NewGitHubRelease Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-reference/release-interface.md Creates a GitHub release provider to retrieve version information from GitHub releases. It takes a repository source and configuration, returning a Release interface or an error. ```APIDOC ## NewGitHubRelease ### Description Creates a GitHub release provider to retrieve version information from GitHub releases. It takes a repository source and configuration, returning a Release interface or an error. ### Function Signature ```go func NewGitHubRelease(source string, config GitHubConfig) (Release, error) ``` ### Parameters #### Path Parameters - **source** (string) - Required - Repository in format "owner/repo" (e.g., "hashicorp/terraform") - **config** (GitHubConfig) - Required - Configuration with optional token and base URL ### GitHubConfig Structure ```go type GitHubConfig struct { BaseURL string // GitHub API base URL (defaults to public GitHub) Token string // Personal access token for private repositories } ``` ### Returns - **release** (Release) - GitHubRelease implementation - **error** (error) - Error if source format invalid or client initialization fails ### Behavior - Queries GitHub API v3 releases endpoint - Requires "owner/repo" format - Supports GitHub Enterprise via BaseURL (testing only; not fully supported) - Token enables access to private repositories - Returns tag names with "v" prefix stripped (v1.0.0 → 1.0.0) ### Example ```go import ( "context" "github.com/minamijoyo/tfupdate/release" ) // Public repository config := release.GitHubConfig{} r, _ := release.NewGitHubRelease("minamijoyo/tfupdate", config) // Private repository with token configPrivate := release.GitHubConfig{ Token: os.Getenv("GITHUB_TOKEN"), } r, _ := release.NewGitHubRelease("org/private-repo", configPrivate) ``` ``` -------------------------------- ### ModuleContext ResolveProviderShortNameFromSource Method Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-reference/module-context.md Resolves the short name of a provider (e.g., 'aws') from its fully qualified source address (e.g., 'hashicorp/aws'). Returns an empty string if the provider is not found in the module's required providers. ```go func (mc *ModuleContext) ResolveProviderShortNameFromSource(source string) string ``` -------------------------------- ### Configure GitHub Release Source Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/configuration.md Use this to specify a GitHub repository for releases. For private repositories, set the GITHUB_TOKEN environment variable. ```bash # Public repository tfupdate release latest hashicorp/terraform # Private repository (requires GITHUB_TOKEN) export GITHUB_TOKEN=ghp_xxxx tfupdate release latest org/private-repo ``` -------------------------------- ### Command Interface Definition Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-reference/command-interface.md Defines the standard interface for all CLI commands, including Help, Run, and Synopsis methods. ```go type Command interface { Help() string Run(args []string) int Synopsis() string } ``` -------------------------------- ### Meta Structure Definition Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/api-reference/command-interface.md The Meta structure holds shared UI and filesystem access for commands. ```go type Meta struct { UI cli.Ui Fs afero.Fs } ``` -------------------------------- ### ReleaseLatestCommand Structure Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/types.md Defines the structure for the ReleaseLatestCommand, used for retrieving the latest release version. ```go type ReleaseLatestCommand struct { Meta sourceType string source string } ``` -------------------------------- ### ListProviderVersionsRequest Struct Source: https://github.com/minamijoyo/tfupdate/blob/master/_autodocs/types.md Defines the request structure for listing provider versions from the registry, requiring namespace and type. ```go type ListProviderVersionsRequest struct { Namespace string Type string } ```