-
-
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.
Signed-off-by: Johan Siebens <johan.siebens@gmail.com>
- Loading branch information
Showing
17 changed files
with
375 additions
and
20 deletions.
There are no files selected for viewing
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,92 @@ | ||
resource "random_password" "token" { | ||
length = 16 | ||
special = false | ||
} | ||
|
||
resource "google_service_account" "default" { | ||
account_id = format("sa-%s", local.name) | ||
display_name = format("%s Service Account", title(local.name)) | ||
} | ||
|
||
resource "google_compute_instance" "server" { | ||
name = format("vm-%s-server", local.name) | ||
machine_type = "e2-medium" | ||
zone = var.zone | ||
|
||
tags = [ | ||
local.name, | ||
format("%s-server", local.name) | ||
] | ||
|
||
boot_disk { | ||
initialize_params { | ||
image = "ubuntu-os-cloud/ubuntu-2004-focal-v20210702" | ||
} | ||
} | ||
|
||
metadata_startup_script = templatefile("${path.module}/../shared/templates/server.sh", { token = random_password.token.result, interface = "ens4" }) | ||
|
||
network_interface { | ||
network = google_compute_network.this.self_link | ||
subnetwork = google_compute_subnetwork.this.self_link | ||
|
||
access_config { | ||
// Ephemeral IP | ||
} | ||
} | ||
|
||
service_account { | ||
email = google_service_account.default.email | ||
scopes = ["cloud-platform"] | ||
} | ||
|
||
} | ||
|
||
resource "google_compute_instance_template" "client" { | ||
name_prefix = format("vm-%s-client-", local.name) | ||
machine_type = "e2-medium" | ||
|
||
disk { | ||
source_image = "ubuntu-os-cloud/ubuntu-2004-focal-v20210702" | ||
} | ||
|
||
network_interface { | ||
network = google_compute_network.this.self_link | ||
subnetwork = google_compute_subnetwork.this.self_link | ||
} | ||
|
||
service_account { | ||
email = google_service_account.default.email | ||
scopes = ["cloud-platform"] | ||
} | ||
|
||
tags = [ | ||
local.name, | ||
format("%s-client", local.name) | ||
] | ||
|
||
metadata_startup_script = templatefile( | ||
"${path.module}/../shared/templates/client.sh", | ||
{ | ||
server_ip = google_compute_instance.server.network_interface.0.network_ip, | ||
interface = "ens4" | ||
} | ||
) | ||
|
||
lifecycle { | ||
create_before_destroy = true | ||
} | ||
} | ||
|
||
resource "google_compute_instance_group_manager" "client" { | ||
name = format("igm-%s-client", local.name) | ||
base_instance_name = format("vm-%s-client", local.name) | ||
zone = var.zone | ||
target_size = "3" | ||
target_pools = [google_compute_target_pool.client.id] | ||
|
||
version { | ||
name = local.name | ||
instance_template = google_compute_instance_template.client.id | ||
} | ||
} |
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,41 @@ | ||
locals { | ||
nomad_addr = "http://${google_compute_instance.server.network_interface.0.access_config.0.nat_ip}:4646" | ||
} | ||
|
||
provider "nomad" { | ||
address = local.nomad_addr | ||
} | ||
|
||
resource "null_resource" "nomad_readiness" { | ||
triggers = { | ||
address = local.nomad_addr | ||
} | ||
|
||
provisioner "local-exec" { | ||
command = "while ! nomad server members > /dev/null 2>&1; do echo 'waiting for nomad api...'; sleep 10; done" | ||
environment = { | ||
NOMAD_ADDR = local.nomad_addr | ||
} | ||
} | ||
} | ||
|
||
resource "nomad_job" "nats" { | ||
depends_on = [null_resource.nomad_readiness] | ||
jobspec = file( | ||
"${path.module}/../shared/jobs/faas-nats.hcl" | ||
) | ||
} | ||
|
||
resource "nomad_job" "monitoring" { | ||
depends_on = [null_resource.nomad_readiness] | ||
jobspec = file( | ||
"${path.module}/../shared/jobs/faas-monitoring.hcl" | ||
) | ||
} | ||
|
||
resource "nomad_job" "gateway" { | ||
depends_on = [null_resource.nomad_readiness] | ||
jobspec = file( | ||
"${path.module}/../shared/jobs/faas-gateway.hcl" | ||
) | ||
} |
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,24 @@ | ||
resource "google_compute_address" "client" { | ||
name = format("%s-client", local.name) | ||
} | ||
|
||
resource "google_compute_forwarding_rule" "client_8080" { | ||
name = format("fw-%s-client-8080", local.name) | ||
region = var.region | ||
port_range = 8080 | ||
target = google_compute_target_pool.client.id | ||
ip_address = google_compute_address.client.address | ||
} | ||
|
||
resource "google_compute_target_pool" "client" { | ||
name = format("tp-%s-client", local.name) | ||
health_checks = [google_compute_http_health_check.gateway.name] | ||
} | ||
|
||
resource "google_compute_http_health_check" "gateway" { | ||
name = format("hc-%s-gateway", local.name) | ||
request_path = "/healthz" | ||
check_interval_sec = 5 | ||
timeout_sec = 1 | ||
port = 8080 | ||
} |
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,88 @@ | ||
locals { | ||
name = random_pet.name.id | ||
} | ||
|
||
resource "random_pet" "name" { | ||
} | ||
|
||
resource "google_compute_network" "this" { | ||
name = format("vpc-%s", local.name) | ||
auto_create_subnetworks = false | ||
} | ||
|
||
resource "google_compute_subnetwork" "this" { | ||
name = format("sb-%s", local.name) | ||
ip_cidr_range = var.ip_range | ||
network = google_compute_network.this.id | ||
} | ||
|
||
resource "google_compute_router" "this" { | ||
name = format("cr-%s", local.name) | ||
network = google_compute_network.this.id | ||
} | ||
|
||
resource "google_compute_router_nat" "this" { | ||
name = format("rn-%s", local.name) | ||
router = google_compute_router.this.name | ||
nat_ip_allocate_option = "AUTO_ONLY" | ||
source_subnetwork_ip_ranges_to_nat = "ALL_SUBNETWORKS_ALL_IP_RANGES" | ||
} | ||
|
||
module "my_ip_address" { | ||
source = "matti/resource/shell" | ||
command = "curl https://ipinfo.io/ip" | ||
} | ||
|
||
resource "google_compute_firewall" "fwr_allow_iap" { | ||
name = format("fwr-%s-iap", local.name) | ||
network = google_compute_network.this.name | ||
|
||
allow { | ||
protocol = "tcp" | ||
ports = ["22"] | ||
} | ||
source_ranges = ["35.235.240.0/20"] | ||
} | ||
|
||
resource "google_compute_firewall" "fwr_allow_server" { | ||
name = format("fwr-%s-server", local.name) | ||
network = google_compute_network.this.name | ||
|
||
allow { | ||
protocol = "tcp" | ||
ports = ["4646", "8500", "8200"] | ||
} | ||
source_ranges = [module.my_ip_address.stdout] | ||
target_tags = [format("%s-server", local.name)] | ||
} | ||
|
||
resource "google_compute_firewall" "fwr_allow_internal" { | ||
name = format("fwr-%s-internal", local.name) | ||
network = google_compute_network.this.name | ||
|
||
allow { | ||
protocol = "tcp" | ||
} | ||
|
||
allow { | ||
protocol = "udp" | ||
} | ||
|
||
source_tags = [local.name] | ||
target_tags = [local.name] | ||
} | ||
|
||
resource "google_compute_firewall" "allow_client_ingress" { | ||
name = format("fwr-%s-ingress", local.name) | ||
network = google_compute_network.this.name | ||
|
||
source_ranges = ["0.0.0.0/0"] | ||
target_tags = [format("%s-client", local.name)] | ||
|
||
allow { | ||
protocol = "tcp" | ||
ports = [ | ||
"8080", | ||
] | ||
} | ||
} |
Oops, something went wrong.