|
| 1 | +/** |
| 2 | + * Copyright 2025 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | + |
| 18 | +module "producer-network" { |
| 19 | + source = "terraform-google-modules/network/google//modules/vpc" |
| 20 | + version = "~> 10.0.0" |
| 21 | + project_id = var.project_id |
| 22 | + network_name = "producer-network" |
| 23 | + auto_create_subnetworks = false |
| 24 | +} |
| 25 | + |
| 26 | +module "producer-subnet" { |
| 27 | + source = "terraform-google-modules/network/google//modules/subnets" |
| 28 | + version = "~> 10.0.0" |
| 29 | + |
| 30 | + subnets = [ |
| 31 | + { |
| 32 | + subnet_name = "producer-subnet-a" |
| 33 | + subnet_ip = "10.1.2.0/24" |
| 34 | + subnet_region = "us-central1" |
| 35 | + }, |
| 36 | + { |
| 37 | + subnet_name = "producer-subnet-b" |
| 38 | + subnet_ip = "10.1.3.0/24" |
| 39 | + subnet_region = "us-central1" |
| 40 | + purpose = "PRIVATE_SERVICE_CONNECT" |
| 41 | + } |
| 42 | + ] |
| 43 | + |
| 44 | + network_name = module.producer-network.network_name |
| 45 | + project_id = var.project_id |
| 46 | + depends_on = [module.producer-network] |
| 47 | +} |
| 48 | + |
| 49 | +module "gce-ilb" { |
| 50 | + source = "GoogleCloudPlatform/lb-internal/google" |
| 51 | + version = "~> 6.0" |
| 52 | + project = var.project_id |
| 53 | + region = "us-central1" |
| 54 | + name = "group2-ilb" |
| 55 | + ports = ["80"] |
| 56 | + |
| 57 | + source_tags = ["allow-group1"] |
| 58 | + target_tags = ["allow-group2"] |
| 59 | + |
| 60 | + global_access = true |
| 61 | + |
| 62 | + network = module.producer-network.network_name |
| 63 | + subnetwork = module.producer-subnet.subnets["us-central1/producer-subnet-a"].name |
| 64 | + |
| 65 | + health_check = { |
| 66 | + type = "http" |
| 67 | + check_interval_sec = 1 |
| 68 | + healthy_threshold = 4 |
| 69 | + timeout_sec = 1 |
| 70 | + unhealthy_threshold = 5 |
| 71 | + response = "" |
| 72 | + proxy_header = "NONE" |
| 73 | + port = 80 |
| 74 | + port_name = "health-check-port" |
| 75 | + request = "" |
| 76 | + request_path = "/" |
| 77 | + host = "1.2.3.4" |
| 78 | + enable_log = false |
| 79 | + } |
| 80 | + |
| 81 | + backends = [] |
| 82 | + depends_on = [module.producer-subnet] |
| 83 | + |
| 84 | +} |
| 85 | + |
| 86 | +resource "google_compute_service_attachment" "minimal_sa" { |
| 87 | + project = var.project_id |
| 88 | + name = "sa" |
| 89 | + region = "us-central1" |
| 90 | + enable_proxy_protocol = false |
| 91 | + connection_preference = "ACCEPT_AUTOMATIC" |
| 92 | + nat_subnets = [module.producer-subnet.subnets["us-central1/producer-subnet-b"].name] |
| 93 | + target_service = module.gce-ilb.forwarding_rule |
| 94 | + |
| 95 | + depends_on = [module.gce-ilb] |
| 96 | +} |
| 97 | + |
| 98 | + |
| 99 | +module "psc-neg-network" { |
| 100 | + source = "terraform-google-modules/network/google//modules/vpc" |
| 101 | + version = "~> 10.0.0" |
| 102 | + project_id = var.project_id |
| 103 | + network_name = "psc-neg-network" |
| 104 | + auto_create_subnetworks = false |
| 105 | +} |
| 106 | + |
| 107 | +module "psc-neg-subnet" { |
| 108 | + source = "terraform-google-modules/network/google//modules/subnets" |
| 109 | + version = "~> 10.0.0" |
| 110 | + |
| 111 | + subnets = [ |
| 112 | + { |
| 113 | + subnet_name = "psc-neg-subnet-a" |
| 114 | + subnet_ip = "10.1.2.0/24" |
| 115 | + subnet_region = "us-central1" |
| 116 | + } |
| 117 | + ] |
| 118 | + |
| 119 | + network_name = module.psc-neg-network.network_name |
| 120 | + project_id = var.project_id |
| 121 | + depends_on = [module.psc-neg-network] |
| 122 | +} |
| 123 | + |
| 124 | +module "lb-backend-psc-neg" { |
| 125 | + source = "terraform-google-modules/lb-http/google//modules/backend" |
| 126 | + version = "~> 12.0" |
| 127 | + |
| 128 | + project_id = var.project_id |
| 129 | + name = "backend-with-psc-negs" |
| 130 | + psc_neg_backends = [{ |
| 131 | + name = "test-psc-1" |
| 132 | + region = "us-central1" |
| 133 | + psc_target_service = google_compute_service_attachment.minimal_sa.self_link |
| 134 | + network = module.psc-neg-network.network_name |
| 135 | + subnetwork = module.psc-neg-subnet.subnets["us-central1/psc-neg-subnet-a"].name |
| 136 | + producer_port = "80" |
| 137 | + }] |
| 138 | + |
| 139 | + depends_on = [google_compute_service_attachment.minimal_sa] |
| 140 | +} |
| 141 | + |
| 142 | +module "lb-frontend" { |
| 143 | + source = "terraform-google-modules/lb-http/google//modules/frontend" |
| 144 | + version = "~> 12.0" |
| 145 | + |
| 146 | + project_id = var.project_id |
| 147 | + name = "global-lb-fe-psc-neg" |
| 148 | + url_map_input = module.lb-backend-psc-neg.backend_service_info |
| 149 | +} |
0 commit comments