-
Notifications
You must be signed in to change notification settings - Fork 11
/
00-aws-infra.tf
103 lines (86 loc) · 2.1 KB
/
00-aws-infra.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
##Amazon Infrastructure
provider "aws" {
region = "${var.aws_region}"
}
##Create swarm security group
resource "aws_security_group" "swarm_sg" {
name = "swarm_sg"
description = "Allow all inbound traffic necessary for Swarm"
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 2377
to_port = 2377
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 7946
to_port = 7946
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 7946
to_port = 7946
protocol = "udp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 4789
to_port = 4789
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = [
"0.0.0.0/0",
]
}
tags {
Name = "swarm_sg"
}
}
##Find latest Ubuntu 16.04 AMI
data "aws_ami" "ubuntu" {
most_recent = true
filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-*"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
owners = ["099720109477"] # Canonical
}
##Create Swarm Master Instance
resource "aws_instance" "swarm-master" {
depends_on = ["aws_security_group.swarm_sg"]
ami = "${data.aws_ami.ubuntu.id}"
instance_type = "${var.aws_instance_size}"
vpc_security_group_ids = ["${aws_security_group.swarm_sg.id}"]
key_name = "${var.aws_key_name}"
tags {
Name = "swarm-master"
}
}
##Create AWS Swarm Workers
resource "aws_instance" "aws-swarm-members" {
depends_on = ["aws_security_group.swarm_sg"]
ami = "${data.aws_ami.ubuntu.id}"
instance_type = "${var.aws_instance_size}"
vpc_security_group_ids = ["${aws_security_group.swarm_sg.id}"]
key_name = "${var.aws_key_name}"
count = "${var.aws_worker_count}"
tags {
Name = "swarm-member-${count.index}"
}
}