-
Notifications
You must be signed in to change notification settings - Fork 0
/
variables.tf
208 lines (193 loc) · 5.27 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
variable "ibmcloud_api_key" {
description = "IBM Cloud API key needed to deploy the resources"
type = string
}
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
default = ""
}
variable "region" {
description = "IBM Cloud region where resources will be deployed"
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 "number_of_addresses" {
description = "Number of IPs to assign for each subnet."
type = number
default = 128
}
variable "owner" {
description = "Owner declaration for resource tags. e.g. 'ryantiffany'"
type = string
}
variable "existing_ssh_key" {
description = "Name of an existing SSH key to use for the VPC. If not set, a new SSH key will be created."
type = string
default = ""
}
variable "existing_cos_instance" {
description = "Name of an existing Object Storage instance to use for the VPC Flowlog collectors. If not set, a new Object Storage instance will be created."
type = string
default = ""
}
variable "controller_node_count" {
description = "Number of microk8s controller nodes to create."
type = number
default = 1
}
variable "worker_node_count" {
description = "Number of microk8s worker nodes to create."
type = number
default = 3
}
variable "frontend_rules" {
description = "A list of security group rules to be added to the microk8s 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-cluster-join"
direction = "inbound"
remote = "0.0.0.0/0"
ip_version = "ipv4"
tcp = {
port_min = 25000
port_max = 25000
}
},
{
name = "inbound-icmp"
direction = "inbound"
remote = "0.0.0.0/0"
ip_version = "ipv4"
icmp = {
code = 0
type = 8
}
},
{
name = "microk8s-api-inbound"
direction = "inbound"
remote = "0.0.0.0/0"
ip_version = "ipv4"
tcp = {
port_min = 16443
port_max = 16443
}
},
{
name = "services-outbound"
direction = "outbound"
remote = "161.26.0.0/16"
ip_version = "ipv4"
},
{
name = "all-outbound"
direction = "outbound"
remote = "0.0.0.0/0"
ip_version = "ipv4"
}
]
}