github.com/gtmtechltd/terraform@v0.11.12-beta1/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  In some cases, this can be solved by installing provider plugins into the
    13  [user plugins directory](https://www.terraform.io/docs/configuration/providers.html#third-party-plugins).
    14  However, this doesn't always meet the needs of automated deployments.
    15  
    16  `terraform-bundle` provides an alternative, by allowing the auto-download
    17  process to be run out-of-band on a separate machine that _does_ have access
    18  to the repository. The result is a zip file that can be extracted onto the
    19  target system to install both the desired Terraform version and a selection
    20  of providers, thus avoiding the need for on-the-fly plugin installation.
    21  
    22  ## Building
    23  
    24  To build `terraform-bundle` from source, set up a Terraform development
    25  environment per [Terraform's own README](../../README.md) and then install
    26  this tool from within it:
    27  
    28  ```
    29  $ go install ./tools/terraform-bundle
    30  ```
    31  
    32  This will install `terraform-bundle` in `$GOPATH/bin`, which is assumed by
    33  the rest of this README to be in `PATH`.
    34  
    35  ## Usage
    36  
    37  `terraform-bundle` uses a simple configuration file to define what should
    38  be included in a bundle. This is designed so that it can be checked into
    39  version control and used by an automated build and deploy process.
    40  
    41  The configuration file format works as follows:
    42  
    43  ```hcl
    44  terraform {
    45    # Version of Terraform to include in the bundle. An exact version number
    46    # is required.
    47    version = "0.10.0"
    48  }
    49  
    50  # Define which provider plugins are to be included
    51  providers {
    52    # Include the newest "aws" provider version in the 1.0 series.
    53    aws = ["~> 1.0"]
    54  
    55    # Include both the newest 1.0 and 2.0 versions of the "google" provider.
    56    # Each item in these lists allows a distinct version to be added. If the
    57    # two expressions match different versions then _both_ are included in
    58    # the bundle archive.
    59    google = ["~> 1.0", "~> 2.0"]
    60  
    61    # Include a custom plugin to the bundle. Will search for the plugin in the
    62    # plugins directory, and package it with the bundle archive. Plugin must have
    63    # a name of the form: terraform-provider-*, and must be build with the operating
    64    # system and architecture that terraform enterprise is running, e.g. linux and amd64
    65    customplugin = ["0.1"]
    66  }
    67  
    68  ```
    69  
    70  The `terraform` block defines which version of Terraform will be included
    71  in the bundle. An exact version is required here.
    72  
    73  The `providers` block defines zero or more providers to include in the bundle
    74  along with core Terraform. Each attribute in this block is a provider name,
    75  and its value is a list of version constraints. For each given constraint,
    76  `terraform-bundle` will find the newest available version matching the
    77  constraint and include it in the bundle.
    78  
    79  It is allowed to specify multiple constraints for the same provider, in which
    80  case multiple versions can be included in the resulting bundle. Each constraint
    81  string given results in a separate plugin in the bundle, unless two constraints
    82  resolve to the same concrete plugin.
    83  
    84  Including multiple versions of the same provider allows several configurations
    85  running on the same system to share an installation of the bundle and to
    86  choose a version using version constraints within the main Terraform
    87  configuration. This avoids the need to upgrade all configurations to newer
    88  versions in lockstep.
    89  
    90  After creating the configuration file, e.g. `terraform-bundle.hcl`, a bundle
    91  zip file can be produced as follows:
    92  
    93  ```
    94  $ terraform-bundle package terraform-bundle.hcl
    95  ```
    96  
    97  By default the bundle package will target the operating system and CPU
    98  architecture where the tool is being run. To override this, use the `-os` and
    99  `-arch` options. For example, to build a bundle for on-premises Terraform
   100  Enterprise:
   101  
   102  ```
   103  $ terraform-bundle package -os=linux -arch=amd64 terraform-bundle.hcl
   104  ```
   105  
   106  The bundle file is assigned a name that includes the core Terraform version
   107  number, a timestamp to the nearest hour of when the bundle was built, and the
   108  target OS and CPU architecture. It is recommended to refer to a bundle using
   109  this composite version number so that bundle archives can be easily
   110  distinguished from official release archives and from each other when multiple
   111  bundles contain the same core Terraform version.
   112  
   113  To include custom plugins in the bundle file, create a local directory "./plugins"
   114  and put all the plugins you want to include there. Optionally, you can use the
   115  `-plugin-dir` flag to specify a location where to find the plugins. To be recognized
   116  as a valid plugin, the file must have a name of the form
   117  `terraform-provider-<NAME>-v<VERSION>`. In
   118  addition, ensure that the plugin is built using the same operating system and
   119  architecture used for Terraform Enterprise. Typically this will be `linux` and `amd64`.
   120  
   121  ## Provider Resolution Behavior
   122  
   123  Terraform's provider resolution behavior is such that if a given constraint
   124  can be resolved by any plugin already installed on the system it will use
   125  the newest matching plugin and not attempt automatic installation.
   126  
   127  Therefore if automatic installation is not desired, it is important to ensure
   128  that version constraints within Terraform configurations do not exclude all
   129  of the versions available from the bundle. If a suitable version cannot be
   130  found in the bundle, Terraform _will_ attempt to satisfy that dependency by
   131  automatic installation from the official repository. If you want
   132  `terraform init` to explicitly fail instead of contacting the repository, pass
   133  the `-get-plugins=false` option.
   134  
   135  For full details about provider resolution, see
   136  [How Terraform Works: Plugin Discovery](https://www.terraform.io/docs/extend/how-terraform-works.html#discovery).
   137  
   138  The downloaded provider archives are verified using the same signature check
   139  that is used for auto-installed plugins, using Hashicorp's release key. At
   140  this time, the core Terraform archive itself is _not_ verified in this way;
   141  that may change in a future version of this tool.
   142  
   143  ## Installing a Bundle in On-premises Terraform Enterprise
   144  
   145  If using a private install of Terraform Enterprise in an "air-gapped"
   146  environment, this tool can produce a custom Terraform version package, which
   147  includes a set of provider plugins along with core Terraform.
   148  
   149  To create a suitable bundle, use the `-os` and `-arch` options as described
   150  above to produce a bundle targeting `linux_amd64`. You can then place this
   151  archive on an HTTP server reachable by the Terraform Enterprise hosts and
   152  install it as per
   153  [Administration: Managing Terraform Versions](https://www.terraform.io/docs/enterprise/private/admin/resources.html#managing-terraform-versions).
   154  
   155  After clicking the "Add Terraform Version" button:
   156  
   157  1. In the "Version" field, enter the generated bundle version from the bundle
   158     filename, which will be of the form `N.N.N-bundleYYYYMMDDHH`.
   159  2. In the "URL" field, enter the URL where the generated bundle archive can be found.
   160  3. In the "SHA256 Checksum" field, enter the SHA256 hash of the file, which can
   161     be found by running `sha256sum <FILE>` or `shasum -a256 <FILE>`.
   162  
   163  The new bundle version can then be selected as the Terraform version for
   164  any workspace. When selected, configurations that require only plugins
   165  included in the bundle will run without trying to auto-install.
   166  
   167  Note that the above does _not_ apply to Terraform Pro, or to Terraform Premium
   168  when not running a private install. In these packages, Terraform versions
   169  are managed centrally across _all_ organizations and so custom bundles are not
   170  supported.
   171  
   172  For more information on the available Terraform Enterprise packages, see
   173  [the Terraform product site](https://www.hashicorp.com/products/terraform/).