This repository has been archived by the owner on Jun 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcat_defaults.tf
167 lines (140 loc) · 4.89 KB
/
cat_defaults.tf
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# _____ ___ _____ ______ ___________ ___ _ _ _ _____ _____
# / __ \ / _ \_ _| | _ \ ___| ___/ _ \| | | | | |_ _/ ___|
# | / \// /_\ \| | | | | | |__ | |_ / /_\ \ | | | | | | \ `--.
# | | | _ || | | | | | __|| _|| _ | | | | | | | `--. \
# | \__/\| | | || | | |/ /| |___| | | | | | |_| | |____| | /\__/ /
# \____/\_| |_/\_/ |___/ \____/\_| \_| |_/\___/\_____/\_/ \____/
#
# https://patorjk.com/software/taag/#p=display&f=Doom&t=DEFAULTS
#
#
variable "region" {
type = string
description = "The default region for the application / deployment"
validation {
condition = contains([
"eu-central-1",
"eu-west-1",
"eu-west-2",
"eu-south-1",
"eu-west-3",
"eu-north-1",
"af-south-1"
], var.region)
error_message = "Invalid region provided."
}
}
variable "environment" {
type = string
description = "Will this deploy a development (dev) or production (prod) environment"
validation {
condition = contains(["dev", "prd"], var.environment)
error_message = "Stage must be either 'dev' or 'prd'."
}
}
variable "code_repo" {
type = string
description = "Points to the source code used to deploy the resources {{repo}} [{{branch}}]"
}
variable "namespace" {
type = string
description = "Used to identify which part of the application these resources belong to (auth, infra, api, web, data)"
validation {
condition = contains(["sec", "auth", "infra", "api", "web", "data"], var.namespace)
error_message = "Namespace needs to be : \"sec\", \"auth\", \"infra\", \"api\" or \"web\"."
}
}
variable "application_name" {
type = object({
short = string
long = string
})
description = "Used in naming conventions, expecting an object"
validation {
condition = length(var.application_name["short"]) <= 5
error_message = "The application_name[\"short\"] needs to be less or equal to 5 chars."
}
}
variable "nukeable" {
type = bool
description = "Can these resources be cleaned up. Will be ignored for prod environments"
}
variable "client_name" {
type = object({
short = string
long = string
})
description = "Used in naming conventions, expecting an object"
validation {
condition = length(var.client_name["short"]) <= 5
error_message = "The client_name[\"short\"] needs to be less or equal to 5 chars."
}
}
variable "purpose" {
type = string
description = "Used for cost allocation purposes"
validation {
condition = contains(["rnd", "client", "product", "self"], var.purpose)
error_message = "Purpose needs to be : \"rnd\", \"client\", \"product\", \"self\"."
}
}
variable "owner" {
type = string
description = "Used to find resources owners, expects an email address"
validation {
condition = can(regex("^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$", var.owner))
error_message = "Owner needs to be a valid email address."
}
}
variable "aws_account_id" {
type = string
description = "Needed for Guards to ensure code is being deployed to the correct account"
}
variable "tags" {
type = map(string)
description = "Tags added to all resources, this will be added to the list of mandatory tags"
}
# _____ _ _ ___ __________________ ___ _____ _ _____
# | __ \ | | |/ _ \ | ___ \ _ \ ___ \/ _ \|_ _| | / ___|
# | | \/ | | / /_\ \| |_/ / | | | |_/ / /_\ \ | | | | \ `--.
# | | __| | | | _ || /| | | | /| _ | | | | | `--. \
# | |_\ \ |_| | | | || |\ \| |/ /| |\ \| | | |_| |_| |____/\__/ /
# \____/\___/\_| |_/\_| \_|___/ \_| \_\_| |_/\___/\_____/\____/
#
# These will raise errors when the conditions are not met
data "aws_caller_identity" "current" {
provider = aws.reference
}
resource "null_resource" "tf_guard_provider_account_match" {
count = tonumber(data.aws_caller_identity.current.account_id == var.aws_account_id ? "1" : "fail")
}
# _ _ ___ ___ ________ _ _ _____
# | \ | | / _ \ | \/ |_ _| \ | | __ \
# | \| |/ /_\ \| . . | | | | \| | | \/
# | . ` || _ || |\/| | | | | . ` | | __
# | |\ || | | || | | |_| |_| |\ | |_\ \
# \_| \_/\_| |_/\_| |_/\___/\_| \_/\____/
#
#
locals {
mandatory_tags = merge(var.tags, {
"cat:application" = var.application_name.long
"cat:client" = var.client_name.long
"cat:purpose" = var.purpose
"cat:owner" = var.owner
"cat:repo" = var.code_repo
"cat:nukeable" = var.nukeable
"tf:account_id" = data.aws_caller_identity.current.account_id
"tf:caller_arn" = data.aws_caller_identity.current.arn
"tf:user_id" = data.aws_caller_identity.current.user_id
"app:region" = var.region
"app:namespace" = var.namespace
"app:environment" = var.environment
})
naming_prefix = join("-", [
var.client_name.short,
var.application_name.short,
var.environment,
var.namespace
])
}