GitHub Action
Terraform Backend Action
v0.0.10
Latest version
This action enables to use GitHub repo as Terraform backend.
For Terraform environment with local
type backend configuration, this action downloads and uploads Terraform state file from a specified GitHub repository.
state_repo
: Repository containing Terraform state filetoken
: GitHub Token which hasread and write
permission forstate_repo
action
: Action to perform, 'download' or 'upload'sha
: 'SHA of the state file to be overwritten by upload action (required for upload)'
state_path_remote
: Path to the Terraform state file instate_repo
(terraform.tfstate
)state_path_local
: Path to the Terraform state file in GitHub Actions environment (terraform.tfstate
)commit_message
: Commit message for the upload action ('Update state file'
)committer_name
: Committer name for the upload action ('github-actions[bot]'
)committer_email
: Committer email for the upload action ('github-actions[bot]@users.noreply.github.com'
)
sha
: SHA of the original state file to use in 'upload' action
jobs:
terraform:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
- name: Initialize Terraform workdir
run: terraform init
- name: Download Terraform state file
id: terraform
uses: your-username/terraform-backend-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
state_repo: your-repo/tfstates
- name: Execute `terraform apply`
run: |
terraform plan -no-color -out .terraform/terraform.plan
terraform apply -no-color .terraform/terraform.plan
- name: Upload Terraform state file
uses: your-username/terraform-backend-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
state_repo: your-repo/tfstates
sha: ${{ steps.terraform.outputs.sha }}