-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.tf
127 lines (105 loc) · 2.58 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
provider "aws" {
region = "${var.aws_region}"
}
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
}
# VPC
resource "aws_vpc" "vpc" {
cidr_block = "${var.cidr_block}"
enable_dns_support = true
enable_dns_hostnames = true
}
# Internet Gateway
resource "aws_internet_gateway" "igw" {
vpc_id = "${aws_vpc.vpc.id}"
}
# Grant the VPC internet access
resource "aws_route" "internet_access" {
route_table_id = "${aws_vpc.vpc.main_route_table_id}"
destination_cidr_block = "0.0.0.0/0"
gateway_id = "${aws_internet_gateway.igw.id}"
}
# Public Subnet
resource "aws_subnet" "public_subnet" {
vpc_id = "${aws_vpc.vpc.id}"
cidr_block = "${var.subnet_cidr_block}"
map_public_ip_on_launch = true
}
# EC2 Security Group
resource "aws_security_group" "sgGophish" {
name = "GophishSG"
description = "Access from VPN"
vpc_id = "${aws_vpc.vpc.id}"
# SSH from VPN
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["${var.vpn_cidr}"]
}
# HTTPS from VPN
ingress {
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["${var.vpn_cidr}"]
}
ingress {
from_port = 4433
to_port = 4433
protocol = "tcp"
cidr_blocks = ["${var.vpn_cidr}"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
# EC2
resource "random_pet" "ec2" {}
resource "aws_instance" "gophish" {
ami = "${data.aws_ami.ubuntu.id}"
instance_type = "t3.micro"
key_name = "son"
vpc_security_group_ids = ["${aws_security_group.sgGophish.id}"]
subnet_id = "${aws_subnet.public_subnet.id}"
tags {
Name = "${random_pet.ec2.id}"
}
connection {
user = "ubuntu"
}
provisioner "file" {
source = "scripts/install_gophish.sh"
destination = "/home/ubuntu/install_gophish.sh"
}
provisioner "file" {
source = "scripts/start_gophish.sh"
destination = "/home/ubuntu/start_gophish.sh"
}
provisioner "file" {
source = "scripts/install_le_cert.sh"
destination = "/home/ubuntu/install_le_cert.sh"
}
provisioner "remote-exec" {
inline = [
"sudo bash /home/ubuntu/install_gophish.sh",
]
connection {
type = "ssh"
user = "ubuntu"
}
}
}