This workflow:
- is triggered on a push to the
main
branch. - runs on an Ubuntu runner.
- checks out the repository code.
- sets up Terraform using the HashiCorp setup action and specifies the version of Terraform to use.
- runs
terraform init
to initialize the working directory. - runs
terraform apply -auto-approve
to apply the changes in the Terraform configuration.
In this example, we also pass an environment variable TF_VAR_my_variable
to the terraform apply
command. The value of this variable is retrieved from a GitHub secret named MY_SECRET
.
name: Terraform Apply
on:
push:
branches:
- main
jobs:
terraform_apply:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_version: '1.0.4'
- name: Terraform Init
run: terraform init
- name: Terraform Apply
env:
TF_VAR_my_variable: ${{ secrets.MY_SECRET }}
run: terraform apply -auto-approve
I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I am working at Cotocus. I blog tech insights at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at I reviewed , and SEO strategies at Wizbrand.
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at PINTEREST
Rajesh Kumar at QUORA
Rajesh Kumar at WIZBRAND