-
Notifications
You must be signed in to change notification settings - Fork 0
/
variables.tf
58 lines (49 loc) · 1.64 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
# ===============
# Input Variables
# ===============
variable "vm_name" {
description = "VM Name"
type = string
default = "my-test-vm"
validation {
condition = can(regex("^[0-9a-z\\-]+$",var.vm_name))
error_message = "VM name should use lower case chars only and not use a underscore."
}
}
variable "net_name" {
description = "Network/VPC Name. Created at all Zones"
type = list(string)
default = ["my-network", "My network description."]
validation {
condition = can(regex("^[0-9a-z\\-]+$",var.net_name[0]))
error_message = "Network name should use lower case chars only and not use a underscore."
}
}
variable "subnet_list" {
description = "Subnet structure primitive"
type = list(object({
name = string,
zone = string,
prefix = string
}))
default = [
{ name = "sub1", zone = "ru-central1-a", prefix = "10.1.1.128/25" },
{ name = "sub2", zone = "ru-central1-b", prefix = "10.2.2.0/24" },
{ name = "sub3", zone = "ru-central1-c", prefix = "10.3.3.64/28" },
]
validation {
condition = length(var.subnet_list) >= 1
error_message = "At least one Subnet/Zone should be used."
}
}
data "yandex_compute_image" "vm_image" {
family = "ubuntu-2004-lts"
}
locals {
# make a list with 2nd IPv4 address on each subnet
dns_base = [ for el in var.subnet_list : cidrhost(el.prefix,2) ]
# build a dns server list (dns_set) for each subnet where:
# 1st element in the list -> local active DNS server
# 2nd and subsequent elements in the list -> dns_base exclude the active local DNS server IP
dns_set = [ for el in local.dns_base : concat( [el], tolist(setsubtract(local.dns_base, [el]))) ]
}