-
Notifications
You must be signed in to change notification settings - Fork 0
/
tertemplate.sh
executable file
·88 lines (74 loc) · 1.89 KB
/
tertemplate.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env bash
set -e
echo "Create base terraform templates"
touch main.tf data.tf outputs.tf
if [ ! -f providers.tf ]
then
echo "Create providers file"
cat > providers.tf <<- PROVIDERS
provider "aws" {
region = var.region
default_tags {
tags = {
created_by = "terraform"
workspace = terraform.workspace
}
}
}
PROVIDERS
fi
if [ ! -f variables.tf ]
then
echo "Create variables file"
cat > variables.tf <<- VARIABLES
variable "region" {
description = "AWS region to create resources in"
type = string
default = "ap-southeast-2"
}
VARIABLES
fi
if [ ! -f locals.tf ]
then
echo "Create locals template file"
cat > locals.tf <<- LOCALS
locals {
}
LOCALS
fi
if [ ! -f backend.tf ]
then
echo "Create backend template file"
cat > backend.tf <<- BACKEND
terraform {
backend "remote" {
hostname = "app.terraform.io"
}
}
BACKEND
fi
echo "Create default terraform variable file"
mkdir -p tfvars && touch tfvars/main.tfvars
echo "Create .gitignore file"
cat > .gitignore <<- IGNORE
**/.terraform/**
**/.terragrunt-cache/**
IGNORE
# echo "Create terraform prehook"
# mkdir -p hooks
# tee hooks/pre-commit <<- PRECOMMIT
# #!/bin/sh -e
# base_path=`pwd`
# processed_paths=()
# for changed_file in `git diff --name-only`
# do
# changed_path=`dirname $changed_file`
# if [[ ! ${processed_paths[*]} =~ $changed_path ]]
# then
# cd $base_path/$changed_path && terraform fmt -recursive && \
# terraform init -backend=false && terraform validate
# processed_paths+=($changed_path)
# fi
# done
# PRECOMMIT
# chmod +x hooks/pre-commit