How-to, notes, thoughts


How to run terraform task in cron under MacOS

One day, I needed to create some cloud infrastructure, but the provider didn’t have enough capacity, so I had to wait. The problem with it is that the resource is ‘free’, so once capacity becomes available, it’s quickly reassigned. As a solution, I decided to use the cron table for this task. This isn’t the typical usage of Terraform, and it took some time to figure out how to do it. Here is the working configuration that worked for me:

*/4 * * * * /opt/homebrew/bin/terraform -chdir=/Users/username/terraform_project apply -auto-approve >> /Users/username/terraform_project/cron.log 2>&1