|
| 1 | +resource "google_compute_network" "default" { |
| 2 | + name = "rbs-net-${local.name_suffix}" |
| 3 | + auto_create_subnetworks = false |
| 4 | +} |
| 5 | + |
| 6 | +resource "google_compute_subnetwork" "default" { |
| 7 | + name = "rbs-subnet-${local.name_suffix}" |
| 8 | + ip_cidr_range = "10.1.2.0/24" |
| 9 | + region = "us-central1" |
| 10 | + network = google_compute_network.default.id |
| 11 | +} |
| 12 | + |
| 13 | +resource "google_compute_network_endpoint" "endpoint" { |
| 14 | + network_endpoint_group = google_compute_network_endpoint_group.neg.name |
| 15 | + |
| 16 | + instance = google_compute_instance.endpoint-instance.name |
| 17 | + ip_address = google_compute_instance.endpoint-instance.network_interface[0].network_ip |
| 18 | +} |
| 19 | + |
| 20 | +data "google_compute_image" "my_image" { |
| 21 | + family = "debian-12" |
| 22 | + project = "debian-cloud" |
| 23 | +} |
| 24 | + |
| 25 | +resource "google_compute_instance" "endpoint-instance" { |
| 26 | + name = "rbs-instance-${local.name_suffix}" |
| 27 | + machine_type = "e2-medium" |
| 28 | + |
| 29 | + boot_disk { |
| 30 | + initialize_params { |
| 31 | + image = data.google_compute_image.my_image.self_link |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + network_interface { |
| 36 | + subnetwork = google_compute_subnetwork.default.id |
| 37 | + access_config { |
| 38 | + } |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +resource "google_compute_network_endpoint_group" "neg" { |
| 43 | + name = "rbs-neg-${local.name_suffix}" |
| 44 | + network_endpoint_type = "GCE_VM_IP" |
| 45 | + network = google_compute_network.default.id |
| 46 | + subnetwork = google_compute_subnetwork.default.id |
| 47 | + zone = "us-central1-a" |
| 48 | +} |
| 49 | + |
| 50 | +resource "google_compute_region_backend_service" "default" { |
| 51 | + region = "us-central1" |
| 52 | + name = "region-service-${local.name_suffix}" |
| 53 | + protocol = "UDP" |
| 54 | + load_balancing_scheme = "EXTERNAL" |
| 55 | + network = google_compute_network.default.id |
| 56 | + backend { |
| 57 | + group = google_compute_network_endpoint_group.neg.self_link |
| 58 | + balancing_mode = "CONNECTION" |
| 59 | + } |
| 60 | + ha_policy { |
| 61 | + fast_ip_move = "GARP_RA" |
| 62 | + leader { |
| 63 | + backend_group = google_compute_network_endpoint_group.neg.self_link |
| 64 | + network_endpoint { |
| 65 | + instance = google_compute_instance.endpoint-instance.name |
| 66 | + } |
| 67 | + } |
| 68 | + } |
| 69 | + // Must explicitly disable connection draining to override default value. |
| 70 | + connection_draining_timeout_sec = 0 |
| 71 | +} |
0 commit comments