-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvariables.tf
197 lines (181 loc) · 5.36 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
variable "existing_resource_group" {
description = "Resource group to use for all deployed resources. If not specified, a new one will be created."
type = string
}
variable "project_prefix" {
description = "Prefix to be added to all deployed resources. If none provided, one will be automatically generated."
type = string
}
variable "owner" {
description = "Project owner or identifier. This is used as a tag on all supported resources."
type = string
}
variable "region" {
description = "IBM Cloud Region where resources will be deployed. If not specified, one will be randomly selected. To see available regions, run 'ibmcloud is regions'."
type = string
}
variable "existing_cos_instance" {
description = "The name of an existing COS instance to use. If not specified, a new instance will be created."
type = string
default = ""
}
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_ssh_key" {
description = "The name of an existing SSH key to use. If not specified, a new key will be created."
type = string
default = ""
}
variable "instance_profile" {
description = "The name of an existing instance profile to use. You can list available instance profiles with the command 'ibmcloud is instance-profiles'."
type = string
default = "cx2-2x4"
}
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-1-minimal-amd64-3"
}
variable "allow_ip_spoofing" {
description = "Allow IP spoofing on the bastion instance primary interface."
type = bool
default = false
}
variable "metadata_service_enabled" {
description = "Enable the metadata service on the bastion instance."
type = bool
default = true
}
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-vpn-udp"
direction = "inbound"
remote = "0.0.0.0/0"
ip_version = "ipv4"
udp = {
port_min = 51280
port_max = 51280
}
},
{
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 = "all-outbound"
direction = "outbound"
remote = "0.0.0.0/0"
ip_version = "ipv4"
}
]
}