|
| 1 | +provider "google" { |
| 2 | + project = var.project_id |
| 3 | +} |
| 4 | + |
| 5 | +provider "google-beta" { |
| 6 | + project = var.project_id |
| 7 | +} |
| 8 | + |
| 9 | +resource "google_compute_network" "default" { |
| 10 | + name = "lb-internal-cloud-run" |
| 11 | + auto_create_subnetworks = "false" |
| 12 | + project = var.project_id |
| 13 | +} |
| 14 | + |
| 15 | +resource "google_compute_subnetwork" "default" { |
| 16 | + name = "lb-internal-subnet-a-cloud-run" |
| 17 | + ip_cidr_range = "10.1.2.0/24" |
| 18 | + network = google_compute_network.default.id |
| 19 | + region = var.subnet_region |
| 20 | + project = var.project_id |
| 21 | + depends_on = [google_compute_network.default] |
| 22 | +} |
| 23 | + |
| 24 | +resource "google_compute_subnetwork" "default_proxy_only" { |
| 25 | + name = "proxy-only-subnet" |
| 26 | + ip_cidr_range = "10.129.0.0/23" |
| 27 | + network = google_compute_network.default.id |
| 28 | + purpose = "GLOBAL_MANAGED_PROXY" |
| 29 | + region = var.subnet_region |
| 30 | + project = var.project_id |
| 31 | + role = "ACTIVE" |
| 32 | + depends_on = [google_compute_network.default] |
| 33 | +} |
| 34 | + |
| 35 | +module "backend-service-a" { |
| 36 | + source = "GoogleCloudPlatform/cloud-run/google//modules/v2" |
| 37 | + version = "~> 0.16.3" |
| 38 | + project_id = var.project_id |
| 39 | + location = var.region_a |
| 40 | + service_name = "bs-a" |
| 41 | + containers = [{ "container_name" = "", "container_image" = "gcr.io/cloudrun/hello" }] |
| 42 | + members = ["allUsers"] |
| 43 | + ingress = "INGRESS_TRAFFIC_INTERNAL_ONLY" |
| 44 | + cloud_run_deletion_protection = false |
| 45 | + enable_prometheus_sidecar = false |
| 46 | +} |
| 47 | + |
| 48 | +module "backend-service-b" { |
| 49 | + source = "GoogleCloudPlatform/cloud-run/google//modules/v2" |
| 50 | + version = "~> 0.16.3" |
| 51 | + project_id = var.project_id |
| 52 | + location = var.region_b |
| 53 | + service_name = "bs-b" |
| 54 | + containers = [{ "container_name" = "", "container_image" = "gcr.io/cloudrun/hello" }] |
| 55 | + members = ["allUsers"] |
| 56 | + ingress = "INGRESS_TRAFFIC_INTERNAL_ONLY" |
| 57 | + cloud_run_deletion_protection = false |
| 58 | + enable_prometheus_sidecar = false |
| 59 | +} |
| 60 | + |
| 61 | +module "lb-http-backend" { |
| 62 | + source = "../../modules/backend" # use registry |
| 63 | + #version = "~> 12.1.1" |
| 64 | + |
| 65 | + project_id = var.project_id |
| 66 | + name = "backend-lb-int" |
| 67 | + enable_cdn = false |
| 68 | + load_balancing_scheme = "INTERNAL_MANAGED" |
| 69 | + locality_lb_policy = "RANDOM" |
| 70 | + compression_mode = "DISABLED" |
| 71 | + serverless_neg_backends = [ |
| 72 | + { region : var.region_a, type : "cloud-run", service_name : module.backend-service-a.service_name }, |
| 73 | + { region : var.region_b, type : "cloud-run", service_name : module.backend-service-b.service_name } |
| 74 | + ] |
| 75 | +} |
| 76 | + |
| 77 | +module "lb-http-frontend" { |
| 78 | + source = "../../modules/frontend" # use registry |
| 79 | + #version = "~> 12.1.1" |
| 80 | + |
| 81 | + project_id = var.project_id |
| 82 | + name = "frontend-lb-int" |
| 83 | + url_map_input = module.lb-http-backend.backend_service_info |
| 84 | + network = google_compute_network.default.name |
| 85 | + load_balancing_scheme = "INTERNAL_MANAGED" |
| 86 | + subnetwork = google_compute_subnetwork.default.id |
| 87 | + create_address = false |
| 88 | +} |
| 89 | + |
| 90 | +resource "google_vpc_access_connector" "default" { |
| 91 | + provider = google-beta |
| 92 | + project = var.project_id |
| 93 | + name = "fe-vpc-cx" |
| 94 | + region = var.region_a |
| 95 | + ip_cidr_range = "10.8.0.0/28" |
| 96 | + network = google_compute_network.default.name |
| 97 | + max_throughput = 500 |
| 98 | + min_throughput = 300 |
| 99 | +} |
| 100 | + |
| 101 | +# the id address part needs to be fixed |
| 102 | +module "frontend-service" { |
| 103 | + source = "GoogleCloudPlatform/cloud-run/google//modules/v2" |
| 104 | + version = "~> 0.16.3" |
| 105 | + project_id = var.project_id |
| 106 | + location = var.region_a |
| 107 | + service_name = "fs-2002" |
| 108 | + containers = [{ "env_vars" : { "TARGET_IP" : module.lb-http-frontend.ip_address_http }, "ports" = { "container_port" = 80, "name" = "http1" }, "container_name" = "", "container_image" = "gcr.io/design-center-container-repo/redirect-traffic:latest-2002" }] |
| 109 | + members = ["allUsers"] |
| 110 | + vpc_access = { |
| 111 | + connector = google_vpc_access_connector.default.id |
| 112 | + egress = "ALL_TRAFFIC" |
| 113 | + } |
| 114 | + ingress = "INGRESS_TRAFFIC_ALL" |
| 115 | + cloud_run_deletion_protection = false |
| 116 | + enable_prometheus_sidecar = false |
| 117 | + depends_on = [google_vpc_access_connector.default] |
| 118 | +} |
| 119 | + |
| 120 | +module "frontend-service_b" { |
| 121 | + source = "GoogleCloudPlatform/cloud-run/google//modules/v2" |
| 122 | + version = "~> 0.16.3" |
| 123 | + project_id = var.project_id |
| 124 | + location = var.region_a |
| 125 | + service_name = "fs-b-2002" |
| 126 | + containers = [{ "env_vars" : { "TARGET_IP" : module.lb-http-frontend.ip_address_http }, "ports" = { "container_port" = 80, "name" = "http1" }, "container_name" = "", "container_image" = "gcr.io/design-center-container-repo/redirect-traffic:latest-2002" }] |
| 127 | + members = ["allUsers"] |
| 128 | + vpc_access = { |
| 129 | + connector = google_vpc_access_connector.default.id |
| 130 | + egress = "ALL_TRAFFIC" |
| 131 | + } |
| 132 | + ingress = "INGRESS_TRAFFIC_ALL" |
| 133 | + cloud_run_deletion_protection = false |
| 134 | + enable_prometheus_sidecar = false |
| 135 | +} |
0 commit comments