{"id":30068,"date":"2026-12-05T22:05:15","date_gmt":"2026-12-05T22:05:15","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=30068"},"modified":"2026-12-05T22:05:15","modified_gmt":"2026-12-05T22:05:15","slug":"terraform-tutorial-with-google-cloud-create-single-vm-network","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/terraform-tutorial-with-google-cloud-create-single-vm-network\/","title":{"rendered":"Terraform Tutorial with Google Cloud &#8211; Create Single VM &#038; Network"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">This tutorial uses Terraform to create a Google Compute Engine VM on Google Cloud, either in a new auto-mode VPC network or in the project&#039;s <code>default<\/code> network. Below the original examples you&#039;ll find a corrected, ready-to-run version with a current Debian image, variables, a firewall rule and outputs. It also covers authentication, the full init-plan-apply-destroy workflow and fixes for the errors you&#039;re most likely to hit.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">provider <span class=\"hljs-string\">\"google\"<\/span> {\n  project = <span class=\"hljs-string\">\"{{YOUR GCP PROJECT}}\"<\/span>\n  region  = <span class=\"hljs-string\">\"us-central1\"<\/span>\n  zone    = <span class=\"hljs-string\">\"us-central1-c\"<\/span>\n}\n\nresource <span class=\"hljs-string\">\"google_compute_instance\"<\/span> <span class=\"hljs-string\">\"vm_instance\"<\/span> {\n  name         = <span class=\"hljs-string\">\"terraform-instance\"<\/span>\n  machine_type = <span class=\"hljs-string\">\"e2-micro\"<\/span>\n\n  boot_disk {\n    initialize_params {\n      image = <span class=\"hljs-string\">\"debian-cloud\/debian-9\"<\/span>\n    }\n  }\n\n  network_interface {\n    <span class=\"hljs-comment\"># A default network is created for all GCP projects<\/span>\n    network = google_compute_network.vpc_network.self_link\n    access_config {\n    }\n  }\n}\n\nresource <span class=\"hljs-string\">\"google_compute_network\"<\/span> <span class=\"hljs-string\">\"vpc_network\"<\/span> {\n  name                    = <span class=\"hljs-string\">\"terraform-network\"<\/span>\n  auto_create_subnetworks = <span class=\"hljs-string\">\"true\"<\/span>\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">\r\nresource <span class=\"hljs-string\">\"google_compute_instance\"<\/span> <span class=\"hljs-string\">\"default\"<\/span> {\r\n  name         = <span class=\"hljs-string\">\"test\"<\/span>\r\n  machine_type = <span class=\"hljs-string\">\"e2-medium\"<\/span>\r\n  zone         = <span class=\"hljs-string\">\"us-central1-a\"<\/span>\r\n\r\n  tags = &#91;<span class=\"hljs-string\">\"foo\"<\/span>, <span class=\"hljs-string\">\"bar\"<\/span>, <span class=\"hljs-string\">\"ramu\"<\/span>]\r\n\r\n  boot_disk {\r\n    initialize_params {\r\n      image = <span class=\"hljs-string\">\"debian-cloud\/debian-9\"<\/span>\r\n    }\r\n  }\r\n\r\n  network_interface {\r\n    network = <span class=\"hljs-string\">\"default\"<\/span>\r\n\r\n    access_config {\r\n      <span class=\"hljs-comment\">\/\/ Ephemeral public IP<\/span>\r\n    }\r\n  }\r\n\r\n  metadata = {\r\n    foo = <span class=\"hljs-string\">\"bar\"<\/span>\r\n  }\r\n\r\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">What the two examples above do<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong>first example<\/strong> creates two resources. <code>google_compute_network.vpc_network<\/code> is a new VPC called <code>terraform-network<\/code> in auto mode, which means Google creates one subnet in every region. <code>google_compute_instance.vm_instance<\/code> is an <code>e2-micro<\/code> VM attached to that network. The VM refers to the network through <code>google_compute_network.vpc_network.self_link<\/code>. Terraform reads that reference as a dependency, so it creates the network first and deletes it last.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong>second example<\/strong> creates one <code>e2-medium<\/code> VM in the project&#039;s existing <code>default<\/code> network. It also shows network tags (<code>tags<\/code>), which firewall rules use to target instances, and custom instance <code>metadata<\/code>, which software on the VM can read from the metadata server. In both examples, the empty <code>access_config {}<\/code> block gives the VM an ephemeral public IP. Remove that block if the VM should have only a private IP.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong> Neither example will work exactly as written today. The <code>debian-cloud\/debian-9<\/code> image family is end-of-life and has been removed from the public images. The second example also assumes a <code>default<\/code> network exists, and many organisations delete it or block it with policy. The corrected version below fixes both problems.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites and authentication<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A Google Cloud project with billing enabled, and its project ID (not the display name).<\/li>\n\n\n<li>Terraform CLI installed (<code>terraform -version<\/code>).<\/li>\n\n\n<li>Google Cloud CLI installed (<code>gcloud --version<\/code>).<\/li>\n\n\n<li>An account with permission to create Compute Engine resources, for example the Compute Admin role on the project.<\/li>\n<\/ul>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\"># Log in and set the project for gcloud commands<\/span>\ngcloud auth login\ngcloud config set project YOUR_PROJECT_ID\n\n<span class=\"hljs-comment\"># Create Application Default Credentials, which the Terraform Google provider uses<\/span>\ngcloud auth application-<span class=\"hljs-keyword\">default<\/span> login\n\n<span class=\"hljs-comment\"># Enable the Compute Engine API (the first enable can take a minute)<\/span>\ngcloud services enable compute.googleapis.com<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">In CI pipelines, use a service account through Workload Identity Federation or the runner&#039;s attached identity rather than user credentials. Avoid downloading long-lived service account JSON keys where you can.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Corrected and complete configuration<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Put these files in an empty directory. This version builds on the first example. It adds a <code>terraform<\/code> block that pins the provider source, swaps the hard-coded project placeholder for a variable, uses a supported Debian image and adds a firewall rule so you can actually SSH to the VM.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\"># versions.tf<\/span>\nterraform {\n  required_providers {\n    google = {\n      source  = <span class=\"hljs-string\">\"hashicorp\/google\"<\/span>\n      version = <span class=\"hljs-string\">\"&gt;= 5.0\"<\/span> <span class=\"hljs-comment\"># pin to the major version you have tested<\/span>\n    }\n  }\n}\n\nprovider <span class=\"hljs-string\">\"google\"<\/span> {\n  project = <span class=\"hljs-keyword\">var<\/span>.project_id\n  region  = <span class=\"hljs-keyword\">var<\/span>.region\n  zone    = <span class=\"hljs-keyword\">var<\/span>.zone\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\"># variables.tf<\/span>\nvariable <span class=\"hljs-string\">\"project_id\"<\/span> {\n  description = <span class=\"hljs-string\">\"GCP project ID\"<\/span>\n  type        = string\n}\n\nvariable <span class=\"hljs-string\">\"region\"<\/span> {\n  type    = string\n  <span class=\"hljs-keyword\">default<\/span> = <span class=\"hljs-string\">\"us-central1\"<\/span>\n}\n\nvariable <span class=\"hljs-string\">\"zone\"<\/span> {\n  type    = string\n  <span class=\"hljs-keyword\">default<\/span> = <span class=\"hljs-string\">\"us-central1-c\"<\/span>\n}\n\nvariable <span class=\"hljs-string\">\"ssh_source_ranges\"<\/span> {\n  description = <span class=\"hljs-string\">\"CIDRs allowed to SSH. 35.235.240.0\/20 is the IAP TCP forwarding range.\"<\/span>\n  type        = <span class=\"hljs-keyword\">list<\/span>(string)\n  <span class=\"hljs-keyword\">default<\/span>     = &#91;<span class=\"hljs-string\">\"35.235.240.0\/20\"<\/span>]\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\"># main.tf<\/span>\nresource <span class=\"hljs-string\">\"google_compute_network\"<\/span> <span class=\"hljs-string\">\"vpc_network\"<\/span> {\n  name                    = <span class=\"hljs-string\">\"terraform-network\"<\/span>\n  auto_create_subnetworks = <span class=\"hljs-keyword\">true<\/span>\n}\n\nresource <span class=\"hljs-string\">\"google_compute_firewall\"<\/span> <span class=\"hljs-string\">\"allow_ssh\"<\/span> {\n  name    = <span class=\"hljs-string\">\"terraform-allow-ssh\"<\/span>\n  network = google_compute_network.vpc_network.name\n\n  allow {\n    protocol = <span class=\"hljs-string\">\"tcp\"<\/span>\n    ports    = &#91;<span class=\"hljs-string\">\"22\"<\/span>]\n  }\n\n  source_ranges = <span class=\"hljs-keyword\">var<\/span>.ssh_source_ranges\n  target_tags   = &#91;<span class=\"hljs-string\">\"ssh\"<\/span>]\n}\n\nresource <span class=\"hljs-string\">\"google_compute_instance\"<\/span> <span class=\"hljs-string\">\"vm_instance\"<\/span> {\n  name         = <span class=\"hljs-string\">\"terraform-instance\"<\/span>\n  machine_type = <span class=\"hljs-string\">\"e2-micro\"<\/span>\n  tags         = &#91;<span class=\"hljs-string\">\"ssh\"<\/span>]\n\n  boot_disk {\n    initialize_params {\n      image = <span class=\"hljs-string\">\"debian-cloud\/debian-12\"<\/span>\n    }\n  }\n\n  network_interface {\n    network = google_compute_network.vpc_network.self_link\n    access_config {} <span class=\"hljs-comment\"># ephemeral public IP<\/span>\n  }\n\n  metadata = {\n    environment = <span class=\"hljs-string\">\"lab\"<\/span>\n  }\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\"># outputs.tf<\/span>\noutput <span class=\"hljs-string\">\"instance_name\"<\/span> {\n  value = google_compute_instance.vm_instance.name\n}\n\noutput <span class=\"hljs-string\">\"public_ip\"<\/span> {\n  value = google_compute_instance.vm_instance.network_interface&#91;<span class=\"hljs-number\">0<\/span>].access_config&#91;<span class=\"hljs-number\">0<\/span>].nat_ip\n}\n\noutput <span class=\"hljs-string\">\"internal_ip\"<\/span> {\n  value = google_compute_instance.vm_instance.network_interface&#91;<span class=\"hljs-number\">0<\/span>].network_ip\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\"># terraform.tfvars<\/span>\nproject_id = <span class=\"hljs-string\">\"your-project-id\"<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">A new custom VPC has only implied rules: all egress is allowed and all ingress is denied. Without the firewall rule, the VM boots normally but no SSH connection can reach it. The rule applies only to instances with the <code>ssh<\/code> network tag, and the VM has that tag.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Run the workflow<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><code>terraform init<\/code> downloads the Google provider and creates <code>.terraform\/<\/code> and <code>.terraform.lock.hcl<\/code>. Commit the lock file to version control.<\/li>\n\n\n<li><code>terraform fmt<\/code> and <code>terraform validate<\/code> fix formatting and catch syntax or type errors before any API call is made.<\/li>\n\n\n<li><code>terraform plan<\/code> shows what will be created. Expect <code>Plan: 3 to add, 0 to change, 0 to destroy.<\/code><\/li>\n\n\n<li><code>terraform apply<\/code> repeats the plan and asks for <code>yes<\/code>. On success it prints <code>Apply complete! Resources: 3 added, 0 changed, 0 destroyed.<\/code> followed by the outputs.<\/li>\n\n\n<li>Connect to the VM with <code>gcloud compute ssh terraform-instance --zone us-central1-c --tunnel-through-iap<\/code>.<\/li>\n\n\n<li><code>terraform destroy<\/code> removes the VM, the firewall rule and the network, in reverse dependency order, when you are finished.<\/li>\n<\/ol>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">terraform init\nterraform fmt\nterraform validate\nterraform plan -out=tfplan\nterraform apply tfplan\nterraform output public_ip\n\n<span class=\"hljs-comment\"># verify from gcloud<\/span>\ngcloud compute instances <span class=\"hljs-keyword\">list<\/span> --filter=<span class=\"hljs-string\">\"name=terraform-instance\"<\/span>\n\n<span class=\"hljs-comment\"># clean up<\/span>\nterraform destroy<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong> When you run <code>terraform apply tfplan<\/code>, Terraform applies the saved plan without asking again. Use this pattern in pipelines so that exactly what was reviewed is what gets applied.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Making the second example work<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The second example has no provider block, so it inherits the project from the provider configuration in the same directory. If you copy it into the configuration above, change the image to <code>debian-cloud\/debian-12<\/code>. Then check that the <code>default<\/code> network exists with <code>gcloud compute networks list<\/code>. Also note that its <code>zone = &quot;us-central1-a&quot;<\/code> argument overrides the provider&#039;s default zone for that one instance.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>default<\/code> network comes with a <code>default-allow-ssh<\/code> rule that opens port 22 to <code>0.0.0.0\/0<\/code>. That is convenient for a lab and risky for anything else. Network tags such as <code>foo<\/code>, <code>bar<\/code> and <code>ramu<\/code> have no effect until a firewall rule targets them. Tags must be lowercase letters, digits and hyphens.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common errors and fixes<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Error<\/th><th>Cause<\/th><th>Fix<\/th><\/tr><\/thead><tbody><tr><td><code>Compute Engine API has not been used in project ... or it is disabled<\/code><\/td><td>API not enabled<\/td><td><code>gcloud services enable compute.googleapis.com<\/code>, wait a minute, then retry<\/td><\/tr><tr><td><code>could not find default credentials<\/code><\/td><td>No Application Default Credentials<\/td><td><code>gcloud auth application-default login<\/code> or set <code>GOOGLE_APPLICATION_CREDENTIALS<\/code><\/td><\/tr><tr><td><code>The resource &#039;projects\/debian-cloud\/global\/images\/family\/debian-9&#039; was not found<\/code><\/td><td>Debian 9 image removed<\/td><td>Use a current family such as <code>debian-cloud\/debian-12<\/code><\/td><\/tr><tr><td><code>The resource &#039;projects\/...\/global\/networks\/default&#039; was not found<\/code><\/td><td>Default network deleted or never created<\/td><td>Create your own network as in the corrected configuration<\/td><\/tr><tr><td><code>Error 403 ... Required &#039;compute.instances.create&#039; permission<\/code><\/td><td>Missing IAM role or wrong project ID<\/td><td>Grant a Compute role, then check that <code>project_id<\/code> is the ID, not the name<\/td><\/tr><tr><td><code>ZONE_RESOURCE_POOL_EXHAUSTED<\/code><\/td><td>No capacity for that machine type in the zone<\/td><td>Change <code>zone<\/code> or <code>machine_type<\/code> and apply again<\/td><\/tr><tr><td>SSH times out<\/td><td>No ingress rule or wrong source range<\/td><td>Check the firewall rule, its <code>target_tags<\/code> and your source CIDR<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Best practices<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Store state in a remote backend such as a GCS bucket with object versioning, not on a laptop. The state file contains resource details and sometimes secrets.<\/li>\n\n\n<li>Don&#039;t put project IDs, credentials or SSH keys in <code>.tf<\/code> files. Use variables, <code>tfvars<\/code> files kept out of Git and a secrets manager.<\/li>\n\n\n<li>Prefer IAP or a bastion host over public IPs. Remove <code>access_config {}<\/code> on VMs that don&#039;t need internet ingress and use Cloud NAT for outbound traffic.<\/li>\n\n\n<li>For production, use custom-mode VPCs (<code>auto_create_subnetworks = false<\/code>) with explicitly defined <code>google_compute_subnetwork<\/code> resources and planned CIDR ranges.<\/li>\n\n\n<li>Attach a dedicated, minimally scoped service account to VMs instead of the Compute Engine default service account.<\/li>\n\n\n<li>Run <code>terraform fmt<\/code>, <code>validate<\/code> and a security scanner such as tfsec in pre-commit hooks or CI.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Frequently asked questions<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Is the e2-micro VM in this tutorial free?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Google Cloud&#039;s free tier has historically included one e2-micro instance per month in some US regions, including us-central1. Usage limits apply, along with charges for things like egress. Check the current free tier terms for your account before relying on it.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Why can&#039;t I SSH into a VM created in a new Terraform VPC?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A new custom VPC denies all ingress by default. Add a <code>google_compute_firewall<\/code> rule that allows TCP 22 from your IP or from the IAP range <code>35.235.240.0\/20<\/code>, and give the VM a matching network tag.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What is the difference between auto mode and custom mode VPC networks?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">With <code>auto_create_subnetworks = true<\/code>, Google creates one subnet in every region from a fixed IP range. Custom mode (<code>false<\/code>) creates no subnets, so you define each subnet and its CIDR yourself. That&#039;s why it&#039;s the usual choice for production.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How do I find a valid image name for boot_disk?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Run <code>gcloud compute images list --filter=&quot;family~debian&quot;<\/code> or browse the public image projects. Referencing a family such as <code>debian-cloud\/debian-12<\/code> gives you the latest image in that family.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How do I give the VM only a private IP?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Remove the <code>access_config {}<\/code> block from <code>network_interface<\/code>. To give the VM outbound internet access, add a Cloud Router and Cloud NAT, and use IAP for SSH.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Related tutorials<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/category\/infrastructure-as-code\/terraform\/\">More Terraform tutorials<\/a><\/li>\n\n\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/category\/cloud-computing\/google-cloud\/\">More Google Cloud tutorials<\/a><\/li>\n\n\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/terraform-tutorials-tfsec-for-security-scanning\/\">Terraform Tutorials: TFSec for Security Scanning<\/a><\/li>\n\n\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/how-to-do-looping-iterations-in-terraform\/\">Terraform Loops and Iteration: Complete Guide to count, for_each, for Expressions, and Dynamic Blocks<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial uses Terraform to create a Google Compute Engine VM on Google Cloud, either in a new auto-mode VPC network or in the project&#039;s default network&#8230;. <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[5129,26149],"tags":[26259,26224],"class_list":["post-30068","post","type-post","status-publish","format-standard","hentry","category-terraform","category-google-cloud","tag-google-compute-engine","tag-hcl"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/30068","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=30068"}],"version-history":[{"count":3,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/30068\/revisions"}],"predecessor-version":[{"id":80676,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/30068\/revisions\/80676"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=30068"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=30068"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=30068"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}