Terraform
Acceptance Tests: Continuous Integration
GitHub Actions Workflow
If using GitHub, run acceptance testing via GitHub Actions. Other continuous integration runners are also supported.
Ensure the GitHub Organization settings for GitHub
Actions
and GitHub Repository settings for GitHub
Actions
allows running workflows and allows the actions/checkout
, actions/setup-go
,
and hashicorp/setup-terraform
actions.
Create a GitHub Actions
workflow
file, such as .github/workflows/test.yaml
, that does the following:
- Runs when pull requests are submitted or on other events as appropriate.
- Uses
actions/checkout
to checkout the provider codebase. - Uses
actions/setup-go
to install Go. - Uses
hashicorp/setup-terraform
to install Terraform CLI. - Runs the
go test
command with the appropriate environment variables and flags.
Use the
matrix
strategy for more advanced configuration, such as running acceptance testing
against multiple Terraform CLI versions.
The following example workflow runs acceptance testing for the provider using
the latest patch versions of the Go version in the go.mod
file and Terraform
CLI 1.11:
---
name: Terraform Provider Tests
on:
pull_request:
paths:
- '.github/workflows/test.yaml'
- '**.go'
permissions:
# Permission for checking out code
contents: read
jobs:
acceptance:
name: Acceptance Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
- uses: hashicorp/setup-terraform@v2
with:
terraform_version: '1.11.*'
terraform_wrapper: false
- run: go test -v -cover ./...
env: TF_ACC: '1'r
unit:
name: Unit Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
- run: go test -v -cover ./... ```
The following example workflow runs acceptance testing for the provider using
the latest patch versions of Go version in the go.mod
file and Terraform CLI
0.12 through 1.11:
name: Terraform Provider Tests
on:
pull_request:
paths:
- '.github/workflows/test.yaml'
- '**.go'
permissions:
# Permission for checking out code
contents: read
jobs:
acceptance:
name: Acceptance Tests (Terraform ${{ matrix.terraform-version }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
terraform-version:
- '0.12.*'
- '0.13.*'
- '0.14.*'
- '0.15.*'
- '1.0.*'
- '1.1.*'
- '1.2.*'
- '1.3.*'
- '1.4.*'
- '1.5.*'
- '1.6.*'
- '1.7.*'
- '1.8.*'
- '1.9.*'
- '1.10.*'
- '1.11.*'
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
- uses: hashicorp/setup-terraform@v2
with:
terraform_version: ${{ matrix.terraform-version }}
terraform_wrapper: false
- run: go test -v -cover ./...
env:
TF_ACC: '1'
unit:
name: Unit Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
- run: go test -v -cover ./...