-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
main.tf
125 lines (105 loc) · 2.65 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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
### PROVIDER
provider "google" {
project = "advancedterraform" #replace this with your project-id
region = "us-central1"
zone = "us-central1-a"
}
### NETWORK
data "google_compute_network" "default" {
name = "default"
}
## SUBNET
resource "google_compute_subnetwork" "subnet-1" {
name = "subnet1"
ip_cidr_range = "10.127.0.0/20"
network = data.google_compute_network.default.self_link
region = "us-central1"
private_ip_google_access = true
}
resource "google_compute_firewall" "default" {
name = "test-firewall"
network = data.google_compute_network.default.self_link
allow {
protocol = "icmp"
}
allow {
protocol = "tcp"
ports = ["80", "8080", "1000-2000", "22"]
}
source_tags = ["web"]
}
### COMPUTE
## NGINX PROXY
resource "google_compute_instance" "nginx_instance" {
name = "nginx-proxy"
machine_type = "f1-micro"
tags = ["web"]
boot_disk {
initialize_params {
image = "debian-cloud/debian-11"
}
}
network_interface {
network = data.google_compute_network.default.self_link
subnetwork = google_compute_subnetwork.subnet-1.self_link
access_config {
}
}
}
## WEB1
resource "google_compute_instance" "web1" {
name = "web1"
machine_type = "f1-micro"
boot_disk {
initialize_params {
image = "debian-cloud/debian-11"
}
}
network_interface {
# A default network is created for all GCP projects
network = data.google_compute_network.default.self_link
subnetwork = google_compute_subnetwork.subnet-1.self_link
}
}
## WEB2
resource "google_compute_instance" "web2" {
name = "web2"
machine_type = "f1-micro"
boot_disk {
initialize_params {
image = "debian-cloud/debian-11"
}
}
network_interface {
network = data.google_compute_network.default.self_link
subnetwork = google_compute_subnetwork.subnet-1.self_link
}
}
## WEB3
resource "google_compute_instance" "web3" {
name = "web3"
machine_type = "f1-micro"
boot_disk {
initialize_params {
image = "debian-cloud/debian-11"
}
}
network_interface {
network = data.google_compute_network.default.self_link
subnetwork = google_compute_subnetwork.subnet-1.self_link
}
}
## DB
resource "google_compute_instance" "mysqldb" {
name = "mysqldb"
machine_type = "f1-micro"
boot_disk {
initialize_params {
image = "debian-cloud/debian-11"
}
}
network_interface {
network = data.google_compute_network.default.self_link
subnetwork = google_compute_subnetwork.subnet-1.self_link
}
}