-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvariables.tf
217 lines (200 loc) · 5.29 KB
/
variables.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
variable "region" {
description = "The region where the VPC will be deployed"
type = string
default = "ca-tor"
}
variable "existing_resource_group" {
description = "Existing resource group to use for the VPC."
type = string
default = ""
}
variable "existing_ssh_key" {
description = "Existing SSH key to use for the VPC."
type = string
default = ""
}
variable "allow_ip_spoofing" {
description = "Allow IP Spoofing"
type = bool
default = true
}
variable "instance_profile" {
description = "The profile to use for the instance"
type = string
default = "bx2-4x16"
}
variable "image_name" {
description = "The name of an existing OS image to use. You can list available images with the command 'ibmcloud is images'."
type = string
default = "ibm-ubuntu-22-04-2-minimal-amd64-1"
}
variable "tags" {
description = "Tags to apply to all resources"
type = list(string)
default = ["terraform101"]
}
variable "default_address_prefix" {
default = "auto"
}
variable "classic_access" { default = false }
variable "instance_count" { default = 1 }
variable "monitoring_key_secret" {}
variable "logging_key_secret" {}
variable "owner" {
description = "Value for the owner tag"
type = string
}
variable "prefix" {
description = "Prefix to use for resource names"
type = string
}
variable "super_secret_key" {
description = "Super secret key to use super secret things"
sensitive = true
type = string
}
variable "sm_instance_name" {
description = "Name of the Secrets Manager instance where the logging and monitoring secrets are stored"
type = string
}
variable "frontend_rules" {
description = "A list of security group rules to be added to the Frontend security group"
type = list(
object({
name = string
direction = string
remote = string
tcp = optional(
object({
port_max = optional(number)
port_min = optional(number)
})
)
udp = optional(
object({
port_max = optional(number)
port_min = optional(number)
})
)
icmp = optional(
object({
type = optional(number)
code = optional(number)
})
)
})
)
validation {
error_message = "Security group rules can only have one of `icmp`, `udp`, or `tcp`."
condition = (var.frontend_rules == null || length(var.frontend_rules) == 0) ? true : length(distinct(
# Get flat list of results
flatten([
# Check through rules
for rule in var.frontend_rules :
# Return true if there is more than one of `icmp`, `udp`, or `tcp`
true if length(
[
for type in ["tcp", "udp", "icmp"] :
true if rule[type] != null
]
) > 1
])
)) == 0 # Checks for length. If all fields all correct, array will be empty
}
validation {
error_message = "Security group rule direction can only be `inbound` or `outbound`."
condition = (var.frontend_rules == null || length(var.frontend_rules) == 0) ? true : length(distinct(
flatten([
# Check through rules
for rule in var.frontend_rules :
# Return false if direction is not valid
false if !contains(["inbound", "outbound"], rule.direction)
])
)) == 0
}
validation {
error_message = "Security group rule names must match the regex pattern ^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$."
condition = (var.frontend_rules == null || length(var.frontend_rules) == 0) ? true : length(distinct(
flatten([
# Check through rules
for rule in var.frontend_rules :
# Return false if direction is not valid
false if !can(regex("^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$", rule.name))
])
)) == 0
}
default = [
{
name = "inbound-http"
direction = "inbound"
remote = "0.0.0.0/0"
ip_version = "ipv4"
tcp = {
port_min = 80
port_max = 80
}
},
{
name = "inbound-https"
direction = "inbound"
remote = "0.0.0.0/0"
ip_version = "ipv4"
tcp = {
port_min = 443
port_max = 443
}
},
{
name = "inbound-ssh"
direction = "inbound"
remote = "0.0.0.0/0"
ip_version = "ipv4"
tcp = {
port_min = 22
port_max = 22
}
},
{
name = "inbound-icmp"
direction = "inbound"
remote = "0.0.0.0/0"
ip_version = "ipv4"
icmp = {
code = 0
type = 8
}
},
{
name = "http-outbound"
direction = "outbound"
remote = "0.0.0.0/0"
ip_version = "ipv4"
tcp = {
port_min = 80
port_max = 80
}
},
{
name = "https-outbound"
direction = "outbound"
remote = "0.0.0.0/0"
ip_version = "ipv4"
tcp = {
port_min = 443
port_max = 443
}
},
{
name = "iaas-services-outbound"
direction = "outbound"
remote = "161.26.0.0/16"
ip_version = "ipv4"
},
{
name = "cloud-services-outbound"
direction = "outbound"
remote = "166.8.0.0/14"
ip_version = "ipv4"
}
]
}