This is one of a suite of Terraform related actions - find them at dflook/terraform-github-actions.
Creates a new Terraform workspace. If the workspace already exists, succeeds without doing anything.
path
Path to the Terraform root module
workspace
Terraform workspace to create
backend_config
List of terraform backend config values, one per line.
with:
backend_config: token=$
backend_config_file
List of Terraform backend config files to use, one per line. Paths should be relative to the GitHub Actions workspace
with:
backend_config_file: prod.backend.tfvars
GITHUB_DOT_COM_TOKEN
This is used to specify a token for GitHub.com when the action is running on a GitHub Enterprise instance. This is only used for downloading OpenTofu binaries from GitHub.com. If this is not set, an unauthenticated request will be made to GitHub.com to download the binary, which may be rate limited.
TERRAFORM_CLOUD_TOKENS
API tokens for cloud hosts, of the form <host>=<token>
. Multiple tokens may be specified, one per line.
These tokens may be used with the remote
backend and for fetching required modules from the registry.
e.g:
env:
TERRAFORM_CLOUD_TOKENS: app.terraform.io=$
With other registries:
env:
TERRAFORM_CLOUD_TOKENS: |
app.terraform.io=$
terraform.example.com=$
TERRAFORM_SSH_KEY
A SSH private key that Terraform will use to fetch git module sources.
This should be in PEM format.
For example:
env:
TERRAFORM_SSH_KEY: $
TERRAFORM_PRE_RUN
A set of commands that will be ran prior to terraform init
. This can be used to customise the environment before running Terraform.
The runtime environment for these actions is subject to change in minor version releases. If using this environment variable, specify the minor version of the action to use.
The runtime image is currently based on debian:bullseye
, with the command run using bash -xeo pipefail
.
For example:
env:
TERRAFORM_PRE_RUN: |
# Install latest Azure CLI
curl -skL https://aka.ms/InstallAzureCLIDeb | bash
# Install postgres client
apt-get install -y --no-install-recommends postgresql-client
TERRAFORM_HTTP_CREDENTIALS
Credentials that will be used for fetching modules sources with git::http://
, git::https://
, http://
& https://
schemes.
Credentials have the format <host>=<username>:<password>
. Multiple credentials may be specified, one per line.
Each credential is evaluated in order, and the first matching credentials are used.
Credentials that are used by git (git::http://
, git::https://
) allow a path after the hostname.
Paths are ignored by http://
& https://
schemes.
For git module sources, a credential matches if each mentioned path segment is an exact match.
For example:
env:
TERRAFORM_HTTP_CREDENTIALS: |
example.com=dflook:$
github.com/dflook/terraform-github-actions.git=dflook-actions:$
github.com/dflook=dflook:$
github.com=graham:$
This example creates a workspace named after the git branch when the associated PR is opened or updated, and deploys a test environment to it.
name: Run integration tests
on: [pull_request]
jobs:
integration:
runs-on: ubuntu-latest
name: Run integration tests
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Use branch workspace
uses: dflook/terraform-new-workspace@v1
with:
path: terraform
workspace: $
- name: Deploy test infrastrucutre
uses: dflook/terraform-apply@v1
with:
path: terraform
workspace: $
auto_approve: true