Terraform

Buildkite Packages provides registry support for Terraform modules.

Once your Terraform registry has been created, you can publish/upload modules (generated from your application's build) to this registry via the curl command presented on your Terraform registry's details page.

To view and copy this curl command:

  1. Select Packages in the global navigation to access the Registries page.
  2. Select your Terraform registry on this page.
  3. Select Publish a Terraform Package and in the resulting dialog, use the copy icon at the top-right of the code box to copy this curl command and submit it to publish a module to your Terraform registry.

This command provides:

  • The specific URL to publish a module to your specific Terraform registry in Buildkite.
  • The API write token (generated by Buildkite Packages) required to publish modules to your Terraform registry.

Publish a module

The following curl command (modified as required before submitting) describes the process above to publish a module to your Terraform registry:

curl -X POST https://buildkitepackages.com/api/v1/repos/{org.slug}/{registry.name}/packages.json \
  -H "Authorization: Bearer $REGISTRY_WRITE_TOKEN" \
  -F "package[package_file]=@<path_to_file>"

where:

  • {org.slug} can be obtained from the end of your Buildkite URL, after accessing Pipelines in the global navigation of your organization in Buildkite.
  • {registry.name} is the name of your Terraform registry.
  • $REGISTRY_WRITE_TOKEN is the Buildkite Packages-generated API token required to publish/upload modules to your Terraform registry.

  • <path_to_file> is the full path required to the module file. If the file is located in the same directory that this command is running from, then no path is required.

For example, to upload the file my-terraform-module-1.0.1.tgz from the current directory to the My-Terraform-modules registry in the My organization Buildkite organization, run the curl command:

curl -X POST https://buildkitepackages.com/api/v1/repos/my-organization/my-terraform-modules/packages.json \
  -H "Authorization: Bearer $REPLACE_WITH_MY_REGISTRY_WRITE_TOKEN" \
  -F "package[package_file]=@my-terraform-module-1.0.1.tgz"

Access a module's details

A Terraform module's details can be accessed from this registry using the Packages section of your Terraform registry page.

To access your Terraform module's details page:

  1. Select Packages in the global navigation to access the Registries page.
  2. Select your Terraform registry on this page.
  3. On your Terraform registry page, select the module within the Packages section. The module's details page is displayed.

The module's details page provides the following information in the following sections:

  • Installation: the installation instructions.
  • Contents (where available): a list of directories and files contained within the module.
  • Details: a list of checksum values for this module—MD5, SHA1, SHA256, and SHA512.
  • About this version: a brief (metadata) description about the module.
  • Details: details about:

    • the name of the module (typically the file name excluding any version details and extension).
    • the module version.
    • the registry the module is located in.
    • the module's visibility—whether the module is Private and requires authentication to access, or is publicly accessible.
    • the distribution name / version.
    • additional optional metadata contained within the module, such as a homepage, licenses, etc.
  • Last pushed: the date when the last module was uploaded to the registry.

  • Total files: the total number of files (and directories) within the module.

  • Dependencies: the number of dependency modules required by this module.

  • Package size: the storage size (in bytes) of this module.

  • Downloads: the number of times this module has been downloaded.

Downloading a module

A Terraform module can be downloaded from the module's details page.

To download a module:

  1. Access the module's details.
  2. Select Download.

Installing a module

A Terraform module can be installed using code snippet details provided on the package's details page.

To install a module:

  1. Access the module's details.
  2. Ensure the Installation > Installation instructions section is displayed.
  3. If your Terraform registry is private, copy the top section of the code snippet, and paste it into your ~/.terraformrc configuration file. This code snippet is based on the format:

    credentials "buildkitepackages.com" {
      token = "registry-read-token"
    }
    

    where:

    • registry-read-token is the Buildkite Packages-generated API token required to download packages from your Debian registry.

    Note: This step only needs to be conducted once for the life of your Terraform registry.

  4. Copy the lower section of the code snippet, and paste it into your Terraform file. This code snippet is based on the format:

    module "org_slug___registry_name_module_name" {
      source = "buildkitepackages.com/org-slug---registry-name/ksh/all"
      version = "version.number"
    }
    

    where:

    • org_slug can be derived from the end of your Buildkite URL (in snake_case), after accessing Pipelines in the global navigation of your organization in Buildkite.
    • registry_name is the name of your Terraform registry (in snake_case).
    • module_name is the name of your Terraform module.
    • org-slug can be obtained from the end of your Buildkite URL (in kebab-case), after accessing Pipelines in the global navigation of your organization in Buildkite.
    • registry-name is the name of your Terraform registry (in kebab-case).
    • version.number is the version of your Terraform module.
  5. Run the Terraform command:

    terraform init