Back to Checks
gcp

Compute Engine VM instances have Automatic Restart enabled

compute_instance_automatic_restart_enabled
Service: computeSeverity: medium
OfficialBuilt-inVerified
Categories:resilience
Resource Type:compute.googleapis.com/Instance

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 Cloud
Run
prowler gcp --checks compute_instance_automatic_restart_enabled

Recommendation

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

11) Open Google Cloud Console → Compute Engine → VM instances
22) Click on the instance name to view details
33) Click 'Edit' at the top of the page
44) Under 'Availability policies', set 'Automatic restart' to 'On (recommended)'
55) Click 'Save' at the bottom of the page

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