Skip to content

Commit 8c34b83

Browse files
CCM-6104 consolidating repo changes for AMET structure back to template
1 parent b2f48dd commit 8c34b83

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

scripts/terraform/terraform.lib.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,12 @@ function terraform-destroy() {
5353
# dir=[path to a directory where the command will be executed, relative to the project's top-level directory, default is '.']
5454
# opts=[options to pass to the Terraform fmt command, default is '-recursive']
5555
function terraform-fmt() {
56+
for d in "${PWD}infrastructure/"*; do
57+
if [ -d "$d" ]; then
58+
terraform fmt --recursive "${d}"
59+
fi
60+
done
5661

57-
_terraform fmt -recursive # 'dir' and 'opts' are passed to the function as environment variables, if set
5862
}
5963

6064
# Validate Terraform code.

scripts/terraform/terraform.mk

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@
44
# Custom implementation - implementation of a make target should not exceed 5 lines of effective code.
55
# In most cases there should be no need to modify the existing make targets.
66

7-
TF_ENV ?= dev
8-
STACK ?= ${stack}
9-
TERRAFORM_STACK ?= $(or ${STACK}, infrastructure/environments/${TF_ENV})
10-
dir ?= ${TERRAFORM_STACK}
11-
127
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
138
make _terraform cmd="init" \
149
dir=$(or ${terraform_dir}, ${dir}) \
@@ -46,9 +41,11 @@ clean:: # Remove Terraform files (terraform) - optional: terraform_dir|dir=[path
4641
opts=$(or ${terraform_opts}, ${opts})
4742

4843
_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]
44+
# 'TERRAFORM_STACK' is passed to the functions as environment variable
45+
TERRAFORM_STACK=$(or ${TERRAFORM_STACK}, $(or ${terraform_stack}, $(or ${STACK}, ${stack})))
4946
dir=$(or ${dir}, ${TERRAFORM_STACK})
50-
. scripts/terraform/terraform.lib.sh && \
51-
terraform-${cmd} # 'dir' and 'opts' are accessible by the function as environment variables, if set
47+
. "scripts/terraform/terraform.lib.sh"; \
48+
terraform-${cmd} # 'dir' and 'opts' are accessible by the function as environment variables, if set
5249

5350
# ==============================================================================
5451
# Quality checks - please DO NOT edit this section!
@@ -58,6 +55,31 @@ terraform-shellscript-lint: # Lint all Terraform module shell scripts @Quality
5855
file=$${file} scripts/shellscript-linter.sh
5956
done
6057

58+
terraform-sec: # TFSEC check against Terraform files - 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 fmt command, default is '-recursive'] @Quality
59+
tfsec infrastructure/terraform \
60+
--force-all-dirs \
61+
--exclude-downloaded-modules \
62+
--tfvars-file infrastructure/terraform/etc/global.tfvars \
63+
--tfvars-file infrastructure/terraform/etc/env_eu-west-2_main.tfvars \
64+
--config-file scripts/config/tfsec.yml
65+
66+
# ==============================================================================
67+
# Module tests and examples - please DO NOT edit this section!
68+
69+
terraform-example-provision-aws-infrastructure: # Provision example of AWS infrastructure @ExamplesAndTests
70+
make terraform-init
71+
make terraform-plan opts="-out=terraform.tfplan"
72+
make terraform-apply opts="-auto-approve terraform.tfplan"
73+
74+
terraform-example-destroy-aws-infrastructure: # Destroy example of AWS infrastructure @ExamplesAndTests
75+
make terraform-destroy opts="-auto-approve"
76+
77+
terraform-example-clean: # Remove Terraform example files @ExamplesAndTests
78+
dir=$(or ${dir}, ${TERRAFORM_STACK})
79+
. "scripts/terraform/terraform.lib.sh"; \
80+
terraform-clean
81+
rm -f ${TERRAFORM_STACK}/.terraform.lock.hcl
82+
6183
# ==============================================================================
6284
# Configuration - please DO NOT edit this section!
6385

@@ -71,6 +93,9 @@ ${VERBOSE}.SILENT: \
7193
clean \
7294
terraform-apply \
7395
terraform-destroy \
96+
terraform-example-clean \
97+
terraform-example-destroy-aws-infrastructure \
98+
terraform-example-provision-aws-infrastructure \
7499
terraform-fmt \
75100
terraform-init \
76101
terraform-install \

0 commit comments

Comments
 (0)