|
| 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 | + |
| 18 | +# Create Network with a subnetwork and private service access for both netapp.servicenetworking.goog and servicenetworking.googleapis.com |
| 19 | + |
| 20 | +resource "google_compute_network" "default" { |
| 21 | + name = var.network_name |
| 22 | + project = var.project_id |
| 23 | + auto_create_subnetworks = false |
| 24 | + description = "test network" |
| 25 | +} |
| 26 | + |
| 27 | +resource "google_compute_subnetwork" "subnetwork1" { |
| 28 | + name = "subnet-${local.region_1}-mssql" |
| 29 | + ip_cidr_range = "10.0.0.0/24" |
| 30 | + region = local.region_1 |
| 31 | + project = var.project_id |
| 32 | + network = google_compute_network.default.self_link |
| 33 | + private_ip_google_access = true |
| 34 | +} |
| 35 | + |
| 36 | +resource "google_compute_subnetwork" "subnetwork_2" { |
| 37 | + name = "subnet-${local.region_2}-mssql" |
| 38 | + ip_cidr_range = "10.0.1.0/24" |
| 39 | + region = local.region_2 |
| 40 | + project = var.project_id |
| 41 | + network = google_compute_network.default.self_link |
| 42 | + private_ip_google_access = true |
| 43 | +} |
| 44 | + |
| 45 | + |
| 46 | +resource "google_compute_global_address" "private_ip_alloc" { |
| 47 | + project = var.project_id |
| 48 | + name = "psa-mssql" |
| 49 | + address_type = "INTERNAL" |
| 50 | + purpose = "VPC_PEERING" |
| 51 | + address = "10.10.0.0" |
| 52 | + prefix_length = 16 |
| 53 | + network = google_compute_network.default.id |
| 54 | +} |
| 55 | + |
| 56 | +resource "google_service_networking_connection" "vpc_connection" { |
| 57 | + network = google_compute_network.default.id |
| 58 | + service = "servicenetworking.googleapis.com" |
| 59 | + reserved_peering_ranges = [ |
| 60 | + google_compute_global_address.private_ip_alloc.name, |
| 61 | + ] |
| 62 | + deletion_policy = "ABANDON" |
| 63 | + |
| 64 | + depends_on = [ |
| 65 | + google_compute_subnetwork.subnetwork1, |
| 66 | + google_compute_subnetwork.subnetwork_2 |
| 67 | + ] |
| 68 | +} |
0 commit comments