Riaan's SysAdmin Blog

My tips, howtos, gotchas, snippets and stuff. Use at your own risk!

Terraform

Terraform with a Makefile

To streamline Terraform use you can use the typical make command. Below is a very simple Makefile and of course it can be built out for testing steps etc...

Makefile

➜ cat Makefile 

init:
        terraform init

validate:
        terraform fmt -recursive
        terraform validate

plan:
        terraform validate
        terraform plan -var-file="variables.tfvars"

apply:
        terraform apply -var-file="variables.tfvars" --auto-approve

destroy:
        terraform destroy -var-file="variables.tfvars"

all: validate plan apply

Example command

❯ make init
terraform init

Initializing the backend...

Initializing provider plugins...
- Reusing previous version of oracle/oci from the dependency lock file
- Using previously-installed oracle/oci v5.2.1

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.

admin

Bio Info for Riaan