-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.tf
56 lines (47 loc) · 1.62 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
provider "aws" {
region = "${var.region}"
}
module "rancher_vpc" {
source = "./modules/aws/vpc"
name = "rancher"
}
module "rancher_server" {
source = "./modules/aws/server"
name = "rancher-server"
security_groups = ["${module.rancher_vpc.rancher_server_security_group}"]
subnet_id = "${module.rancher_vpc.rancher_subnet_id}"
keypair_name = "${var.keypair_name}"
instance_type = "${var.instance_type}"
user_data = "#!/bin/sh
apt-get update
apt-get install -y docker.io
sudo docker run -d --restart=unless-stopped -p 8080:8080 rancher/server"
}
module "rancher_agent" {
source = "./modules/aws/server"
instance_count = "${var.agent_count}"
name = "rancher-agent"
security_groups = ["${module.rancher_vpc.rancher_agent_security_group}", "${module.rancher_vpc.gocd_security_group}"]
subnet_id = "${module.rancher_vpc.rancher_subnet_id}"
keypair_name = "${var.keypair_name}"
instance_type = "${var.instance_type}"
}
data "template_file" "agent-userdata" {
template = "${file("data/user-data.agent")}"
vars {
server_ip_address = "${element(split(",", module.rancher_server.public_ip), 0)}"
}
}
resource "null_resource" "configure_rancher_hosts" {
count = "${var.agent_count}"
connection {
type = "ssh"
agent = false
user = "ubuntu"
host = "${element(split(",", module.rancher_agent.public_ip), count.index)}"
private_key = "${file("${var.key_file}")}"
}
provisioner "remote-exec" {
inline = ["${data.template_file.agent-userdata.rendered}"]
}
}