-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvariables.tf
167 lines (155 loc) · 4.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
variable "ibmcloud_api_key" {
description = "IBM Cloud API key for deployed resources."
type = string
sensitive = true
}
variable "existing_resource_group" {
description = "Name of an existing Resource Group to use for resources. If not set, a new Resource Group will be created."
type = string
}
variable "region" {
description = "IBM Cloud region where resources will be deployed"
type = string
}
variable "project_prefix" {
description = "Prefix to use for resource names"
type = string
default = ""
}
variable "existing_ssh_key" {
description = "Name of an existing SSH key in the region. If not set, a new SSH key will be created."
type = string
}
variable "classic_access" {
description = "Allow classic access to the VPC."
type = bool
default = false
}
variable "default_address_prefix" {
description = "The address prefix to use for the VPC. Default is set to auto."
type = string
default = "auto"
}
variable "existing_cos_instance" {
description = "Name of an existing COS instance to use for resources. If not set, a new COS instance will be created."
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 = "dns-outbound"
direction = "outbound"
remote = "0.0.0.0/0"
ip_version = "ipv4"
udp = {
port_min = 53
port_max = 53
}
}
]
}