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://api.buildkite.com/v2/packages/organizations/{org.slug}/registries/{registry.name}/packages.json \
  -H "Authorization: Bearer $REGISTRY_WRITE_TOKEN" \
  -F "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 your API access token used to publish/upload packages to your Terraform registry. Ensure this access token has the Write Packages REST API scope, which allows this token to publish packages to any registry your user account has access to within your Buildkite organization.

  • <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://api.buildkite.com/v2/packages/organizations/my-organization/registries/my-terraform-modules/packages.json \
  -H "Authorization: Bearer $REPLACE_WITH_MY_REGISTRY_WRITE_TOKEN" \
  -F "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 "packages.buildkite.com" {
      token = "registry-read-token"
    }
    

    where:

    • registry-read-token is your API access token used to download packages from your Debian registry. Ensure this access token has the Read Packages REST API scope, which allows this token to download packages from any registry your user account has access to within your Buildkite organization.

    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 = "packages.buildkite.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