-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgcn.tf
111 lines (107 loc) · 3.1 KB
/
gcn.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# # Create a VPC network
module "network" {
count = var.use_existing_network ? 0 : 1
source = "terraform-google-modules/network/google"
version = "9.3.0"
description = "Truefoundry network for ${var.cluster_name}"
project_id = var.project_id
network_name = local.network_name
routing_mode = var.routing_mode
auto_create_subnetworks = false
subnets = [
{
subnet_name = local.private_subnet_name
subnet_ip = var.private_subnet_cidr
subnet_region = var.region
subnet_private_access = var.enable_private_access
subnet_flow_logs = var.enable_flow_logs
}
]
secondary_ranges = {
# has to be passed in interpolation otherwise it give error
# tflint-ignore: terraform_deprecated_interpolation
"${local.private_subnet_name}" = var.network_vpc_secondary_ranges
}
ingress_rules = [
{
name = "${local.network_name}-ingress-allow-http-https"
description = "Allow port 80 and 443"
source_ranges = ["0.0.0.0/0"]
allow = [
{
protocol = "tcp"
ports = ["80", "443"]
}
]
},
{
name = "${local.network_name}-ingress-allow-internal"
description = "Allow all ports inside a subnet"
source_ranges = [var.private_subnet_cidr]
allow = [
{
protocol = "tcp"
}
]
}
]
egress_rules = [
{
name = "${local.network_name}-egress-allow-all"
description = "Allow egress"
source_ranges = ["0.0.0.0/0"]
destination_ranges = ["0.0.0.0/0"]
allow = [
{
protocol = "tcp"
},
{
protocol = "udp"
}
]
},
]
routes = [
{
name = "${local.network_name}-egress-internet"
description = "Route through IGW to access internet"
destination_range = "0.0.0.0/0"
tags = "egress-inet"
next_hop_internet = "true"
},
]
shared_vpc_host = false
}
resource "time_sleep" "wait_2_mins" {
count = var.use_existing_network ? 0 : 1
depends_on = [module.network[0]]
create_duration = "2m"
}
module "cloud_router" {
count = var.use_existing_network ? 0 : 1
source = "terraform-google-modules/cloud-router/google"
version = "6.2.0"
description = "Truefoundry NAT router for ${var.cluster_name}"
name = local.router_name
project = var.project_id
region = var.region
network = module.network[0].network_name
nats = [
{
name = local.nat_name
nat_ip_allocate_option = "AUTO_ONLY"
source_subnetwork_ip_ranges_to_nat = "LIST_OF_SUBNETWORKS"
subnetworks = [
{
name = local.private_subnet_name
source_ip_ranges_to_nat = ["ALL_IP_RANGES"]
}
]
log_config = {
enabled = true
filter = "ERRORS_ONLY"
}
}
]
depends_on = [time_sleep.wait_2_mins]
}