-
Notifications
You must be signed in to change notification settings - Fork 0
/
web-server-autoscale-lb-gcp.tf
66 lines (59 loc) · 1.56 KB
/
web-server-autoscale-lb-gcp.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
provider "google" {
project = "cool-agility-442507-c5"
region = "us-central1"
}
resource "google_compute_instance_template" "web_template" {
name = "web-template"
machine_type = "e2-micro"
disk {
boot = true
auto_delete = true
source_image = "ubuntu-os-cloud/ubuntu-2004-lts"
}
network_interface {
network = "default"
access_config {}
}
metadata_startup_script = <<EOT
#!/bin/bash
sudo apt update
sudo apt install -y apache2
sudo systemctl start apache2
EOT
}
resource "google_compute_target_pool" "web_pool" {
name = "web-pool"
}
resource "google_compute_instance_group_manager" "web_igm" {
name = "web-igm"
base_instance_name = "web-instance"
target_size = 1
target_pools = [google_compute_target_pool.web_pool.self_link]
zone = "us-central1-a" # Replace with your desired zone
version {
instance_template = google_compute_instance_template.web_template.id
}
}
resource "google_compute_http_health_check" "health_check" {
name = "http-health-check"
request_path = "/"
check_interval_sec = 5
timeout_sec = 5
healthy_threshold = 2
unhealthy_threshold = 2
}
resource "google_compute_forwarding_rule" "http_lb" {
name = "http-lb"
target = google_compute_target_pool.web_pool.self_link
port_range = "80"
ip_protocol = "TCP"
}
resource "google_compute_firewall" "allow_http" {
name = "allow-http"
network = "default"
allow {
protocol = "tcp"
ports = ["80"]
}
source_ranges = ["0.0.0.0/0"]
}