-
Notifications
You must be signed in to change notification settings - Fork 0
/
webodm.tf
177 lines (177 loc) · 4.72 KB
/
webodm.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#-------------------------------
# AWS Provider
#-------------------------------
provider "aws" {
region = var.aws_region
default_tags {
tags = {
Name = var.repo_name # Important to use capital "N" for Name as this will automatically display in the consoles default tag
Owner = var.repo_owner
Project = var.project
}
}
}
#-------------------------------
# S3 Remote State
# Comment out this section if testing locally and do not want to use the S3 bucket
# Remove the leading # to disable the backend
#-------------------------------
#/* Begin comment block - only need to remove the leading "#"
terraform {
backend "s3" {
key = "terraform.tfstate"
region = "us-east-1"
}
}
#End of comment block */
#-------------------------------
# VPC
#-------------------------------
resource "aws_vpc" "odm" {
cidr_block = var.vpc_cidr_block
}
resource "aws_subnet" "odm_public_subnet" {
vpc_id = aws_vpc.odm.id
cidr_block = var.public_subnet
availability_zone = var.avail_zone
}
#-------------------------------
# Internet Gateway
#-------------------------------
resource "aws_internet_gateway" "odm" {
vpc_id = aws_vpc.odm.id
}
#-------------------------------
# Route Tables
#-------------------------------
resource "aws_route_table" "public_rt" {
vpc_id = aws_vpc.odm.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.odm.id
}
route {
ipv6_cidr_block = "::/0"
gateway_id = aws_internet_gateway.odm.id
}
}
resource "aws_route_table_association" "public_1_rt_a" {
subnet_id = aws_subnet.odm_public_subnet.id
route_table_id = aws_route_table.public_rt.id
}
#-------------------------------
# Security Group
#-------------------------------
resource "aws_security_group" "odm" {
name = "SSH and ODM"
vpc_id = aws_vpc.odm.id
/* Add "#" to the beginning of this line to open port 22 if needed.
ingress {
description = "SSH"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
} # */
ingress {
description = "WebODM"
from_port = 8000
to_port = 8000
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
description = "ClusterODM"
from_port = 8001
to_port = 8001
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
/* only if direct access is needed to nodes
ingress {
description = "nodeODM"
from_port = 3000
to_port = 3000
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
# */
ingress {
description = "internal"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = [var.public_subnet]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
#-------------------------------
# EC2 instance
#-------------------------------
#-------------------------------
# AMI reference
#-------------------------------
data "aws_ami" "ubuntu" {
most_recent = true
filter {
name = "name"
values = [lookup(var.ubuntu_image, var.ami_selector)]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
owners = ["099720109477"] # Canonical
}
#-------------------------------
# Get cloud-init template file
#-------------------------------
data "template_file" "webodm" {
template = file("webodm.tpl")
vars = {
ssh_key = var.pub_key_data
}
}
data "template_file" "nodeodm" {
template = file("nodeodm.tpl")
vars = {
ssh_key = var.pub_key_data
}
}
#-------------------------------
# EC2 instance WebODM
#-------------------------------
resource "aws_instance" "webodm" {
count = var.webodm_count
ami = data.aws_ami.ubuntu.id
instance_type = lookup(var.instance_type, var.type_selector)
key_name = var.pub_key
subnet_id = aws_subnet.odm_public_subnet.id
vpc_security_group_ids = [aws_security_group.odm.id]
associate_public_ip_address = true
user_data = data.template_file.webodm.rendered
root_block_device {
volume_size = var.rootBlockSize
}
}
#-------------------------------
# EC2 instance nodeodm
#-------------------------------
resource "aws_instance" "nodeodm" {
count = var.nodeodm_count
ami = data.aws_ami.ubuntu.id
instance_type = lookup(var.instance_type, var.type_selector)
key_name = var.pub_key
subnet_id = aws_subnet.odm_public_subnet.id
vpc_security_group_ids = [aws_security_group.odm.id]
associate_public_ip_address = true
user_data = data.template_file.nodeodm.rendered
root_block_device {
volume_size = var.rootBlockSize
}
}