|
| 1 | +/** |
| 2 | + * Copyright 2019 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 | +provider "google" { |
| 18 | + version = "~> 2.19.0" |
| 19 | +} |
| 20 | + |
| 21 | +provider "google-beta" { |
| 22 | + version = "~> 2.19.0" |
| 23 | +} |
| 24 | + |
| 25 | +provider "null" { |
| 26 | + version = "~> 2.1" |
| 27 | +} |
| 28 | + |
| 29 | +module "vpc" { |
| 30 | + source = "../../modules/vpc" |
| 31 | + network_name = var.network_name |
| 32 | + project_id = var.project_id |
| 33 | +} |
| 34 | + |
| 35 | +module "subnets" { |
| 36 | + source = "../../modules/subnets-beta" |
| 37 | + project_id = var.project_id |
| 38 | + network_name = module.vpc.network_name |
| 39 | + |
| 40 | + subnets = [ |
| 41 | + { |
| 42 | + subnet_name = "${var.network_name}-subnet" |
| 43 | + subnet_ip = "10.10.10.0/24" |
| 44 | + subnet_region = "us-west1" |
| 45 | + }, |
| 46 | + { |
| 47 | + subnet_name = "${var.network_name}-subnet-01" |
| 48 | + subnet_ip = "10.20.10.0/24" |
| 49 | + subnet_region = "us-west1" |
| 50 | + purpose = "INTERNAL_HTTPS_LOAD_BALANCER" |
| 51 | + role = "ACTIVE" |
| 52 | + } |
| 53 | + ] |
| 54 | +} |
| 55 | + |
| 56 | +module "subnets-backup" { |
| 57 | + source = "../../modules/subnets-beta" |
| 58 | + project_id = var.project_id |
| 59 | + network_name = module.vpc.network_name |
| 60 | + |
| 61 | + subnets = [ |
| 62 | + { |
| 63 | + subnet_name = "${var.network_name}-subnet-02" |
| 64 | + subnet_ip = "10.20.20.0/24" |
| 65 | + subnet_region = "us-west1" |
| 66 | + purpose = "INTERNAL_HTTPS_LOAD_BALANCER" |
| 67 | + role = "BACKUP" |
| 68 | + } |
| 69 | + ] |
| 70 | + |
| 71 | + module_depends_on = [module.subnets.subnets] |
| 72 | +} |
| 73 | + |
| 74 | +resource "google_compute_health_check" "this" { |
| 75 | + project = var.project_id |
| 76 | + name = "${var.network_name}-test" |
| 77 | + check_interval_sec = 1 |
| 78 | + timeout_sec = 1 |
| 79 | + |
| 80 | + tcp_health_check { |
| 81 | + port = "80" |
| 82 | + } |
| 83 | +} |
| 84 | + |
| 85 | +resource "google_compute_region_backend_service" "this" { |
| 86 | + project = var.project_id |
| 87 | + name = "${var.network_name}-test" |
| 88 | + region = "us-west1" |
| 89 | + health_checks = [google_compute_health_check.this.self_link] |
| 90 | +} |
| 91 | + |
| 92 | +resource "google_compute_forwarding_rule" "this" { |
| 93 | + project = var.project_id |
| 94 | + name = "${var.network_name}-fw-role" |
| 95 | + |
| 96 | + network = module.vpc.network_name |
| 97 | + subnetwork = module.subnets.subnets["us-west1/${var.network_name}-subnet"].name |
| 98 | + backend_service = google_compute_region_backend_service.this.self_link |
| 99 | + region = "us-west1" |
| 100 | + load_balancing_scheme = "INTERNAL" |
| 101 | + all_ports = true |
| 102 | +} |
| 103 | + |
| 104 | +module "routes" { |
| 105 | + source = "../../modules/routes-beta" |
| 106 | + project_id = var.project_id |
| 107 | + network_name = module.vpc.network_name |
| 108 | + routes_count = 2 |
| 109 | + |
| 110 | + routes = [ |
| 111 | + { |
| 112 | + name = "${var.network_name}-egress-inet" |
| 113 | + description = "route through IGW to access internet" |
| 114 | + destination_range = "0.0.0.0/0" |
| 115 | + tags = "egress-inet" |
| 116 | + next_hop_internet = "true" |
| 117 | + }, |
| 118 | + { |
| 119 | + name = "${var.network_name}-ilb" |
| 120 | + description = "route through ilb" |
| 121 | + destination_range = "10.10.20.0/24" |
| 122 | + next_hop_ilb = google_compute_forwarding_rule.this.self_link |
| 123 | + }, |
| 124 | + ] |
| 125 | + |
| 126 | + module_depends_on = [module.subnets.subnets, module.subnets-backup.subnets] |
| 127 | +} |
0 commit comments