github.com/gtmtechltd/terraform@v0.11.12-beta1/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  	"log"
    37  	"os"
    38  
    39  	"io/ioutil"
    40  
    41  	"github.com/mitchellh/cli"
    42  )
    43  
    44  const Version = "0.0.1"
    45  
    46  func main() {
    47  	ui := &cli.ColoredUi{
    48  		OutputColor: cli.UiColorNone,
    49  		InfoColor:   cli.UiColorNone,
    50  		ErrorColor:  cli.UiColorRed,
    51  		WarnColor:   cli.UiColorYellow,
    52  
    53  		Ui: &cli.BasicUi{
    54  			Reader:      os.Stdin,
    55  			Writer:      os.Stdout,
    56  			ErrorWriter: os.Stderr,
    57  		},
    58  	}
    59  
    60  	// Terraform's code tends to produce noisy logs, since Terraform itself
    61  	// suppresses them by default. To avoid polluting our console, we'll do
    62  	// the same.
    63  	if os.Getenv("TF_LOG") == "" {
    64  		log.SetOutput(ioutil.Discard)
    65  	}
    66  
    67  	c := cli.NewCLI("terraform-bundle", Version)
    68  	c.Args = os.Args[1:]
    69  	c.Commands = map[string]cli.CommandFactory{
    70  		"package": func() (cli.Command, error) {
    71  			return &PackageCommand{
    72  				ui: ui,
    73  			}, nil
    74  		},
    75  	}
    76  
    77  	exitStatus, err := c.Run()
    78  	if err != nil {
    79  		ui.Error(err.Error())
    80  	}
    81  
    82  	os.Exit(exitStatus)
    83  }