Compute Engine VM instances have Automatic Restart enabled
Google Compute Engine virtual machine instances are evaluated to ensure that Automatic Restart is enabled. This feature allows the Google Cloud Compute Engine service to automatically restart VM instances when they are terminated due to non-user-initiated reasons such as maintenance events, hardware failures, or software failures.
Risk
VM instances without Automatic Restart enabled will not recover automatically from host maintenance events or unexpected failures, potentially leading to prolonged service downtime and requiring manual intervention to restore services.
Run this check with Prowler
Run in Prowler Cloudprowler gcp --checks compute_instance_automatic_restart_enabledRecommendation
Enable the Automatic Restart feature for Compute Engine VM instances to enhance system reliability by automatically recovering from crashes or system-initiated terminations. This setting does not interfere with user-initiated shutdowns or stops.
Remediation
CLI
gcloud compute instances update <INSTANCE_NAME> --restart-on-failure --zone=<ZONE>Terraform
# Example: enable Automatic Restart for a Compute Engine VM instance
resource "google_compute_instance" "example" {
name = var.instance_name
machine_type = var.machine_type
zone = var.zone
scheduling {
automatic_restart = true
on_host_maintenance = "MIGRATE"
}
}Other
Check Code
from prowler.lib.check.models import Check, Check_Report_GCP
from prowler.providers.gcp.services.compute.compute_client import compute_client
class compute_instance_automatic_restart_enabled(Check):
"""
Ensure Compute Engine VM instances have Automatic Restart enabled.
Reports PASS if a VM instance has automatic restart enabled, otherwise FAIL.
"""
def execute(self) -> list[Check_Report_GCP]:
findings = []
for instance in compute_client.instances:
report = Check_Report_GCP(metadata=self.metadata(), resource=instance)
# Preemptible and Spot VMs cannot have automatic restart enabled
if instance.preemptible or instance.provisioning_model == "SPOT":
report.status = "FAIL"
report.status_extended = (
f"VM Instance {instance.name} is a Preemptible or Spot instance, "
"which cannot have Automatic Restart enabled by design."
)
elif instance.automatic_restart:
report.status = "PASS"
report.status_extended = (
f"VM Instance {instance.name} has Automatic Restart enabled."
)
else:
report.status = "FAIL"
report.status_extended = f"VM Instance {instance.name} does not have Automatic Restart enabled."
findings.append(report)
return findings