-
Notifications
You must be signed in to change notification settings - Fork 78
/
app-instances.tf
67 lines (66 loc) · 2.36 KB
/
app-instances.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
/* Setup our aws provider */
provider "aws" {
access_key = "${var.access_key}"
secret_key = "${var.secret_key}"
region = "${var.region}"
}
resource "aws_instance" "master" {
ami = "ami-26c43149"
instance_type = "t2.micro"
security_groups = ["${aws_security_group.swarm.name}"]
key_name = "${aws_key_pair.deployer.key_name}"
connection {
user = "ubuntu"
key_file = "ssh/key"
}
provisioner "remote-exec" {
inline = [
"sudo apt-get update",
"sudo apt-get install apt-transport-https ca-certificates",
"sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D",
"sudo sh -c 'echo \"deb https://apt.dockerproject.org/repo ubuntu-trusty main\" > /etc/apt/sources.list.d/docker.list'",
"sudo apt-get update",
"sudo apt-get install -y docker-engine=1.12.0-0~trusty",
"sudo docker swarm init",
"sudo docker swarm join-token --quiet worker > /home/ubuntu/token"
]
}
provisioner "file" {
source = "proj"
destination = "/home/ubuntu/"
}
tags = {
Name = "swarm-master"
}
}
resource "aws_instance" "slave" {
count = 2
ami = "ami-26c43149"
instance_type = "t2.micro"
security_groups = ["${aws_security_group.swarm.name}"]
key_name = "${aws_key_pair.deployer.key_name}"
connection {
user = "ubuntu"
key_file = "ssh/key"
}
provisioner "file" {
source = "key.pem"
destination = "/home/ubuntu/key.pem"
}
provisioner "remote-exec" {
inline = [
"sudo apt-get update",
"sudo apt-get install apt-transport-https ca-certificates",
"sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D",
"sudo sh -c 'echo \"deb https://apt.dockerproject.org/repo ubuntu-trusty main\" > /etc/apt/sources.list.d/docker.list'",
"sudo apt-get update",
"sudo apt-get install -y docker-engine=1.12.0-0~trusty",
"sudo chmod 400 /home/ubuntu/test.pem",
"sudo scp -o StrictHostKeyChecking=no -o NoHostAuthenticationForLocalhost=yes -o UserKnownHostsFile=/dev/null -i test.pem ubuntu@${aws_instance.master.private_ip}:/home/ubuntu/token .",
"sudo docker swarm join --token $(cat /home/ubuntu/token) ${aws_instance.master.private_ip}:2377"
]
}
tags = {
Name = "swarm-${count.index}"
}
}