Terraform GitHub action CronJob

Schedule GitHub action workflow for specific time (UTC based)

Download Terraform
Extract zip file
→ run terraform.exe
check terraform version
terraform --version

Download terraform code from here

Create Account on Terraform cloud
image.png

Click on Free Account
image.png

Verify email address
image.png

Create Organization
image.png

image.png

Create API- Driven Workspace
image.png

Add Details
image.png
Work Space Created
image.png

Go to variable Section add digital Ocean Token according name in main.tf
image.png
go to settings
image.png

Select auto apply & save settings
image.png

Generate API Token
click on above link
create user token
image.png

Copy and save the token
image.png

Copy workspace id
image.png

Add this secrets in GitHub actions
image.png

ORG_NAME = “organization name of terraform cloud”
TERRAFORM_API_TOKEN = ”Token of Terraform cloud”
TF_VAR_DIGITALOCEAN_TOKEN = “digital ocean token”
WORKSPACE_ID =” workspace id “
WORKSPACE_NAME = “ name of workspace”

Workflow file
schedule based on UTC time period

Go to this website for utc time conversion →
Go to this website for cronjob expression →

Uncomment this part in workflow file to schedule GitHub action
Example
image.png
in above screenshot 5:56 is UTC time

make cronjob expression for it
Type like below screenshot
image.png

schedule:
- cron: '56 5* * *' # Schedule for 11:26 AM daily

Run Terraform cloud Locally
Same code as GitHub
In terminal Configure Terraform Cloud
terraform init -reconfigure
Add Yes in Terminal
Add token in terminal
Plan terraform
terraform plan

Apply Terraform
terraform apply



Single Project → Multiple Environment (Workspace)
image.png

Create Work Space
image.png
This link can't be embedded.
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.