-
Notifications
You must be signed in to change notification settings - Fork 448
/
main.tf
68 lines (63 loc) · 1.81 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
resource "oci_identity_compartment" "_" {
name = var.name
description = var.name
enable_delete = true
}
locals {
compartment_id = oci_identity_compartment._.id
}
data "oci_identity_availability_domains" "_" {
compartment_id = local.compartment_id
}
data "oci_core_images" "_" {
compartment_id = local.compartment_id
shape = var.shape
operating_system = "Canonical Ubuntu"
operating_system_version = "22.04"
#operating_system = "Oracle Linux"
#operating_system_version = "7.9"
}
resource "oci_core_instance" "_" {
for_each = local.nodes
display_name = each.value.node_name
availability_domain = data.oci_identity_availability_domains._.availability_domains[var.availability_domain].name
compartment_id = local.compartment_id
shape = var.shape
shape_config {
memory_in_gbs = var.memory_in_gbs_per_node
ocpus = var.ocpus_per_node
}
source_details {
source_id = data.oci_core_images._.images[0].id
source_type = "image"
}
create_vnic_details {
subnet_id = oci_core_subnet._.id
private_ip = each.value.ip_address
}
metadata = {
ssh_authorized_keys = join("\n", local.authorized_keys)
user_data = data.cloudinit_config._[each.key].rendered
}
connection {
host = self.public_ip
user = "ubuntu"
private_key = tls_private_key.ssh.private_key_pem
}
provisioner "remote-exec" {
inline = [
"tail -f /var/log/cloud-init-output.log &",
"cloud-init status --wait >/dev/null",
]
}
}
locals {
nodes = {
for i in range(1, 1 + var.how_many_nodes) :
i => {
node_name = format("node%d", i)
ip_address = format("10.0.0.%d", 10 + i)
role = i == 1 ? "controlplane" : "worker"
}
}
}