-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvpc.tf
78 lines (65 loc) · 2.24 KB
/
vpc.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
resource "google_project_service" "service" {
count = length(var.project_services)
project = var.project
service = element(var.project_services, count.index)
// Do not disable the service on destroy. On destroy, we are going to
// destroy the project, but we need the APIs available to destroy the
// underlying resources.
disable_on_destroy = false
}
resource "google_compute_network" "sandbox-net" {
name = "sandbox-net"
auto_create_subnetworks = false
}
resource "google_compute_subnetwork" "sandbox-subnet" {
name = "sandbox-subnetwork"
ip_cidr_range = var.internal_vms_range
private_ip_google_access = true
region = var.region
network = google_compute_network.sandbox-net.id
secondary_ip_range {
range_name = "pods"
ip_cidr_range = "192.168.0.0/18"
}
secondary_ip_range {
range_name = "services"
ip_cidr_range = "192.168.64.0/18"
}
}
// Create an external NAT IP
resource "google_compute_address" "nat" {
name = format("%s-nat-ip", var.cluster_name)
project = var.project
region = var.region
depends_on = [
google_project_service.service,
]
}
// Create a cloud router for use by the Cloud NAT
resource "google_compute_router" "router" {
name = format("%s-cloud-router", var.cluster_name)
project = var.project
region = var.region
network = google_compute_network.sandbox-net.self_link
bgp {
asn = 64514
}
}
// Create a NAT router so the nodes can reach DockerHub, etc
resource "google_compute_router_nat" "nat" {
name = format("%s-cloud-nat", var.cluster_name)
project = var.project
router = google_compute_router.router.name
region = var.region
nat_ip_allocate_option = "MANUAL_ONLY"
nat_ips = [google_compute_address.nat.self_link]
source_subnetwork_ip_ranges_to_nat = "LIST_OF_SUBNETWORKS"
subnetwork {
name = google_compute_subnetwork.sandbox-subnet.self_link
source_ip_ranges_to_nat = ["PRIMARY_IP_RANGE", "LIST_OF_SECONDARY_IP_RANGES"]
secondary_ip_range_names = [
google_compute_subnetwork.sandbox-subnet.secondary_ip_range.0.range_name,
google_compute_subnetwork.sandbox-subnet.secondary_ip_range.1.range_name,
]
}
}