Complete the code to create a managed instance group with autohealing enabled.
resource "google_compute_instance_group_manager" "example" { name = "example-group" base_instance_name = "example-instance" zone = "us-central1-a" version { instance_template = google_compute_instance_template.example.self_link } auto_healing_policies { health_check = [1] initial_delay_sec = 300 } }
The auto_healing_policies block requires a health check resource link to monitor instance health and enable autohealing.
Complete the code to configure a global HTTP load balancer backend service with session affinity.
resource "google_compute_backend_service" "default" { name = "backend-service" protocol = "HTTP" load_balancing_scheme = "EXTERNAL" session_affinity = [1] backends { group = google_compute_instance_group.example.self_link } health_checks = [google_compute_health_check.default.self_link] }
Setting session_affinity to GENERATED_COOKIE enables the load balancer to route requests from the same client to the same backend using a generated cookie.
Fix the error in the health check configuration to enable HTTPS health checks.
resource "google_compute_health_check" "https_check" { name = "https-health-check" https_health_check { port = [1] request_path = "/healthz" } check_interval_sec = 10 timeout_sec = 5 healthy_threshold = 3 unhealthy_threshold = 3 }
HTTPS health checks must use port 443, the standard HTTPS port, to properly check the service.
Fill both blanks to configure an instance group with autoscaling based on CPU utilization.
resource "google_compute_autoscaler" "cpu_autoscaler" { name = "cpu-autoscaler" target = google_compute_instance_group_manager.example.self_link autoscaling_policy { max_replicas = [1] cpu_utilization { target = [2] } } }
The max_replicas sets the maximum number of instances to 5, and cpu_utilization.target is set to 0.6 (60%) to trigger scaling.
Fill all three blanks to configure a global forwarding rule for HTTPS traffic with a target proxy and SSL certificate.
resource "google_compute_global_forwarding_rule" "https_forwarding_rule" { name = "https-forwarding-rule" target = [1] port_range = [2] ip_protocol = [3] }
The forwarding rule targets the HTTPS proxy resource, listens on port 443, and uses TCP as the IP protocol for HTTPS traffic.