github.com/rstandt/terraform@v0.12.32-0.20230710220336-b1063613405c/tools/terraform-bundle/main.go (about) 1 // terraform-bundle is a tool to create "bundle archives" that contain both 2 // a particular version of Terraform and a set of providers for use with it. 3 // 4 // Such bundles are useful for distributing a Terraform version and a set 5 // of providers to a system out-of-band, in situations where Terraform's 6 // auto-installer cannot be used due to firewall rules, "air-gapped" systems, 7 // etc. 8 // 9 // When using bundle archives, it's suggested to use a version numbering 10 // scheme that adds a suffix that identifies the archive as being a bundle, 11 // to make it easier to distinguish bundle archives from the normal separated 12 // release archives. This tool by default produces files with the following 13 // naming scheme: 14 // 15 // terraform_0.10.0-bundle2017070302_linux_amd64.zip 16 // 17 // The user is free to rename these files, since the archive filename has 18 // no significance to Terraform itself and the generated pseudo-version number 19 // is not referenced within the archive contents. 20 // 21 // If using such a bundle with an on-premises Terraform Enterprise installation, 22 // it's recommended to use the generated version number (or a modification 23 // thereof) as the tool version within Terraform Enterprise, so that 24 // bundle archives can be distinguished from official releases and from 25 // each other even if the same core Terraform version is used. 26 // 27 // Terraform providers in general release more often than core, so it is 28 // intended that this tool can be used to periodically upgrade providers 29 // within certain constraints and produce a new bundle containing these 30 // upgraded provider versions. A bundle archive can include multiple versions 31 // of the same provider, allowing configurations containing provider version 32 // constrants to be gradually migrated to newer versions. 33 package main 34 35 import ( 36 "io/ioutil" 37 "log" 38 "os" 39 40 tfversion "github.com/hashicorp/terraform/version" 41 "github.com/mitchellh/cli" 42 ) 43 44 func main() { 45 ui := &cli.ColoredUi{ 46 OutputColor: cli.UiColorNone, 47 InfoColor: cli.UiColorNone, 48 ErrorColor: cli.UiColorRed, 49 WarnColor: cli.UiColorYellow, 50 51 Ui: &cli.BasicUi{ 52 Reader: os.Stdin, 53 Writer: os.Stdout, 54 ErrorWriter: os.Stderr, 55 }, 56 } 57 58 // Terraform's code tends to produce noisy logs, since Terraform itself 59 // suppresses them by default. To avoid polluting our console, we'll do 60 // the same. 61 if os.Getenv("TF_LOG") == "" { 62 log.SetOutput(ioutil.Discard) 63 } 64 65 c := cli.NewCLI("terraform-bundle", tfversion.Version) 66 c.Args = os.Args[1:] 67 c.Commands = map[string]cli.CommandFactory{ 68 "package": func() (cli.Command, error) { 69 return &PackageCommand{ 70 ui: ui, 71 }, nil 72 }, 73 } 74 75 exitStatus, err := c.Run() 76 if err != nil { 77 ui.Error(err.Error()) 78 } 79 80 os.Exit(exitStatus) 81 }