Skip to content

Instantly share code, notes, and snippets.

@andyshinn
Created June 3, 2020 17:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andyshinn/923ba0ff97ce9d641b9e8b882bf34852 to your computer and use it in GitHub Desktop.
Save andyshinn/923ba0ff97ce9d641b9e8b882bf34852 to your computer and use it in GitHub Desktop.
resource "google_compute_network" "nat" {
project = var.gcp_project_id
name = "nat"
}
resource "google_compute_router" "nat" {
project = var.gcp_project_id
name = "nat"
network = google_compute_network.nat.self_link
}
resource "google_compute_router_nat" "nat" {
project = var.gcp_project_id
name = "nat"
router = google_compute_router.nat.name
region = google_compute_router.nat.region
nat_ip_allocate_option = "MANUAL_ONLY"
source_subnetwork_ip_ranges_to_nat = "ALL_SUBNETWORKS_ALL_IP_RANGES"
nat_ips = google_compute_address.nat[*].self_link
log_config {
enable = true
filter = "ERRORS_ONLY"
}
}
resource "google_compute_address" "nat" {
project = var.gcp_project_id
count = local.nat_address_count
name = "nat-public-${count.index}"
}
resource "google_compute_instance_template" "lit" {
name_prefix = "lit-"
description = "myorg LIT Service"
machine_type = "n1-standard-1"
scheduling {
automatic_restart = true
on_host_maintenance = "MIGRATE"
}
disk {
source_image = data.google_compute_image.coreos.self_link
auto_delete = true
boot = true
}
network_interface {
network = data.terraform_remote_state.monolith.outputs.nat_network
}
service_account {
scopes = ["userinfo-email", "compute-ro", "storage-ro"]
}
tags = [
"lit",
]
metadata = {
user-data = templatefile("${path.module}/files/cloud-config.tmpl", local.cloud_config)
}
lifecycle {
create_before_destroy = true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment