-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbastion.tf
125 lines (113 loc) · 3.81 KB
/
bastion.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
locals {
bastion_subnet_id = var.use_existing_vcn ? var.bastion_subnet_id : element(concat(oci_core_subnet.public-subnet.*.id, [""]), 0)
}
data "template_file" "bastion_config" {
template = file("config.bastion")
vars = {
key = tls_private_key.ssh.private_key_pem
}
}
resource "oci_core_instance" "bastion" {
depends_on = [oci_core_cluster_network.cluster_network, oci_core_subnet.public-subnet]
availability_domain = var.bastion_ad
compartment_id = var.compartment_ocid
shape = var.bastion_shape
display_name = "${local.cluster_name}-bastion"
metadata = {
ssh_authorized_keys = "${var.ssh_public_key}\n${tls_private_key.ssh.public_key_openssh}"
user_data = base64encode(data.template_file.bastion_config.rendered)
}
source_details {
source_id = var.use_standard_image ? var.bastion_image[var.region] : var.custom_bastion_image
source_type = "image"
}
create_vnic_details {
subnet_id = local.bastion_subnet_id
}
provisioner "file" {
source = "playbooks"
destination = "/home/opc/"
connection {
host = oci_core_instance.bastion.public_ip
type = "ssh"
user = "opc"
private_key = tls_private_key.ssh.private_key_pem
}
}
provisioner "file" {
content = templatefile("${path.module}/inventory.tpl", {
bastion_name = oci_core_instance.bastion.display_name,
bastion_ip = oci_core_instance.bastion.private_ip,
compute = zipmap(data.oci_core_instance.cluster_instances.*.display_name,
data.oci_core_instance.cluster_instances.*.private_ip),
public_subnet = data.oci_core_subnet.public_subnet.cidr_block,
private_subnet = data.oci_core_subnet.private_subnet.cidr_block,
filesystem = var.filesystem,
use_beegfs_over_rdma = var.use_beegfs_over_rdma,
metadata_node_count = var.metadata_node_count,
storage_node_count = var.storage_node_count,
io500 = var.io500,
})
destination = "/home/opc/playbooks/inventory"
connection {
host = oci_core_instance.bastion.public_ip
type = "ssh"
user = "opc"
private_key = tls_private_key.ssh.private_key_pem
}
}
provisioner "file" {
content = tls_private_key.ssh.private_key_pem
destination = "/home/opc/.ssh/cluster.key"
connection {
host = oci_core_instance.bastion.public_ip
type = "ssh"
user = "opc"
private_key = tls_private_key.ssh.private_key_pem
}
}
provisioner "file" {
content = tls_private_key.ssh.private_key_pem
destination = "/home/opc/.ssh/id_rsa"
connection {
host = oci_core_instance.bastion.public_ip
type = "ssh"
user = "opc"
private_key = tls_private_key.ssh.private_key_pem
}
}
provisioner "file" {
content = join("\n", data.oci_core_instance.cluster_instances.*.private_ip)
destination = "/tmp/hosts"
connection {
host = oci_core_instance.bastion.public_ip
type = "ssh"
user = "opc"
private_key = tls_private_key.ssh.private_key_pem
}
}
provisioner "file" {
source = "configure.sh"
destination = "/tmp/configure.sh"
connection {
host = oci_core_instance.bastion.public_ip
type = "ssh"
user = "opc"
private_key = tls_private_key.ssh.private_key_pem
}
}
provisioner "remote-exec" {
inline = [
"chmod 600 /home/opc/.ssh/cluster.key",
"chmod 600 /home/opc/.ssh/id_rsa",
"chmod a+x /tmp/configure.sh",
"/tmp/configure.sh"
]
connection {
host = oci_core_instance.bastion.public_ip
type = "ssh"
user = "opc"
private_key = tls_private_key.ssh.private_key_pem
}
}
}