|
| 1 | +/** |
| 2 | + * Copyright 2018 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 | +locals { |
| 18 | + credentials_file_path = "${var.credentials_path}" |
| 19 | + subnet_01 = "${var.network_name}-subnet-01" |
| 20 | + subnet_02 = "${var.network_name}-subnet-02" |
| 21 | +} |
| 22 | + |
| 23 | +/****************************************** |
| 24 | + Provider configuration |
| 25 | + *****************************************/ |
| 26 | +provider "google" { |
| 27 | + credentials = "${file(local.credentials_file_path)}" |
| 28 | + version = "~> 1.19" |
| 29 | +} |
| 30 | + |
| 31 | +provider "google-beta" { |
| 32 | + credentials = "${file(local.credentials_file_path)}" |
| 33 | + version = "~> 1.19" |
| 34 | +} |
| 35 | + |
| 36 | +/****************************************** |
| 37 | + Host Project Creation |
| 38 | + *****************************************/ |
| 39 | +module "host-project" { |
| 40 | + source = "../../" |
| 41 | + random_project_id = "true" |
| 42 | + name = "${var.host_project_name}" |
| 43 | + org_id = "${var.organization_id}" |
| 44 | + billing_account = "${var.billing_account}" |
| 45 | + credentials_path = "${local.credentials_file_path}" |
| 46 | +} |
| 47 | + |
| 48 | +/****************************************** |
| 49 | + Network Creation |
| 50 | + *****************************************/ |
| 51 | +module "vpc" { |
| 52 | + source = "terraform-google-modules/network/google" |
| 53 | + version = "0.6.0" |
| 54 | + |
| 55 | + project_id = "${module.host-project.project_id}" |
| 56 | + network_name = "${var.network_name}" |
| 57 | + |
| 58 | + delete_default_internet_gateway_routes = "true" |
| 59 | + shared_vpc_host = "true" |
| 60 | + |
| 61 | + subnets = [ |
| 62 | + { |
| 63 | + subnet_name = "${local.subnet_01}" |
| 64 | + subnet_ip = "10.10.10.0/24" |
| 65 | + subnet_region = "us-west1" |
| 66 | + }, |
| 67 | + { |
| 68 | + subnet_name = "${local.subnet_02}" |
| 69 | + subnet_ip = "10.10.20.0/24" |
| 70 | + subnet_region = "us-west1" |
| 71 | + subnet_private_access = "true" |
| 72 | + subnet_flow_logs = "true" |
| 73 | + }, |
| 74 | + ] |
| 75 | + |
| 76 | + secondary_ranges = { |
| 77 | + "${local.subnet_01}" = [] |
| 78 | + "${local.subnet_02}" = [] |
| 79 | + } |
| 80 | +} |
0 commit comments