Skip to content

Commit

Permalink
Add TF_ENV as an option to terraform.mk
Browse files Browse the repository at this point in the history
  • Loading branch information
regularfry committed Mar 1, 2024
1 parent 7c223b2 commit 9b6c998
Showing 1 changed file with 5 additions and 19 deletions.
24 changes: 5 additions & 19 deletions scripts/terraform/terraform.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
# Custom implementation - implementation of a make target should not exceed 5 lines of effective code.
# In most cases there should be no need to modify the existing make targets.

TF_ENV ?= dev
STACK ?= ${stack}
TERRAFORM_STACK ?= $(or ${STACK}, infrastructure/environments/${TF_ENV})
dir ?= ${TERRAFORM_STACK}

terraform-init: # Initialise Terraform - optional: terraform_dir|dir=[path to a directory where the command will be executed, relative to the project's top-level directory, default is one of the module variables or the example directory, if not set], terraform_opts|opts=[options to pass to the Terraform init command, default is none/empty] @Development
make _terraform cmd="init" \
dir=$(or ${terraform_dir}, ${dir}) \
Expand Down Expand Up @@ -41,8 +46,6 @@ clean:: # Remove Terraform files (terraform) - optional: terraform_dir|dir=[path
opts=$(or ${terraform_opts}, ${opts})

_terraform: # Terraform command wrapper - mandatory: cmd=[command to execute]; optional: dir=[path to a directory where the command will be executed, relative to the project's top-level directory, default is one of the module variables or the example directory, if not set], opts=[options to pass to the Terraform command, default is none/empty]
# 'TERRAFORM_STACK' is passed to the functions as environment variable
TERRAFORM_STACK=$(or ${TERRAFORM_STACK}, $(or ${terraform_stack}, $(or ${STACK}, $(or ${stack}, scripts/terraform/examples/terraform-state-aws-s3))))
dir=$(or ${dir}, ${TERRAFORM_STACK})
source scripts/terraform/terraform.lib.sh
terraform-${cmd} # 'dir' and 'opts' are accessible by the function as environment variables, if set
Expand All @@ -55,23 +58,6 @@ terraform-shellscript-lint: # Lint all Terraform module shell scripts @Quality
file=$${file} scripts/shellscript-linter.sh
done

# ==============================================================================
# Module tests and examples - please DO NOT edit this section!

terraform-example-provision-aws-infrastructure: # Provision example of AWS infrastructure @ExamplesAndTests
make terraform-init
make terraform-plan opts="-out=terraform.tfplan"
make terraform-apply opts="-auto-approve terraform.tfplan"

terraform-example-destroy-aws-infrastructure: # Destroy example of AWS infrastructure @ExamplesAndTests
make terraform-destroy opts="-auto-approve"

terraform-example-clean: # Remove Terraform example files @ExamplesAndTests
dir=$(or ${dir}, ${TERRAFORM_STACK})
source scripts/terraform/terraform.lib.sh
terraform-clean
rm -f ${TERRAFORM_STACK}/.terraform.lock.hcl

# ==============================================================================
# Configuration - please DO NOT edit this section!

Expand Down

0 comments on commit 9b6c998

Please sign in to comment.