-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.tf
158 lines (131 loc) · 3.3 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
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
provider "aws" {
region = var.region
}
locals {
amis = {
"us-west-1" = "ami-0ff591da048329e00"
"us-west-2" = "ami-0aff18ec83b712f05"
"us-east-1" = "ami-0b72821e2f351e396"
"us-east-2" = "ami-0862be96e41dcbf74"
}
agent_ami = lookup(local.amis, var.region, var.custom_ami)
other_ami = lookup(local.amis, var.region, var.custom_ami)
}
resource "tls_private_key" "deployer" {
algorithm = "RSA"
rsa_bits = 2048
}
resource "aws_key_pair" "deployer" {
key_name = "deployer-key-${random_id.key_id.hex}"
public_key = tls_private_key.deployer.public_key_openssh
}
resource "local_file" "private_key" {
content = tls_private_key.deployer.private_key_pem
filename = "${path.module}/deployer-key-${random_id.key_id.hex}.pem"
file_permission = "0600"
}
resource "random_id" "key_id" {
byte_length = 4
}
resource "aws_security_group" "kasm_sg" {
name = "kasm_sg"
description = "Security group for Kasm servers"
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"] # Replace with YOUR_IP/32 for more security
}
ingress {
from_port = 5432
to_port = 5432
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 6379
to_port = 6379
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 8443
to_port = 8443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 80
to_port = 80
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"]
}
}
resource "aws_instance" "agent_servers" {
count = var.agent_server_count
ami = local.agent_ami
instance_type = var.agent_server_size
key_name = aws_key_pair.deployer.key_name
security_groups = [aws_security_group.kasm_sg.name]
root_block_device {
volume_size = var.agent_server_disk_size
volume_type = "gp2"
}
tags = {
Name = "kasm-agent-${count.index + 1}"
}
}
resource "aws_instance" "db_server" {
ami = local.other_ami
instance_type = var.other_server_size
key_name = aws_key_pair.deployer.key_name
security_groups = [aws_security_group.kasm_sg.name]
root_block_device {
volume_size = var.other_server_disk_size
volume_type = "gp2"
}
tags = {
Name = "kasm-db"
}
}
resource "aws_instance" "guac_server" {
ami = local.other_ami
instance_type = var.other_server_size
key_name = aws_key_pair.deployer.key_name
security_groups = [aws_security_group.kasm_sg.name]
root_block_device {
volume_size = var.other_server_disk_size
volume_type = "gp2"
}
tags = {
Name = "kasm-guac"
}
}
resource "aws_instance" "web_server" {
ami = local.other_ami
instance_type = var.other_server_size
key_name = aws_key_pair.deployer.key_name
security_groups = [aws_security_group.kasm_sg.name]
root_block_device {
volume_size = var.other_server_disk_size
volume_type = "gp2"
}
tags = {
Name = "kasm-web"
}
}
resource "aws_eip" "web_server_eip" {
instance = aws_instance.web_server.id
}