-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
67 lines (59 loc) · 2.42 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
#######################################################################
# Creates all GCP resources #
#######################################################################
/*
# Enable Cloud Ressource Manager API for the project
resource "google_project_service" "enable_cloud_resource_manager_api" {
service = "cloudresourcemanager.googleapis.com"
project = var.GCP_PROJECT
disable_dependent_services = true
}
# Enable Compute Engine API for the project
resource "google_project_service" "compute_engine_api" {
service = "compute.googleapis.com"
project = var.GCP_PROJECT
disable_dependent_services = true
}
*/
#######################################################
# Creates a VPC and custom Subnet #
#######################################################
resource "google_compute_network" "vpc" {
name = var.vpc1
project = var.GCP_PROJECT
auto_create_subnetworks = false
description = "VPC1 for Servers"
#depends_on = [google_project_service.compute_engine_api]
}
resource "google_compute_subnetwork" "subnet" {
name = "${var.vpc1}-subnet-01"
project = var.GCP_PROJECT
network = google_compute_network.vpc.self_link
ip_cidr_range = var.cidr-gcp
region = var.region
description = "Server SN"
}
###################################################################################
# Creates a GCP Cloud NAT for having Internet available on all VM Instances later #
###################################################################################
resource "google_compute_router" "router" {
name = "${var.vpc1}-router-01"
project = var.GCP_PROJECT
region = google_compute_subnetwork.subnet.region
network = google_compute_network.vpc.self_link
bgp {
asn = 64514
}
}
resource "google_compute_router_nat" "nat" {
name = "${var.vpc1}-router-nat-01"
project = var.GCP_PROJECT
router = google_compute_router.router.name
region = google_compute_router.router.region
nat_ip_allocate_option = "AUTO_ONLY"
source_subnetwork_ip_ranges_to_nat = "ALL_SUBNETWORKS_ALL_IP_RANGES"
log_config {
enable = true
filter = "ERRORS_ONLY"
}
}