Google Cloud samples
Search for samples demonstrating the usage of Google Cloud products.
For Terraform samples, see Resource samples and Blueprints.
Configure stateful IP addresses on MIG creation
Configure stateful IP addresses when you create a managed instance group (MIG).
- Compute Engine
- Google Cloud
- Terraform
- Sample
Create an instance template for a MIG of GPU VMs
Create a global instance template that you can use to create a managed instance group (MIG) of GPU VMs.
- Google Cloud
- Compute Engine
- Terraform
- Sample
Create an endpoint to access Google APIs
Use an internal IP address and create Private Service Connect endpoints to connect to Google APIs.
- Google Cloud
- Compute Engine
- Terraform
- Sample
Create an instance with a virtual display device
This sample creates a f1-micro instance with a virtual display device in us-central1-c zone.
- Google Cloud
- Compute Engine
- Terraform
- Sample
Create a health check for autohealing in MIGs
The sample creates a global health check which you use to configure autohealing in a managed instance group (MIG).
- Compute Engine
- Google Cloud
- Terraform
- Sample
Reserve a static IP Address
Reserve a fixed IP address in a specific region.
- Google Cloud
- Compute Engine
- Terraform
- Sample
Create a firewall to allow health checks for autohealing in MIGs
This sample creates a firewall rule to allow health check probes to connect to your app when autohealing is configured in your MIG.
- Compute Engine
- Google Cloud
- Terraform
- Sample
Create an instance template
Use the specified machine type, boot disk and network to create an instance template.
- Compute Engine
- Google Cloud
- Java
- Node JS
- JavaScript
- Terraform
- Go
- Python
- Sample
Create a regional MIG with a target distribution shape
Create a regional managed instance group (MIG) with BALANCED target distribution shape.
- Compute Engine
- Google Cloud
- Terraform
- Sample
Enable OS Login for a Cloud Project
Use this sample to enable OS Login to all instances in a project.
- Compute Engine
- Google Cloud
- Terraform
- Sample
Create a VM in a subnet
Create a VM in a custom VPC network and a specific subnet.
- Compute Engine
- Google Cloud
- JavaScript
- Python
- Go
- Java
- Terraform
- Node JS
- Sample
Set stateful metadata on VM instance creation in a MIG
In a managed instance group (MIG), create a managed instance with a custom name and set stateful metadata on that VM.
- Compute Engine
- Google Cloud
- Terraform
- Sample
Create a VM instance
Create a VM instance in the specified project and zone.
- Compute Engine
- Google Cloud
- Node JS
- Go
- C#
- Python
- Ruby
- PHP
- JavaScript
- Java
- Terraform
- Sample
Create an instance with a shutdown script for Apache server
Create an instance with a shutdown script for Apache server
- Google Cloud
- Compute Engine
- Terraform
- Sample
Create a Compute Engine instance static IP address
Create a Compute Engine instance with a fixed IP address in a specified region.
- Google Cloud
- Compute Engine
- Terraform
- Sample
Create a local reservation
Create a single-project reservation for N2 machine types
- Google Cloud
- Compute Engine
- Terraform
- Sample
Create a MIG with stateful disks
Create a managed instance group (MIG) that preserves disks for all VMs in the group.
- Google Cloud
- Compute Engine
- Terraform
- Sample
Add OS login admin permissions for Compute Engine Service Agent
Use this example to add OS Login admin role to the Compute Engine service account.
- Compute Engine
- Google Cloud
- Terraform
- Sample
Configure static IP addresses on VM creation in a MIG
Configure static IP addresses on VM creation in a managed instance group (MIG).
- Compute Engine
- Google Cloud
- Terraform
- Sample
Create a VM with a local SSD
Attach a local SSD to a VM during VM creation.
- Compute Engine
- Google Cloud
- Java
- JavaScript
- Python
- Terraform
- Go
- Node JS
- Sample
Configure stateful disks individually for VMs in a MIG
This sample configures stateful disks individually for VMs in a managed instance group (MIG) by configuring the per-instance configuration of that VM.
- Compute Engine
- Google Cloud
- Terraform
- Sample
Create a regional MIG
Create a MIG with VMs evenly distributed across multiple zones in a region.
- Google Cloud
- Compute Engine
- Terraform
- Sample
Create a firewall rule
Create a firewall rule that allows incoming HTTP and HTTPS access from the entire internet.
- Compute Engine
- Google Cloud
- Java
- Node JS
- C#
- PHP
- Ruby
- Terraform
- Python
- Go
- JavaScript
- Sample
Create a custom VPC Subnet
Create a subnet with a custom IP address range.
- Compute Engine
- Google Cloud
- Terraform
- Sample
Add SSH key to instance metadata
Add a public SSH key to the instance metadata during VM creation.
- Google Cloud
- Compute Engine
- Terraform
- Sample
Run a VM as a service account
Assign a service account for a VM, add access scopes, and set up the VM to run as a service account.
- Google Cloud
- Compute Engine
- Terraform
- Sample
Create a disk snapshot
Create a zonal or a regional snapshot of a disk in the specified Cloud Storage location.
- Compute Engine
- Google Cloud
- JavaScript
- Node JS
- Terraform
- Python
- Java
- Go
- Sample
Configure autoscaling in a managed instance group (MIG)
Configure autoscaling based on CPU utilization in a zonal MIG.
- Compute Engine
- Google Cloud
- Terraform
- Sample
Create Spot Instance
Create a spot instance using scheduling block
- Compute Engine
- Google Cloud
- Terraform
- Sample
Create a VM with a custom hostname
Create a VM with a custom hostname that conforms to the RFC 1035 requirements for valid hostnames.
- Compute Engine
- Google Cloud
- JavaScript
- Terraform
- Go
- Java
- Node JS
- Python
- Sample
Add SSH key to project metadata
Add a public SSH key to the project metadata during VM creation.
- Compute Engine
- Google Cloud
- Terraform
- Sample
Add a public SSH key to your Google account
Associate a public SSH key with your Google account for VMs that use OS Login.
- Google Cloud
- Compute Engine
- Terraform
- Sample
Create an instance template for a MIG with preemptible VMs
Create an instance template which you can use to create a managed instance group (MIG) with preemptible VMs.
- Compute Engine
- Google Cloud
- Terraform
- Sample
Configure an autohealing policy in a MIG
This sample configures an autohealing policy to apply health check in a managed instance group (MIG).
- Compute Engine
- Google Cloud
- Terraform
- Sample
Create a regional MIG with proactive instance redistribution disabled
Create a regional managed instance group (MIG) with proactive instance redistribution disabled.
- Google Cloud
- Compute Engine
- Terraform
- Sample
Create a Compute Engine instance with OS Login
Create a Compute Engine instance with OS Login enabled
- Google Cloud
- Compute Engine
- Terraform
- Sample
Create a persistent disk with Debian image on SSD
Create a persistent disk with Debian image on SSD
- Google Cloud
- Compute Engine
- Terraform
- Sample
Increase a managed instance group's (MIG's) size limit
The sample creates a zonal MIG and increases the MIG's size limit from 1,000 VMs (default) to 2,000 VMs. The size limit increases when you enable pagination by setting the list_managed_instances_results argument to PAGINATED.
- Compute Engine
- Google Cloud
- Terraform
- Sample
Create a MIG with stateful disks that are deleted when its VM gets permanently deleted
This sample creates a managed instance group (MIG) with stateful disks and sets the disks to delete when its VM is permanently deleted from the MIG.
- Google Cloud
- Compute Engine
- Terraform
- Sample