forked from jedevc/HackTheMidlandsCTF19
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
153 lines (122 loc) · 3.27 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
provider "google" {
credentials = "${file("credentials/gcloud.json")}"
project = "htm-ctf"
region = "europe-west2"
zone = "europe-west2-a"
}
resource "random_id" "challenge" {
byte_length = 8
}
resource "random_id" "ctfd" {
byte_length = 8
}
resource "tls_private_key" "connection_key" {
algorithm = "RSA"
rsa_bits = 4096
}
resource "google_compute_network" "ctfd_network" {
name = "ctfd-network"
}
resource "google_compute_firewall" "ctfd_firewall" {
name = "ctfd-firewall"
network = "${google_compute_network.ctfd_network.name}"
allow {
protocol = "tcp"
ports = ["22", "80", "443"]
}
}
resource "google_compute_network" "challenge_network" {
name = "challenge-network"
}
resource "google_compute_firewall" "challenge_firewall" {
name = "challenge-firewall"
network = "${google_compute_network.challenge_network.name}"
allow {
protocol = "tcp"
ports = ["22", "2022", "8080"]
}
}
resource "google_compute_address" "ctfd_ip" {
name = "ctfd-address"
}
resource "google_compute_instance" "ctfd" {
name = "ctfd-${random_id.ctfd.hex}"
machine_type = "n1-standard-1"
boot_disk {
initialize_params {
image = "gce-uefi-images/ubuntu-1804-lts"
}
}
scratch_disk {
}
provisioner "file" {
source = "scripts/ctfd.nginx"
destination = "ctfd.nginx"
connection {
type = "ssh"
user = "root"
host = "${google_compute_address.ctfd_ip.address}"
private_key = "${tls_private_key.connection_key.private_key_pem}"
}
}
metadata_startup_script = "${file("./scripts/ctfd-setup.sh")}"
network_interface {
network = "${google_compute_network.ctfd_network.name}"
access_config {
nat_ip = "${google_compute_address.ctfd_ip.address}"
}
}
metadata = {
ssh-keys = "root:${tls_private_key.connection_key.public_key_openssh}"
}
}
output "ctfd-ip" {
value = "${google_compute_address.ctfd_ip.address}"
}
resource "google_compute_address" "challenge_ip" {
name = "challenge-address"
}
resource "google_compute_instance" "challenge" {
name = "ctf-challenges-${random_id.challenge.hex}"
machine_type = "n1-standard-1"
boot_disk {
initialize_params {
image = "gce-uefi-images/ubuntu-1804-lts"
}
}
scratch_disk {
}
provisioner "file" {
source = "ctftool"
destination = "/usr/bin/ctftool"
connection {
type = "ssh"
user = "root"
host = "${google_compute_address.challenge_ip.address}"
private_key = "${tls_private_key.connection_key.private_key_pem}"
}
}
provisioner "file" {
source = "challenges"
destination = "/etc/ctf"
connection {
type = "ssh"
user = "root"
host = "${google_compute_address.challenge_ip.address}"
private_key = "${tls_private_key.connection_key.private_key_pem}"
}
}
metadata_startup_script = "${file("./scripts/challenge-setup.sh")}"
network_interface {
network = "${google_compute_network.challenge_network.name}"
access_config {
nat_ip = "${google_compute_address.challenge_ip.address}"
}
}
metadata = {
ssh-keys = "root:${tls_private_key.connection_key.public_key_openssh}"
}
}
output "challenge-ip" {
value = "${google_compute_address.challenge_ip.address}"
}