-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from paseaf/zl/refactor-scripts
Refactor packer and terraform scripts
- Loading branch information
Showing
13 changed files
with
264 additions
and
240 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
resource "google_compute_firewall" "containerssh_allow_all" { | ||
name = "containerssh-allow-all" | ||
network = google_compute_network.main.self_link | ||
|
||
allow { | ||
protocol = "icmp" | ||
} | ||
allow { | ||
protocol = "udp" | ||
ports = ["0-65535"] | ||
} | ||
allow { | ||
protocol = "tcp" | ||
ports = ["0-65535"] | ||
} | ||
source_ranges = ["0.0.0.0/0"] | ||
} | ||
|
||
resource "google_compute_firewall" "containerssh_allow_ssh" { | ||
name = "containerssh-allow-ssh" | ||
network = google_compute_network.main.self_link | ||
|
||
allow { | ||
protocol = "icmp" | ||
} | ||
|
||
allow { | ||
protocol = "tcp" | ||
ports = ["22"] | ||
} | ||
|
||
source_ranges = ["0.0.0.0/0"] | ||
} | ||
|
||
# open port 3000 for Grafana, 9000 and 9090 for MinIO on our logger-vm | ||
resource "google_compute_firewall" "firewall_logger_view" { | ||
name = "firewall-logger-view" | ||
network = google_compute_network.main.self_link | ||
allow { | ||
protocol = "tcp" | ||
ports = ["3000", "9000", "9090"] | ||
} | ||
target_tags = ["observer"] | ||
source_ranges = ["0.0.0.0/0"] | ||
} | ||
|
||
# open gateway-port 9100 and 9101, to our prometheus and metrics server | ||
resource "google_compute_firewall" "firewall_gateway_nodeexport" { | ||
name = "firewall-gateway-nodeexport" | ||
network = google_compute_network.main.self_link | ||
|
||
allow { | ||
protocol = "tcp" | ||
ports = ["8088", "9100", "9101"] | ||
} | ||
|
||
target_tags = ["gateway"] | ||
source_tags = ["observer"] | ||
} | ||
|
||
# allow inbound connection on TCP port 2376 from gateway | ||
resource "google_compute_firewall" "firewall_sacrificial_exception" { | ||
name = "firewall-sacrificial-exception" | ||
network = google_compute_network.main.name | ||
priority = 500 | ||
source_tags = ["gateway"] | ||
target_tags = ["sacrificial"] | ||
allow { | ||
protocol = "tcp" | ||
ports = ["2376"] | ||
} | ||
} | ||
|
||
# open sacrificial-port 8088 for cadvisor and 9100 for node-exporter | ||
resource "google_compute_firewall" "firewall_sacrificial_nodeexport" { | ||
name = "firewall-sacrificial-nodeexport" | ||
network = google_compute_network.main.self_link | ||
|
||
allow { | ||
protocol = "tcp" | ||
ports = ["8088", "9100"] | ||
} | ||
|
||
target_tags = ["sacrificial"] | ||
source_tags = ["observer"] | ||
} | ||
|
||
# close all outgoing connection from sacrificial host | ||
resource "google_compute_firewall" "firewall_sacrificial_no_egress" { | ||
name = "firewall-sacrificial-no-egress" | ||
network = google_compute_network.main.name | ||
direction = "EGRESS" | ||
destination_ranges = ["0.0.0.0/0"] | ||
target_tags = ["sacrificial"] | ||
deny { | ||
protocol = "all" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
resource "google_compute_instance" "gateway_vm" { | ||
name = "gateway-vm" | ||
machine_type = var.machine_type | ||
tags = ["gateway"] | ||
|
||
boot_disk { | ||
initialize_params { | ||
image = "ubuntu-with-docker-image" | ||
size = 20 | ||
type = "pd-balanced" | ||
} | ||
} | ||
|
||
network_interface { | ||
subnetwork = google_compute_subnetwork.gateway_subnet.self_link | ||
network_ip = "10.0.0.10" | ||
access_config { | ||
|
||
} | ||
} | ||
|
||
connection { | ||
type = "ssh" | ||
user = "deployer" | ||
private_key = file("./deployer_key") | ||
host = google_compute_instance.gateway_vm.network_interface.0.access_config.0.nat_ip | ||
} | ||
|
||
provisioner "file" { | ||
source = "./files/config.yaml" | ||
destination = "./config.yaml" | ||
} | ||
|
||
provisioner "remote-exec" { | ||
scripts = [ | ||
"./scripts/run_cadvisor.sh" | ||
] | ||
} | ||
} | ||
|
||
resource "google_compute_instance" "sacrificial_vm" { | ||
name = "sacrificial-vm" | ||
machine_type = var.machine_type | ||
tags = ["sacrificial"] | ||
boot_disk { | ||
initialize_params { | ||
image = "sacrificial-vm-image" | ||
size = 20 | ||
type = "pd-balanced" | ||
} | ||
} | ||
|
||
network_interface { | ||
subnetwork = google_compute_subnetwork.honeypot_subnet.name | ||
network_ip = "10.0.1.10" | ||
access_config { | ||
|
||
} | ||
} | ||
} | ||
|
||
resource "google_compute_instance" "logger_vm" { | ||
name = "logger-vm" | ||
machine_type = var.machine_type | ||
tags = ["observer"] | ||
|
||
boot_disk { | ||
initialize_params { | ||
image = "ubuntu-with-docker-image" | ||
size = 200 | ||
type = "pd-balanced" | ||
} | ||
} | ||
|
||
network_interface { | ||
subnetwork = google_compute_subnetwork.gateway_subnet.name | ||
network_ip = "10.0.0.11" | ||
access_config { | ||
|
||
} | ||
} | ||
|
||
connection { | ||
type = "ssh" | ||
user = "deployer" | ||
private_key = file("./deployer_key") | ||
host = google_compute_instance.logger_vm.network_interface.0.access_config.0.nat_ip | ||
} | ||
|
||
provisioner "local-exec" { | ||
command = "./generate_credentials.sh" | ||
interpreter = ["/bin/bash"] | ||
} | ||
|
||
provisioner "file" { | ||
source = "./credentials.txt" # relative to terraform work_dir | ||
destination = "./.env" # relative to remote $HOME | ||
} | ||
|
||
provisioner "file" { | ||
source = "./files/prometheus.yml" # relative to terraform work_dir | ||
destination = "./prometheus.yml" # relative to remote $HOME | ||
} | ||
|
||
provisioner "file" { | ||
source = "./files/grafana" # relative to terraform work_dir | ||
destination = "./" # relative to remote $HOME | ||
} | ||
|
||
provisioner "remote-exec" { | ||
scripts = [ | ||
"./scripts/run_cadvisor.sh", | ||
"./scripts/run_minio.sh", | ||
"./scripts/run_prometheus.sh", | ||
"./scripts/run_grafana.sh" | ||
] | ||
} | ||
} |
Oops, something went wrong.