Skip to content

Commit 644581f

Browse files
feat: Add example for MIG with healthcheck (terraform-google-modules#580)
* Added example for Zonal MIGs * Update compute/zonal_instance_group_manager/main.tf Co-authored-by: Sampath Kumar <[email protected]> * Update compute/zonal_instance_group_manager/main.tf Co-authored-by: Sampath Kumar <[email protected]> * Update compute/zonal_instance_group_manager/main.tf Co-authored-by: Sampath Kumar <[email protected]> * changed base instance name for instances in the mig * add example for MIG with healthcheck --------- Co-authored-by: Sampath Kumar <[email protected]>
1 parent 57853ce commit 644581f

File tree

1 file changed

+87
-0
lines changed
  • compute/zonal_mig_health_check

1 file changed

+87
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/**
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
/**
17+
* Made to resemble:
18+
* gcloud compute health-checks create http example-check --port 80 \
19+
* --check-interval 30s \
20+
* --healthy-threshold 1 \
21+
* --timeout 10s \
22+
* --unhealthy-threshold 3 \
23+
* --global
24+
* gcloud compute firewall-rules create allow-health-check \
25+
* --allow tcp:80 \
26+
* --source-ranges 130.211.0.0/22,35.191.0.0/16 \
27+
* --network default
28+
* gcloud compute instance-groups managed create igm-with-hc \
29+
* --size 3 \
30+
* --template an-instance-template \
31+
* --health-check example-check \
32+
* --initial-delay 30s \
33+
* --zone us-central1-f
34+
*/
35+
36+
# [START compute_zonal_instance_group_manager_hc_parent_tag]
37+
resource "google_compute_instance_template" "default" {
38+
name = "an-instance-template"
39+
machine_type = "e2-medium"
40+
disk {
41+
source_image = "debian-cloud/debian-11"
42+
}
43+
network_interface {
44+
network = "default"
45+
}
46+
}
47+
48+
# [START compute_zonal_instance_group_manager_hc_health_check_tag]
49+
resource "google_compute_http_health_check" "default" {
50+
name = "example-check"
51+
timeout_sec = 10
52+
check_interval_sec = 30
53+
healthy_threshold = 1
54+
unhealthy_threshold = 3
55+
port = "80"
56+
}
57+
# [END compute_zonal_instance_group_manager_hc_health_check_tag]
58+
59+
# [START compute_zonal_instance_group_manager_hc_firewall_rule_tag]
60+
resource "google_compute_firewall" "default" {
61+
name = "allow-health-check"
62+
network = "default"
63+
source_ranges = ["130.211.0.0/22", "35.191.0.0/16"]
64+
allow {
65+
protocol = "tcp"
66+
ports = ["80"]
67+
}
68+
}
69+
# [END compute_zonal_instance_group_manager_hc_firewall_rule_tag]
70+
71+
# [START compute_zonal_instance_group_manager_hc_igm_tag]
72+
resource "google_compute_instance_group_manager" "default" {
73+
name = "igm-with-hc"
74+
base_instance_name = "test"
75+
target_size = 3
76+
zone = "us-central1-f"
77+
version {
78+
instance_template = google_compute_instance_template.default.id
79+
name = "primary"
80+
}
81+
auto_healing_policies {
82+
health_check = google_compute_http_health_check.default.id
83+
initial_delay_sec = 30
84+
}
85+
}
86+
# [END compute_zonal_instance_group_manager_hc_igm_tag]
87+
# [END compute_zonal_instance_group_manager_hc_parent_tag]

0 commit comments

Comments
 (0)