-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
83 lines (67 loc) · 2.22 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
variable cluster_prefix {
description = "Cluster prefix"
}
variable ssh_key {
description = "Local path to SSH key"
}
variable ssh_key_pub {
description = "Local path to public SSH key"
}
variable node_count {
description = "Number of nodes to deploy"
}
variable command {
description = "Command to run on the nodes"
}
resource "openstack_compute_keypair_v2" "keypair" {
name = "${var.cluster_prefix}-keypair"
public_key = "${file(var.ssh_key_pub)}"
}
module "secgroup" {
source = "mcapuccini/rke/openstack//modules/secgroup"
name_prefix = "${var.cluster_prefix}"
allowed_ingress_tcp = [22]
}
module "network" {
source = "mcapuccini/rke/openstack//modules/network"
name_prefix = "${var.cluster_prefix}"
external_network_id = "af006ff3-d68a-4722-a056-0f631c5a0039"
}
resource "openstack_compute_instance_v2" "instance" {
count = "${var.node_count}"
name = "${var.cluster_prefix}-${format("%03d", count.index)}"
image_name = "Ubuntu 16.04 LTS (Xenial Xerus) - latest"
flavor_name = "ssc.xlarge"
key_pair = "${openstack_compute_keypair_v2.keypair.name}"
network {
name = "${module.network.network_name}"
}
security_groups = ["${module.secgroup.secgroup_name}"]
}
resource "openstack_compute_floatingip_v2" "floating_ip" {
count = 1
pool = "Public External IPv4 network"
}
resource "openstack_compute_floatingip_associate_v2" "associate_floating_ip" {
count = 1
floating_ip = "${element(openstack_compute_floatingip_v2.floating_ip.*.address, 0)}"
instance_id = "${element(openstack_compute_instance_v2.instance.*.id, 0)}"
}
resource null_resource "prepare_nodes" {
count = "${var.node_count}"
triggers {
instance_id = "${element(openstack_compute_instance_v2.instance.*.id, count.index)}-${timestamp()}"
}
provisioner "remote-exec" {
connection {
bastion_host = "${openstack_compute_floatingip_v2.floating_ip.address}"
bastion_host_key = "${file(var.ssh_key)}"
host = "${element(openstack_compute_instance_v2.instance.*.network.0.fixed_ip_v4, count.index)}"
user = "ubuntu"
private_key = "${file(var.ssh_key)}"
}
inline = [
"${var.command}"
]
}
}