-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.tf
74 lines (58 loc) · 2.95 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#-------------------------------------------------------------------------------
# Module "labels" Configuration #
#-------------------------------------------------------------------------------
module "labels" {
source = "clouddrove/labels/gcp"
version = "1.0.0"
name = var.name
environment = var.environment
label_order = var.label_order
}
#------------------------------------------------------------------------------------------
# Google_Compute_Network_(VPC)_Configuration #
#-------------------------------------------------------------------------------------------
resource "google_compute_network" "vpc" {
count = var.google_compute_network_enabled && var.module_enabled ? 1 : 0
name = module.labels.id
description = var.description
project = var.project_id
auto_create_subnetworks = var.auto_create_subnetworks
routing_mode = var.routing_mode
mtu = var.mtu
delete_default_routes_on_create = var.delete_default_routes_on_create
enable_ula_internal_ipv6 = var.enable_ula_internal_ipv6
internal_ipv6_range = var.internal_ipv6_range
depends_on = [var.module_depends_on]
}
#-------------------------------------------------------------------------------
# shared_vpc_Configuration #
#-------------------------------------------------------------------------------
resource "google_compute_shared_vpc_host_project" "host" {
count = var.google_compute_shared_vpc_host_enabled && var.enabled ? 1 : 0
project = var.host_project_id
}
resource "google_compute_shared_vpc_service_project" "service1" {
count = var.google_compute_shared_vpc_host_enabled && var.enabled ? 1 : 0
host_project = google_compute_shared_vpc_host_project.host[count.index].project
service_project = var.service_project_id
}
#-------------------------------------------------------------------------------
# Private_IP_Configuration #
#-------------------------------------------------------------------------------
resource "google_compute_global_address" "private_ip_alloc" {
count = var.enable_private_ip_alloc ? length(var.private_ip_alloc_name) : 0
name = var.private_ip_alloc_name[count.index]
purpose = "VPC_PEERING"
address_type = "INTERNAL"
prefix_length = var.prefix_length[count.index]
network = google_compute_network.vpc[0].self_link
}
#-------------------------------------------------------------------------------
# Private_connection_service_Configuration #
#-------------------------------------------------------------------------------
resource "google_service_networking_connection" "default" {
count = var.enable_service_networking ? 1 : 0
network = google_compute_network.vpc[0].self_link
service = "servicenetworking.googleapis.com"
reserved_peering_ranges = var.enable_service_networking ? [google_compute_global_address.private_ip_alloc[0].name] : []
}