Prepare and test your skills
Prepare and test your skills
Automated resource configuration and lifecycle management is the practice of defining compute configuration once and letting Google Cloud create and maintain identical virtual machines automatically. In Compute Engine, a Compute Engine instance template holds the standard definition, instance metadata carries per-machine configuration, and a managed instance group (MIG) (opens in a new tab) uses the template to deploy and maintain virtual machines (VMs) at a desired size. The MIG depends on the instance template, so every replica inherits the same configuration and self-heals from the same blueprint.
A Compute Engine instance template is an immutable blueprint that standardizes every VM created from it, so development, test, and production machines stay consistent. Every instance in the group inherits the same machine type, boot image, network, and labels from that template, and the MIG controller recreates failed VMs from it. When configuration must change, a new template version is created and the group rolls to it, rather than editing running VMs one by one.
An instance template standardizes the following configuration for automated deployment:
e2-small or e2-standard-2 with a boot image from debian-cloud/debian-12 or debian-13, with auto_delete and boot set to true.allow-ssh, load-balanced-backend, http-server, or allow-health-check, which firewall rules and load balancer backends match against.automatic_restart and MIGRATE on host maintenance.Instance metadata is configuration data attached to the instance template that each VM can read at boot, and the startup-script metadata key carries a shell script that runs automatically on first boot. Data flows from the template metadata to each new instance, then the guest operating system executes the script to install software, write files, and start services without manual login. Because the same script runs on every replica, all MIG members converge to the same application state.
A typical startup script first updates packages, then installs and configures a web server, then personalizes the page using the metadata server. The script queries the metadata server at http://metadata.google.internal or http://169.254.169.254 with the header Metadata-Flavor: Google to learn its own instance name, hostname, or internal IP, writes that value to /var/www/html/index.html, and restarts apache2 or nginx. In Terraform this appears as metadata = { startup-script = <<EOF ... }, in gcloud as --metadata=startup-script='#! /bin/bash...', and in the console as the Management > Startup script field, but all three deliver the same boot-time automation.
A managed instance group (MIG) is the Compute Engine resource that automates deployment and lifecycle by creating and maintaining VMs from a referenced instance template. The MIG controller keeps the group at its targetSize, such as 2 instances, names new VMs from its baseInstanceName like vm or l7-ilb-backend-example, and recreates any failed instance from the same template so capacity self-heals. Traffic flows from the load balancer backend service to each MIG member through a named port, such as http:80, https:443, or tcp443:443, which maps a logical service name to the serving port on the instances.
Deploying a standardized compute tier follows an ordered workflow:
startup-script metadata that installs the application.targetSize to 2 for the initial replica count.Off for a fixed size of 2, or turn it On so the autoscaler adds or removes instances based on CPU usage, and use create_before_destroy = true so a new template version is created before the old one is removed.Exam tip: Choose a new instance template version when configuration must change; existing MIG instances do not pick up template edits, they are replaced from the new template.
VM Manager (opens in a new tab) is a suite of tools for managing operating systems for large fleets of Windows and Linux virtual machines (VMs) running on Compute Engine. VM Manager drives efficiency through automation and reduces the operational burden of keeping many VMs secure and consistent. The suite divides the work among three services that share the same on-VM agent but serve different purposes.
| Service | Primary unit | Use when |
|---|---|---|
| Patch | Patch job or patch deployment | You need to apply on-demand or scheduled operating system updates and report patch compliance |
| OS inventory management | Collected inventory data | You need to collect and review operating system information such as installed packages and updates |
| OS policies | OS policy assignment | You need to install, remove, or auto-update software packages to maintain a desired state |
The services combine into one operating model where OS inventory management shows what is installed and missing, Patch remediates vulnerabilities with updates, and OS policies keep required packages in their desired state.
VM Manager foundation is the project setup and on-VM agent that must be active before Patch, OS policies, or OS inventory management can run. VM Manager is enabled when the OS Config service API is turned on for the Google Cloud project and the OS Config agent on each VM is activated through instance metadata. The OS Config agent is preinstalled on most images but stays inactive until the required metadata values are set, and enablement can be automatic for a whole project or manual per VM or project.
The OS Config agent depends on the VM's normal update sources to do its work. For Patch and OS policies, the agent calls operating system utilities such as yum, apt, rpm, or the Windows Update Agent to retrieve patches from the OS package or update source and apply them to the VM. The VMs must therefore be able to reach package sources and repositories, and VMs in private networks can use Private Google Access for that access. VM Manager supports only operating systems configured with an English locale, because a non-English locale can prevent the agent from parsing package manager output and cause Patch, inventory, and policy features to fail.
VM Manager also uses a Google-managed OS Config Service Agent with the email service-PROJECT_NUMBER@gcp-sa-osconfig.iam.gserviceaccount.com and the Cloud OS Config Service Agent role (roles/osconfig.serviceAgent). The service agent collects VM information on behalf of the project when Patch starts a patch job and filters VM data, while OS policies does not use this service agent. Owners have full access to run patch jobs, while other users need granular roles such as roles/osconfig.patchJobExecutor to run and manage jobs or roles/osconfig.patchJobViewer for read-only access.
Patch is the VM Manager service for applying on-demand and scheduled operating system patches across a group of VMs. A patch job targets VMs through an instance filter, applies a patch configuration that can differ by operating system, and controls reboot and rollout behavior. For Windows VMs, Google recommends disabling Windows automatic updates to reduce conflicts between automatic updates and the Patch service, and by default Patch applies only Windows operating system patches unless patching for Microsoft software such as SQL Server or .NET Framework is separately enabled.
A patch job moves data and control through an ordered sequence from configuration to verification:
dist-upgrade for apt, security and minimal options for yum, categories or severities for zypper, and classifications such as critical and security for Windows.Safe fleet patching depends on targeting, staging, and disruption limits. Organize instances with labels such as env:dev, env:prod, and tier:frontend so jobs target specific groups, and stagger jobs zone by zone rather than patching all production zones at once. Rollout options are zone-by-zone, which patches one zone at a time, or concurrent zones, which patches all selected zones at once, plus a zone disruption budget that sets the maximum number or percentage of VMs per zone to disrupt at any moment. A VM counts as disrupted from the time the agent is notified to begin until patching, reboot, and post-patch steps complete, and a VM also counts against the budget if patching, pre-patch or post-patch steps, or success notification fails or times out.
Patch has special defaults for managed instance groups (MIGs) and unpatchable systems. By default, VM Manager does not patch VMs that are part of a MIG, and patching them requires setting migInstancesAllowed to true. Patching MIG members carries tradeoffs because MIG repair recreates a VM from its instance template and can revert it to an unpatched state, while autoscaling can delete patched VMs when load falls and create new unpatched VMs from the template when load rises. Setting skipUnpatchableVms to true lets a job skip VMs whose operating systems do not support patching, such as Container-Optimized OS.
Exam tip: Patch jobs deploy and run only for VMs in a single Google Cloud project, even with Shared VPC, but patch compliance data can still be viewed across projects in an organization or folder dashboard.
OS inventory management is the VM Manager service that collects and stores operating system information for review and compliance. The OS Config agent collects inventory data on each VM, and that data flows from the agent to instance metadata and to log streams where it can be queried with the Google Cloud CLI. For broader analysis, Cloud Asset Inventory snapshots and OS inventory data can be exported to BigQuery to check VM Manager enablement, agent versions, operating system distributions, and vulnerability data.
The Patch dashboard in the Google Cloud console turns inventory and patch data into fleet compliance views. The operating system overview shows total VMs by operating system, but a VM appears there only when the OS Config agent is installed and OS inventory management is enabled. A VM shown as No data is unresponsive, missing the agent, missing inventory enablement, running an unsupported operating system, or a combination of those conditions.
Patch compliance status groups each VM by the most severe updates available:
At organization or folder scale, the same dashboard supports a patch summary across all projects, showing patch compliance, available updates, and reboot requirements without running a cross-project patch job. Vulnerability reports use Cloud Asset Inventory exports to BigQuery to identify Common Vulnerabilities and Exposures (CVEs) across the organization, so teams can target the next patch jobs to the VMs and severities that matter most for a secure posture.
Infrastructure as Code (IaC) is the practice of defining infrastructure provisioning and configuration in code files instead of manual console or command-line steps. The code files are stored in source control so they are discoverable, versioned, and audited like application code. Because changes flow through continuous integration and continuous deployment (CI/CD) pipelines, every change can be automatically tested and deployed the same way, which minimizes human error and improves consistency, reproducibility, and resilience.
Immutable infrastructure is the approach where deployed resources are never modified in place after deployment. The resource definition is updated in the source repository, the change is tested and validated, and then the resource is fully redeployed from the new configuration. A virtual machine, Kubernetes cluster, or firewall rule is therefore re-created rather than tweaked. This pattern produces more predictable deployments and rollbacks and mitigates configuration drift and snowflake servers, which are one-off machines that cannot be reliably reproduced.
Terraform (opens in a new tab) is the recommended tool for defining and provisioning Google Cloud infrastructure resources declaratively on Google Cloud. Configuration files declare the desired state, and Terraform creates, updates, or destroys resources to match that state. The Terraform workflow depends on the stored configuration as the source of truth, while the Terraform state maps that configuration to real deployed resources.
Typical resources managed this way include compute, serving, and storage layers that must scale together:
Infrastructure Manager automates the creation and management of Google Cloud resources from Terraform configurations without operating a separate automation server. Config Connector manages Google Cloud resources as Kubernetes objects in Kubernetes-centric environments. Google Cloud also supports third-party configuration tools including Chef and Puppet.
Cluster Toolkit is the collection of modular Terraform templates that accelerates consistent provisioning of complex environments. The toolkit offers Google-curated example blueprints for ready-to-use high-performance computing (HPC), artificial intelligence (AI), and machine learning (ML) clusters in Slurm or GKE. Teams customize the Terraform code, store it in a version control system such as Git, and integrate it into CI/CD pipelines with Cloud Build.
Version-controlled IaC enables automated testing and promotion across environments. Triggers start automatic updates on code commits, and pipeline steps run validation such as terraform validate and terraform plan before apply. Configurations are stored as versioned artifacts, and environment promotion moves the same tested code from dev to staging to prod. For virtual machines, bake images with a tool like Packer so Terraform only launches pre-baked images, pass configuration through instance metadata, and avoid provisioner blocks except as a last resort. This combination of modular templates, versioning, and pipeline automation makes deployments repeatable, enables rollbacks, and keeps development, staging, and production environments consistent while allowing distinct configurations per environment.
Terraform state is the record that maps configuration files to real deployed resources, and consistent state management prevents conflicts and drift. Production state is stored in a central location, typically a Cloud Storage backend configured with a bucket and prefix, so every pipeline run and operator works from the same source of truth. If a configuration tries to create a resource that already exists, Terraform exits with a 409 conflict error, which is resolved by deleting the duplicate or importing the existing resource into Terraform state. Drift is monitored and managed at higher maturity levels rather than left unhandled.
Declarative configuration management keeps resources consistent after initial provisioning. With Config Connector, Agent Platform datasets, models, and endpoints, Cloud SQL instances, Pub/Sub topics, and Cloud Storage buckets are defined in YAML manifests and deployed to a GKE cluster. The manifests integrate application and infrastructure configuration, templating handles differences between environments, and CI/CD pipelines automate updates. Identity and Access Management (IAM) policies and service accounts are also defined in IaC so access stays consistent and auditable.
Exam tip: google_*_iam_policy and google_*_iam_binding are authoritative and overwrite all permissions on the resource to match the configuration, which can remove Google-managed roles, while google_*_iam_member adds a single non-authoritative grant.
Infrastructure Manager orchestration is the managed execution of Terraform deployments in an ephemeral Cloud Build environment that is discarded after the run. The deployment package is downloaded from a storage bucket or Git repository, executed, and recorded with metadata in a Cloud Storage bucket that can be queried for deployment status, resource lists, and resource details. You specify a supported Terraform version for each deployment, and you must not include personal or sensitive information in configuration values.
When a deployment runs, data flows from the stored Terraform module to the Cloud Build job to the provisioned Google Cloud resources in this order:
terraform init to prepare the working directory and backend.terraform validate to check configuration syntax.terraform apply to provision resources, or terraform destroy when deleting a deployment.terraform init or terraform apply a limited number of times.The Terraform maturity model describes how automation, consistency, and governance grow from manual experimentation to scaled operation. Learners in the Adopt stage focus on learning Terraform, Builders in the Build stage expand projects and customizations, and Operators in the Scale stage provision workloads at scale with policies and self-service workflows.
| Stage | Configuration and state | Deployment and automation |
|---|---|---|
| Adopt | Unstructured configuration in varied locations, state not stored | Manual deployment with none or limited automation and consistency |
| Build | Structured configuration in a central location, state stored centrally | Automated deployment with CI/CD pipeline, drift monitored and managed, review required |
| Scale | Structured configuration versioned in version control, state stored centrally | Automated deployment with CI/CD pipeline, integrated with a cloud management platform, high concern for security and compliance |
Movement from Adopt to Scale increases the range of managed resources, documentation quality, and cost, security, and compliance controls. At Scale, Terraform is operated through Infrastructure Manager, Terraform open source with custom pipelines, or Terraform Enterprise on Google Cloud.
http:80 that maps a service name to the serving port.yum, apt, or the Windows Update Agent to apply patches, so VMs must be able to reach package sources.google_*_iam_policy and google_*_iam_binding overwrite all permissions on a resource, while google_*_iam_member adds a single non-authoritative grant.A managed instance group uses a referenced Compute Engine instance template as an immutable blueprint to create and maintain virtual machines at a desired size. The controller keeps the group at its targetSize such as 2, names new virtual machines from its baseInstanceName, recreates any failed instance from the same template so capacity self-heals, and exposes the serving port through a named port that maps a logical service name to the serving port on the instances.
Patch applies on-demand and scheduled operating system updates across virtual machines and reports patch compliance, OS inventory management collects and stores operating system information such as installed packages for review and compliance, and OS policies installs, removes, or auto-updates software packages to maintain a desired state. Inventory shows what is installed and missing, Patch remediates vulnerabilities with updates, and OS policies keeps required packages in their desired state.
Instance metadata attached to the instance template carries configuration data that each virtual machine reads at boot, and the startup-script metadata key carries a shell script that runs automatically on first boot. The guest operating system executes the same script on every replica to install software, write files, and start services without manual login, and the script can query the metadata server with the Metadata-Flavor Google header to learn its own instance name, hostname, or internal IP and personalize the web page before restarting the web server.
An enterprise is designing a scalable, highly available compute infrastructure on Google Cloud for a stateless web service. The deployment must satisfy the following architectural requirements:
Which strategy should the architect implement to automate and standardize this resource configuration?
Last updated