github.com/ticketmaster/terraform@v0.10.0-beta2.0.20170711045249-a12daf5aba4f/tools/terraform-bundle/README.md (about) 1 # terraform-bundle 2 3 `terraform-bundle` is a helper program to create "bundle archives", which are 4 zip files that contain both a particular version of Terraform and a number 5 of provider plugins. 6 7 Normally `terraform init` will download and install the plugins necessary to 8 work with a particular configuration, but sometimes Terraform is deployed in 9 a network that, for one reason or another, cannot access the official 10 plugin repository for automatic download. 11 12 `terraform-bundle` provides an alternative, by allowing the auto-download 13 process to be run out-of-band on a separate machine that _does_ have access 14 to the repository. The result is a zip file that can be extracted onto the 15 target system to install both the desired Terraform version and a selection 16 of providers, thus avoiding the need for on-the-fly plugin installation. 17 18 ## Building 19 20 To build `terraform-bundle` from source, set up a Terraform development 21 environment per [Terraform's own README](../../README.md) and then install 22 this tool from within it: 23 24 ``` 25 $ go install ./tools/terraform-bundle 26 ``` 27 28 This will install `terraform-bundle` in `$GOPATH/bin`, which is assumed by 29 the rest of this README to be in `PATH`. 30 31 ## Usage 32 33 `terraform-bundle` uses a simple configuration file to define what should 34 be included in a bundle. This is designed so that it can be checked into 35 version control and used by an automated build and deploy process. 36 37 The configuration file format works as follows: 38 39 ```hcl 40 terraform { 41 # Version of Terraform to include in the bundle. An exact version number 42 # is required. 43 version = "0.10.0" 44 } 45 46 # Define which provider plugins are to be included 47 providers { 48 # Include the newest "aws" provider version in the 1.0 series. 49 aws = ["~> 1.0"] 50 51 # Include both the newest 1.0 and 2.0 versions of the "google" provider. 52 # Each item in these lists allows a distinct version to be added. If the 53 # two expressions match different versions then _both_ are included in 54 # the bundle archive. 55 google = ["~> 1.0", "~> 2.0"] 56 } 57 58 ``` 59 60 The `terraform` block defines which version of Terraform will be included 61 in the bundle. An exact version is required here. 62 63 The `providers` block defines zero or more providers to include in the bundle 64 along with core Terraform. Each attribute in this block is a provider name, 65 and its value is a list of version constraints. For each given constraint, 66 `terraform-bundle` will find the newest available version matching the 67 constraint and include it in the bundle. 68 69 It is allowed to specify multiple constraints for the same provider, in which 70 case multiple versions can be included in the resulting bundle. Each constraint 71 string given results in a separate plugin in the bundle, unless two constraints 72 resolve to the same concrete plugin. 73 74 Including multiple versions of the same provider allows several configurations 75 running on the same system to share an installation of the bundle and to 76 choose a version using version constraints within the main Terraform 77 configuration. This avoids the need to upgrade all configurations to newer 78 versions in lockstep. 79 80 After creating the configuration file, e.g. `terraform-bundle.hcl`, a bundle 81 zip file can be produced as follows: 82 83 ``` 84 $ terraform-bundle package terraform-bundle.hcl 85 ``` 86 87 By default the bundle package will target the operating system and CPU 88 architecture where the tool is being run. To override this, use the `-os` and 89 `-arch` options. For example, to build a bundle for on-premises Terraform 90 Enterprise: 91 92 ``` 93 $ terraform-bundle package -os=linux -arch=amd64 terraform-bundle.hcl 94 ``` 95 96 The bundle file is assigned a name that includes the core Terraform version 97 number, a timestamp to the nearest hour of when the bundle was built, and the 98 target OS and CPU architecture. It is recommended to refer to a bundle using 99 this composite version number so that bundle archives can be easily 100 distinguished from official release archives and from each other when multiple 101 bundles contain the same core Terraform version. 102 103 ## Provider Resolution Behavior 104 105 Terraform's provider resolution behavior is such that if a given constraint 106 can be resolved by any plugin already installed on the system it will use 107 the newest matching plugin and not attempt automatic installation. 108 109 Therefore if automatic installation is not desired, it is important to ensure 110 that version constraints within Terraform configurations do not exclude all 111 of the versions available from the bundle. If a suitable version cannot be 112 found in the bundle, Terraform _will_ attempt to satisfy that dependency by 113 automatic installation from the official repository. 114 115 To disable automatic installation altogether -- and thus cause a hard failure 116 if no local plugins match -- the `-plugin-dir` option can be passed to 117 `terraform init`, giving the directory into which the bundle was extracted. 118 The presence of this option overrides all of the normal automatic discovery 119 and installation behavior, and thus forces the use of only the plugins that 120 can be found in the directory indicated. 121 122 The downloaded provider archives are verified using the same signature check 123 that is used for auto-installed plugins, using Hashicorp's release key. At 124 this time, the core Terraform archive itself is _not_ verified in this way; 125 that may change in a future version of this tool. 126 127 ## Installing a Bundle in On-premises Terraform Enterprise 128 129 If using a private install of Terraform Enterprise in an "air-gapped" 130 environment, this tool can produce a custom _tool package_ for Terraform, which 131 includes a set of provider plugins along with core Terraform. 132 133 To create a suitable bundle, use the `-os` and `-arch` options as described 134 above to produce a bundle targeting `linux_amd64`. You can then place this 135 archive on an HTTP server reachable by the Terraform Enterprise hosts and 136 install it as per 137 [Managing Tool Versions](https://github.com/hashicorp/terraform-enterprise-modules/blob/master/docs/managing-tool-versions.md). 138 139 After choosing the "Add Tool Version" button, be sure to set the Tool to 140 "terraform" and then enter as the Version the generated bundle version from 141 the bundle filename, which will be of the form `N.N.N-bundleYYYYMMDDHH`. 142 Enter the URL at which the generated bundle archive can be found, and the 143 SHA256 hash of the file which can be determined by running the tool 144 `sha256sum` with the given file. 145 146 The new bundle version can then be selected as the Terraform version for 147 any workspace. When selected, configurations that require only plugins 148 included in the bundle will run without trying to auto-install. 149 150 Note that the above does _not_ apply to Terraform Pro, or to Terraform Premium 151 when not running a private install. In these packages, Terraform versions 152 are managed centrally across _all_ organizations and so custom bundles are not 153 supported. 154 155 For more information on the available Terraform Enterprise packages, see 156 [the Terraform product site](https://www.hashicorp.com/products/terraform/).