Skip to content

Instantly share code, notes, and snippets.

@jcardus
Last active October 8, 2023 18:05
Show Gist options
  • Save jcardus/6bb4cf2dcbccbed231150bef235b4feb to your computer and use it in GitHub Desktop.
Save jcardus/6bb4cf2dcbccbed231150bef235b4feb to your computer and use it in GitHub Desktop.
Deploy Valhalla on Google Compute Engine using Terraform. Usage: terraform init / terraform apply
terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "4.51.0"
}
}
}
variable "project" { }
variable "region" {
default = "us-central1"
}
variable "zone" {
default = "us-central1-c"
}
output "server_url" {
description = "Server URL"
value = "http://${google_compute_instance.instance-valhalla.network_interface.0.access_config.0.nat_ip}:8002"
}
module "gce-container" {
source = "terraform-google-modules/container-vm/google"
version = "~> 2.0"
container = {
image="ghcr.io/gis-ops/docker-valhalla/valhalla:latest"
env = [
{
name = "tile_urls"
# set the tiles you want to load space separated
value = "https://download.geofabrik.de/south-america/brazil-latest.osm.pbf https://download.geofabrik.de/south-america/chile-latest.osm.pbf https://download.geofabrik.de/africa/morocco-latest.osm.pbf"
},
{
name = "use_tiles_ignore_pbf"
value = "False"
},
]
securityContext = {
privileged : true
}
}
restart_policy = "Always"
}
provider "google" {
project = var.project
region = var.region
zone = var.zone
}
resource "google_compute_instance" "instance-valhalla" {
name = "instance-valhalla"
machine_type = "n1-highmem-2"
allow_stopping_for_update = true
tags = ["http-server"]
zone = "us-central1-a"
boot_disk {
auto_delete = true
device_name = "instance-valhalla"
initialize_params {
image = "projects/cos-cloud/global/images/cos-stable-109-17800-0-47"
size = 100
type = "pd-balanced"
}
mode = "READ_WRITE"
}
metadata = {
gce-container-declaration = module.gce-container.metadata_value
google-logging-enabled = true
google-monitoring-enabled = true
}
network_interface {
subnetwork = "default"
access_config {}
}
shielded_instance_config {
enable_integrity_monitoring = true
enable_secure_boot = false
enable_vtpm = true
}
}
resource "google_compute_firewall" "rules" {
name = "valhalla"
network = "default"
description = "Creates firewall rule targeting tagged instances"
allow {
protocol = "tcp"
ports = ["8002"]
}
source_ranges = ["0.0.0.0/0"]
target_tags = ["http-server"]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment