generated from equinix-labs/terraform-equinix-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.tf
99 lines (92 loc) · 3.38 KB
/
main.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
data "equinix_network_device_type" "this" {
name = "Nginx"
}
data "equinix_network_device_platform" "this" {
device_type = data.equinix_network_device_type.this.code
flavor = var.platform
}
data "equinix_network_device_software" "this" {
device_type = data.equinix_network_device_type.this.code
packages = [var.software_package]
stable = true
most_recent = true
}
resource "equinix_network_device" "non_cluster" {
count = !var.cluster.enabled ? 1 : 0
lifecycle {
ignore_changes = [version, core_count]
precondition {
condition = length(var.hostname) >= 2 && length(var.hostname) <= 10
error_message = "Device hostname should consist of 2 to 10 characters."
}
}
self_managed = true
name = var.name
hostname = var.hostname
type_code = data.equinix_network_device_type.this.code
package_code = var.software_package
version = data.equinix_network_device_software.this.version
core_count = data.equinix_network_device_platform.this.core_count
metro_code = var.metro_code
account_number = var.account_number
term_length = var.term_length
interface_count = var.interface_count
notifications = var.notifications
mgmt_acl_template_uuid = var.mgmt_acl_template_uuid != "" ? var.mgmt_acl_template_uuid : null
additional_bandwidth = var.additional_bandwidth > 0 ? var.additional_bandwidth : null
ssh_key {
username = var.ssh_key.userName
key_name = var.ssh_key.keyName
}
dynamic "secondary_device" {
for_each = var.secondary.enabled ? [1] : []
content {
name = "${var.name}-secondary"
hostname = var.secondary.hostname
metro_code = var.secondary.metro_code
account_number = var.secondary.account_number
notifications = var.notifications
mgmt_acl_template_uuid = try(var.secondary.mgmt_acl_template_uuid, null)
ssh_key {
username = var.ssh_key.userName
key_name = var.ssh_key.keyName
}
}
}
}
resource "equinix_network_device" "cluster" {
count = var.cluster.enabled ? 1 : 0
lifecycle {
ignore_changes = [version, core_count]
}
self_managed = true
name = var.name
type_code = data.equinix_network_device_type.this.code
package_code = var.software_package
version = data.equinix_network_device_software.this.version
core_count = data.equinix_network_device_platform.this.core_count
metro_code = var.metro_code
account_number = var.account_number
term_length = var.term_length
interface_count = var.interface_count
notifications = var.notifications
mgmt_acl_template_uuid = var.mgmt_acl_template_uuid != "" ? var.mgmt_acl_template_uuid : null
additional_bandwidth = var.additional_bandwidth > 0 ? var.additional_bandwidth : null
ssh_key {
username = var.ssh_key.userName
key_name = var.ssh_key.keyName
}
cluster_details {
cluster_name = var.cluster.name
node0 {
vendor_configuration {
hostname = var.cluster.node0_vendor_configuration_hostname
}
}
node1 {
vendor_configuration {
hostname = var.cluster.node1_vendor_configuration_hostname
}
}
}
}