Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(nat-router) #3

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 32 additions & 11 deletions examples/simple-subnet/main.tf
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
provider "google" {}

locals {
name = "quark-labs"
region = "us-east1"
project = "quarks-labs"
name = "quark-labs"
region = "us-east1"
project = "quarks-labs"
auto_create_subnetworks = false
}

module "network" {
source = "../.."
region = local.region
name = local.name
auto_create_subnetworks = local.auto_create_subnetworks
project = local.project
source = "../.."
region = local.region
name = local.name
auto_create_subnetworks = local.auto_create_subnetworks
project = local.project

subnetworks = {
subenet1 = {
name = "default-us-east1"
name = "default-01"
region = "us-east1"
ip_cidr_range = "172.28.0.0/27"
private_ip_google_access = false
nat = {
nat_ip_allocate_option = "MANUAL_ONLY"
source_subnetwork_ip_ranges_to_nat = "LIST_OF_SUBNETWORKS"
nat_ip_allocate_option = "MANUAL_ONLY"
source_subnetwork_ip_ranges_to_nat = "LIST_OF_SUBNETWORKS"
}
secondary_ip_ranges = {
primary = {
Expand All @@ -35,5 +35,26 @@ module "network" {
}
}
}

subenet2 = {
name = "default-02"
region = "us-east1"
ip_cidr_range = "172.26.0.0/27"
private_ip_google_access = false
nat = {
nat_ip_allocate_option = "MANUAL_ONLY"
source_subnetwork_ip_ranges_to_nat = "LIST_OF_SUBNETWORKS"
}
secondary_ip_ranges = {
primary = {
range_name = "primary"
ip_cidr_range = "172.22.16.0/20"
}
secondary = {
range_name = "secondary"
ip_cidr_range = "172.22.32.0/20"
}
}
}
}
}
8 changes: 4 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ resource "google_compute_subnetwork" "this" {
resource "google_compute_address" "this" {
for_each = var.subnetworks

name = format("%s-nat-ip", each.key)
name = format("%s-nat-ip-${each.key}", each.key)
project = google_compute_network.this.project
region = each.value.region
depends_on = [
Expand All @@ -59,7 +59,7 @@ resource "google_compute_address" "this" {
resource "google_compute_router" "this" {
for_each = var.subnetworks

name = format("%s-cloud-router", google_compute_network.this.name)
name = format("%s-cloud-router-${each.key}", google_compute_network.this.name)
project = google_compute_network.this.project
network = google_compute_network.this.name
region = each.value.region
Expand All @@ -76,11 +76,11 @@ resource "google_compute_router_nat" "this" {

for_each = var.subnetworks

name = format("%s-cloud-nat", google_compute_network.this.name)
name = format("%s-cloud-nat-${each.key}", google_compute_network.this.name)
project = google_compute_network.this.project
router = google_compute_router.this[each.key].name
region = each.value.region
nat_ips = toset([for address in google_compute_address.this : address.self_link ])
nat_ips = toset([google_compute_address.this[each.key].self_link ])
nat_ip_allocate_option = try(each.value.nat.nat_ip_allocate_option, "MANUAL_ONLY")
source_subnetwork_ip_ranges_to_nat = try(each.value.nat.source_subnetwork_ip_ranges_to_nat, "LIST_OF_SUBNETWORKS")

Expand Down
Loading