-
Notifications
You must be signed in to change notification settings - Fork 12
/
BareMetal.tf
114 lines (96 loc) · 3.62 KB
/
BareMetal.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
resource "equinix_metal_project" "new_project" {
count = var.equinix_metal_create_project ? 1 : 0
name = (var.equinix_metal_project_name != "") ? var.equinix_metal_project_name : format("openstack-%s", random_id.cloud.b64_url)
organization_id = var.equinix_metal_organization_id
}
provider "equinix" {
auth_token = var.equinix_metal_auth_token
}
locals {
ssh_key_name = "metal-key"
metal_project_id = var.equinix_metal_create_project ? equinix_metal_project.new_project[0].id : var.equinix_metal_project_id
}
resource "tls_private_key" "ssh_key_pair" {
algorithm = "RSA"
rsa_bits = 4096
}
resource "equinix_metal_ssh_key" "ssh_pub_key" {
name = random_id.cloud.b64_url
public_key = chomp(tls_private_key.ssh_key_pair.public_key_openssh)
}
resource "local_file" "cluster_private_key_pem" {
content = chomp(tls_private_key.ssh_key_pair.private_key_pem)
filename = pathexpand(format("%s", local.ssh_key_name))
file_permission = "0600"
}
resource "local_file" "cluster_public_key" {
content = chomp(tls_private_key.ssh_key_pair.public_key_openssh)
filename = pathexpand(format("%s.pub", local.ssh_key_name))
file_permission = "0600"
}
resource "equinix_metal_device" "controller" {
hostname = "controller"
tags = ["openstack-${random_id.cloud.b64_url}"]
operating_system = "ubuntu_18_04"
plan = var.equinix_metal_controller_type
connection {
host = self.access_public_ipv4
type = "ssh"
user = "root"
private_key = local_file.cluster_private_key_pem.content
}
user_data = "#cloud-config\n\nssh_authorized_keys:\n - \"${local_file.cluster_public_key.content}\""
project_id = local.metal_project_id
billing_cycle = "hourly"
# ip_address {
# type = "public_ipv4"
# cidr = "29"
# }
}
resource "equinix_metal_device" "dashboard" {
hostname = "dashboard"
tags = ["openstack-${random_id.cloud.hex} "]
operating_system = "ubuntu_18_04"
plan = var.equinix_metal_dashboard_type
connection {
host = self.access_public_ipv4
type = "ssh"
user = "root"
private_key = file(local_file.cluster_private_key_pem)
}
user_data = "#cloud-config\n\nssh_authorized_keys:\n - \"${local_file.cluster_public_key.content}\""
project_id = local.metal_project_id
billing_cycle = "hourly"
}
resource "equinix_metal_device" "compute-x86" {
hostname = format("compute-x86-%02d", count.index)
tags = ["openstack-${random_id.cloud.hex} "]
count = var.openstack_compute-x86_count
operating_system = "ubuntu_18_04"
plan = var.equinix_metal_compute-x86_type
connection {
host = self.access_public_ipv4
type = "ssh"
user = "root"
private_key = file(local_file.cluster_private_key_pem)
}
user_data = "#cloud-config\n\nssh_authorized_keys:\n - \"${local_file.cluster_public_key.content}\""
project_id = local.metal_project_id
billing_cycle = "hourly"
}
resource "equinix_metal_device" "compute-arm" {
hostname = format("compute-arm-%02d", count.index)
tags = ["openstack-${random_id.cloud.hex} "]
count = var.openstack_compute-arm_count
operating_system = "ubuntu_18_04"
plan = var.equinix_metal_compute-arm_type
connection {
host = self.access_public_ipv4
type = "ssh"
user = "root"
private_key = file(local_file.cluster_private_key_pem)
}
user_data = "#cloud-config\n\nssh_authorized_keys:\n - \"${local_file.cluster_public_key.content}\""
project_id = local.metal_project_id
billing_cycle = "hourly"
}