{"id":65459,"date":"2026-03-16T18:51:22","date_gmt":"2026-03-16T15:51:22","guid":{"rendered":"https:\/\/cloudspinx.com\/?p=65459"},"modified":"2026-03-16T18:51:22","modified_gmt":"2026-03-16T15:51:22","slug":"how-to-deploy-vm-instance-on-google-cloud-using-terraform","status":"publish","type":"post","link":"https:\/\/computingforgeeks.com\/how-to-deploy-vm-instance-on-google-cloud-using-terraform\/","title":{"rendered":"How To Deploy VM Instance on Google Cloud using Terraform"},"content":{"rendered":"\n<p>Terraform is an open-source infrastructure as code(IaC) software program created by HashiCorp. HashiCorp Configuration Language, or optionally JSON, a declarative configuration language, is used by users to define and deliver data center architecture. Terraform can manage both low-level and high-level components, such as compute, storage, and networking resources, as well as DNS records and SaaS capabilities. Terraform uses application programming interfaces to construct and manage resources on cloud platforms and other services (APIs).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"terraform-use-case\">Terraform use cases<\/h3>\n\n\n\n<p>Here, we&#8217;ll go over some common Terraform use cases.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Terraform may be used to quickly deploy, release, scale, and monitor multi-tier applications&#8217; infrastructure.<\/li>\n\n\n\n<li>Terraform can assist you in enforcing standards regarding the types of resources that teams are allowed to provide and use.<\/li>\n\n\n\n<li>Your centralized operations staff at a large company may receive a lot of recurring infrastructure requests.<\/li>\n\n\n\n<li>Terraform can work with Software Defined Networks (SDNs) to autonomously configure networks based on the requirements of the applications that operate on them.<\/li>\n\n\n\n<li>Kubernetes is a workload scheduler for containerized applications that is open-source. Terraform allows you to both deploy and manage a Kubernetes cluster&nbsp;e.g.&nbsp;pods, deployments, services, and many more.<\/li>\n\n\n\n<li>Using several clouds to provision infrastructure improves fault tolerance and allows for a more smooth recovery from cloud provider failures.<\/li>\n\n\n\n<li>Platform as a Service (PaaS) companies like Heroku let you build web applications and add-ons like databases and email providers.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"install-terraform-on-linux\">Install Terraform on Linux<\/h3>\n\n\n\n<p>You can install Terraform in different Linux distribution as follows:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"install-terraform-on-ubuntu-ubuntu\">Install Terraform on Ubuntu|Debian<\/h3>\n\n\n\n<p>Install Terraform on Ubuntu\/Debian as follows.<\/p>\n\n\n\n<p>Add GPG key to your Ubuntu \/ Debian system:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update &amp;&amp; sudo apt install curl\ncurl -fsSL https:\/\/apt.releases.hashicorp.com\/gpg | sudo apt-key add -<\/code><\/pre>\n\n\n\n<p>Add the repository to the system:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt-add-repository \"deb &#91;arch=$(dpkg --print-architecture)] https:\/\/apt.releases.hashicorp.com $(lsb_release -cs) main\"<\/code><\/pre>\n\n\n\n<p>Install Terraform from the repository:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install terraform<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"install-terraform-on-centos-rocky-linux-almalinux\">Install Terraform on CentOS|Rocky Linux|AlmaLinux<\/h3>\n\n\n\n<p>Install yum-utils package:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo yum install -y yum-utils<\/code><\/pre>\n\n\n\n<p>Next we add CentOS|Rocky Linux|AlmaLinux  YUM repository:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo yum-config-manager --add-repo https:\/\/rpm.releases.hashicorp.com\/RHEL\/hashicorp.repo<\/code><\/pre>\n\n\n\n<p>Install Terraform by using the commands below:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo yum -y install terraform<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"install-terraform-on-amazon-linux-2\">Install Terraform on Amazon Linux 2<\/h3>\n\n\n\n<p>Follow the guide below to install Terraform on Amazon Linux 2.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/cloudspinx.com.com\/install-terraform-on-amazon-linux\/\" target=\"_blank\" rel=\"noreferrer noopener\">How To Install Terraform on Amazon Linux 2<\/a><\/li>\n<\/ul>\n\n\n\n<p>Confirm the terraform version installed:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-pink-color\">terraform  --version<\/mark>\nTerraform v1.9.8\non linux_amd64<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"sample-terraform-configuration-used-with-google-cloud\">Sample Terraform Configuration used with Google Cloud<\/h3>\n\n\n\n<p>The following is the Terraform configuration file used with Google Cloud. The file has <code>.tf<\/code> extension i.e. <code>main.tf <\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>terraform {\n  required_providers {\n    google = {\n      source = \"hashicorp\/google\"\n      version = \"3.5.0\"\n    }\n  }\n}\n\nprovider \"google\" {\n  credentials = file(\"&lt;NAME&gt;.json\")\n\n  project = \"&lt;PROJECT_ID&gt;\"\n  region  = \"us-central1\"\n  zone    = \"us-central1-c\"\n}\n\nresource \"google_compute_network\" \"vpc_network\" {\n  name = \"terraform-network\"\n}<\/code><\/pre>\n\n\n\n<p>&lt;<code>NAME<\/code>&gt; should be replaced with the path to the service account key file you obtained, and &lt;<code>PROJECT_ID<\/code>&gt; should be replaced with the ID of your project.<\/p>\n\n\n\n<p>Terraform parameters, including the essential providers Terraform will use to provision your infrastructure, are contained in the <code>terraform {}<\/code> block.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"creating-google-cloud-instance-using-terraform\">Creating VM instance in Cloud Cloud using Terraform<\/h3>\n\n\n\n<p>The following are prerequisites in order to create an instance using Terraform.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>You&#8217;ll need a Google Cloud Platform account to get started. <a href=\"https:\/\/console.cloud.google.com\/freetrial\/signup\/tos\" data-type=\"URL\" data-id=\"https:\/\/console.cloud.google.com\/freetrial\/signup\/tos\" target=\"_blank\" rel=\"noreferrer noopener\">Create a Google Cloud Platform<\/a> account if you don&#8217;t already have one. This tutorial can be performed entirely with the GCP free tier&#8217;s services.<\/li>\n\n\n\n<li>Locally installed Terraform version 0.15.3+.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"gcp-setup\">GCP Setup<\/h3>\n\n\n\n<p>To enable Terraform to provision your infrastructure, build or edit the following resources after creating your GCP account.<\/p>\n\n\n\n<p><strong>a) GCP Project<\/strong><\/p>\n\n\n\n<p>Resources are organized into projects by GCP. <a href=\"https:\/\/console.cloud.google.com\/projectcreate\" target=\"_blank\" data-type=\"URL\" data-id=\"https:\/\/console.cloud.google.com\/projectcreate\" rel=\"noreferrer noopener\">Create one in the GCP<\/a> console right now and save the project ID. In the cloud resource manager, you may see a list of your projects.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"965\" height=\"459\" src=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-create-project-01.webp\" alt=\"\" class=\"wp-image-65478\" style=\"width:800px\" title=\"\" srcset=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-create-project-01.webp 965w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-create-project-01-300x143.webp 300w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-create-project-01-768x365.webp 768w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-create-project-01-883x420.webp 883w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-create-project-01-696x331.webp 696w\" sizes=\"auto, (max-width: 965px) 100vw, 965px\" \/><\/figure>\n<\/div>\n\n\n<p><strong>b) Google Compute Engine<\/strong><\/p>\n\n\n\n<p>In the GCP console, enable Google Compute Engine for your project. To follow this lesson, make sure you select the project you&#8217;ll be using and click the &#8220;Enable&#8221; option.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"751\" height=\"309\" src=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-enable-compute-02.webp\" alt=\"\" class=\"wp-image-65479\" title=\"\" srcset=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-enable-compute-02.webp 751w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-enable-compute-02-300x123.webp 300w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-enable-compute-02-696x286.webp 696w\" sizes=\"auto, (max-width: 751px) 100vw, 751px\" \/><\/figure>\n<\/div>\n\n\n<p><strong>c) GCP service account key<\/strong><\/p>\n\n\n\n<p>To allow Terraform to access your GCP account,<a href=\"https:\/\/console.cloud.google.com\/projectselector2\/iam-admin\/serviceaccounts?supportedpurview=project\" target=\"_blank\" data-type=\"URL\" data-id=\"https:\/\/console.cloud.google.com\/projectselector2\/iam-admin\/serviceaccounts?supportedpurview=project\" rel=\"noreferrer noopener\"> create a service account key<\/a>. Use the following procedures when creating the key:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"921\" height=\"555\" src=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-choose-project-03.webp\" alt=\"\" class=\"wp-image-65480\" style=\"width:800px\" title=\"\" srcset=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-choose-project-03.webp 921w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-choose-project-03-300x181.webp 300w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-choose-project-03-768x463.webp 768w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-choose-project-03-697x420.webp 697w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-choose-project-03-696x419.webp 696w\" sizes=\"auto, (max-width: 921px) 100vw, 921px\" \/><\/figure>\n<\/div>\n\n\n<p>Choose the project you made in the preceding stage.<\/p>\n\n\n\n<p>Select &#8220;<strong>Create Service Account<\/strong>&#8220;.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"330\" src=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-create-service-account-04-1024x330.webp\" alt=\"\" class=\"wp-image-65481\" style=\"width:800px\" title=\"\" srcset=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-create-service-account-04-1024x330.webp 1024w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-create-service-account-04-300x97.webp 300w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-create-service-account-04-768x248.webp 768w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-create-service-account-04-696x225.webp 696w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-create-service-account-04-1068x345.webp 1068w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-create-service-account-04.webp 1181w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n\n\n<p>Click &#8220;<strong>Create<\/strong>&#8221; and give it whatever name you like.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"546\" src=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-create-service-account-05-1024x546.png\" alt=\"\" class=\"wp-image-65483\" style=\"width:800px\" title=\"\" srcset=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-create-service-account-05-1024x546.png 1024w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-create-service-account-05-300x160.png 300w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-create-service-account-05-768x409.png 768w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-create-service-account-05-1536x819.png 1536w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-create-service-account-05-788x420.png 788w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-create-service-account-05-696x371.png 696w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-create-service-account-05-1068x569.png 1068w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-create-service-account-05.png 1726w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n\n\n<p>Choose &#8220;<strong>Project -&gt; Editor<\/strong>&#8221; for the Role, then &#8220;<strong>Continue<\/strong>.&#8221;<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"987\" height=\"631\" src=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-role-06.webp\" alt=\"\" class=\"wp-image-65484\" style=\"width:800px\" title=\"\" srcset=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-role-06.webp 987w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-role-06-300x192.webp 300w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-role-06-768x491.webp 768w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-role-06-657x420.webp 657w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-role-06-696x445.webp 696w\" sizes=\"auto, (max-width: 987px) 100vw, 987px\" \/><\/figure>\n<\/div>\n\n\n<p>Click &#8220;<strong>Done<\/strong>&#8221; instead of providing more users access. Download your service account key after you&#8217;ve created your service account:<\/p>\n\n\n\n<p>Choose your service account from the list.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"660\" src=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-manage-keys-07-1024x660.png\" alt=\"\" class=\"wp-image-65485\" style=\"width:600px\" title=\"\" srcset=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-manage-keys-07-1024x660.png 1024w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-manage-keys-07-300x193.png 300w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-manage-keys-07-768x495.png 768w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-manage-keys-07-652x420.png 652w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-manage-keys-07-696x449.png 696w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-manage-keys-07-1068x688.png 1068w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-manage-keys-07.png 1266w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>The &#8220;<strong>Keys<\/strong>&#8221; tab should be selected.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"835\" height=\"477\" src=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-create-new-key-08.webp\" alt=\"\" class=\"wp-image-65486\" style=\"width:800px\" title=\"\" srcset=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-create-new-key-08.webp 835w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-create-new-key-08-300x171.webp 300w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-create-new-key-08-768x439.webp 768w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-create-new-key-08-735x420.webp 735w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-create-new-key-08-696x398.webp 696w\" sizes=\"auto, (max-width: 835px) 100vw, 835px\" \/><\/figure>\n<\/div>\n\n\n<p>Select &#8220;<strong>Create new key<\/strong>&#8221; from the drop-down menu. Leave Key Type set to <strong>JSON<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img decoding=\"async\" src=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-JSON-09-1024x662.png\" alt=\"\" class=\"wp-image-65487\" style=\"width:500px\" title=\"\"><\/figure>\n\n\n\n<p>To create the key and store the key file to your PC, click &#8220;<strong>Create<\/strong>.&#8221;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"deploy-instance-vm-on-google-cloud\">Deploy VM Instance on Google Cloud<\/h3>\n\n\n\n<p>Create Terraform working directory and change to it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir terraform-project\ncd terraform-project<\/code><\/pre>\n\n\n\n<p>Create a&nbsp;<code>main.tf<\/code>&nbsp;file for the instance.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vim main.tf<\/code><\/pre>\n\n\n\n<p>Add the content below to the file above:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>provider \"google\" {\n  credentials  = file(\"<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">~\/Documents\/myterraform-project-341816-b1959e7e2de3.json<\/mark>\")\n  project = \"<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">myterraform-project-341816<\/mark>\"\n  region  = \"<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-amber-color\">us-central1<\/mark>\"\n  zone    = \"<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-green-cyan-color\">us-central1-c<\/mark>\"\n}\n\nresource \"google_compute_instance\" \"vm_instance\" {\n  name         = \"<strong><em>terraform-instance<\/em><\/strong>\"\n  machine_type = \"<strong><em>f1-micro<\/em><\/strong>\"\n\n  boot_disk {\n    initialize_params {\n      image = \"<strong><em>debian-cloud\/debian-11<\/em><\/strong>\"\n    }\n  }\n\n  network_interface {\n    # A default network is created for all GCP projects\n    network = google_compute_network.vpc_network.self_link\n    access_config {\n    }\n  }\n}\n\nresource \"google_compute_network\" \"vpc_network\" {\n  name                    = \"<strong><em>terraform-network<\/em><\/strong>\"\n  auto_create_subnetworks = \"true\"\n}<\/code><\/pre>\n\n\n\n<p>You must use<code> terraform init<\/code> to initialize the directory when creating a new configuration. The providers defined in the configuration are downloaded in this stage.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-pink-color\"> terraform init  <\/mark>    \n\nInitializing the backend...\n\nInitializing provider plugins...\n- Reusing previous version of hashicorp\/google from the dependency lock file\n- Using previously-installed hashicorp\/google v4.11.0\n\n<strong>Terraform has been successfully initialized!\n<\/strong>\nYou may now begin working with Terraform. Try running \"terraform plan\" to see\nany changes that are required for your infrastructure. All Terraform commands\nshould now work.\n\nIf you ever set or change modules or backend configuration for Terraform,\nrerun this command to reinitialize your working directory. If you forget, other\ncommands will detect it and remind you to do so if necessary.<\/code><\/pre>\n\n\n\n<p>Now that you have a Terraform configuration and your credentials set up, you can use <code>terraform apply<\/code> to supply your resources. If you wish to skip this step and have the changes applied automatically, use <code>terraform apply -auto-approve<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-pink-color\"> terraform apply -auto-approve<\/mark>\n\nTerraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:\n  + create\n\nTerraform will perform the following actions:\n\n  # google_compute_instance.vm_instance will be created\n  + resource \"google_compute_instance\" \"vm_instance\" {\n      + can_ip_forward       = false\n      + cpu_platform         = (known after apply)\n      + current_status       = (known after apply)\n      + deletion_protection  = false\n      + guest_accelerator    = (known after apply)\n      + id                   = (known after apply)\n      + instance_id          = (known after apply)\n......\n # google_compute_network.vpc_network will be created\n  + resource \"google_compute_network\" \"vpc_network\" {\n      + auto_create_subnetworks         = true\n      + delete_default_routes_on_create = false\n      + gateway_ipv4                    = (known after apply)\n      + id                              = (known after apply)\n      + mtu                             = (known after apply)\n      + name                            = \"terraform-network\"\n      + project                         = (known after apply)\n      + routing_mode                    = (known after apply)\n      + self_link                       = (known after apply)\n    }\n\nPlan: 2 to add, 0 to change, 0 to destroy.\ngoogle_compute_network.vpc_network: Creating...\ngoogle_compute_network.vpc_network: Still creating... &#91;10s elapsed]\ngoogle_compute_network.vpc_network: Still creating... &#91;20s elapsed]\ngoogle_compute_network.vpc_network: Still creating... &#91;30s elapsed]\ngoogle_compute_network.vpc_network: Creation complete after 33s &#91;id=projects\/myterraform-project-341816\/global\/networks\/terraform-network]\ngoogle_compute_instance.vm_instance: Creating...\ngoogle_compute_instance.vm_instance: Still creating... &#91;10s elapsed]\ngoogle_compute_instance.vm_instance: Creation complete after 16s &#91;id=projects\/myterraform-project-341816\/zones\/us-central1-c\/instances\/terraform-instance]\n\n<strong>Apply complete! Resources: 2 added, 0 changed, 0 destroyed.<\/strong><\/code><\/pre>\n\n\n\n<p>Now the instance is deployed on GCP with Terraform:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"271\" src=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-instance-deployed-11-1024x271.webp\" alt=\"\" class=\"wp-image-65488\" style=\"width:900px\" title=\"\" srcset=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-instance-deployed-11-1024x271.webp 1024w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-instance-deployed-11-300x79.webp 300w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-instance-deployed-11-768x203.webp 768w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-instance-deployed-11-696x184.webp 696w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-instance-deployed-11-1068x283.webp 1068w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2024\/11\/terraform-gcp-instance-deployed-11.webp 1255w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>The<code> terraform destroy<\/code> command can be used to terminate the instance. The<code> terraform destroy -auto-approve<\/code> flag can be used in the same way as the apply command to skip the confirmation.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-amber-color\">terraform destroy -auto-approve<\/mark>\n.....\nTerraform will perform the following actions:\n\n  # google_compute_instance.vm_instance will be <strong>destroyed<\/strong>\n  - resource \"google_compute_instance\" \"vm_instance\" {\n      - can_ip_forward       = false -&gt; null\n      - cpu_platform         = \"Intel Haswell\" -&gt; null\n      - current_status       = \"RUNNING\" -&gt; null\n      - deletion_protection  = false -&gt; null\n      - enable_display       = false -&gt; null\n      - guest_accelerator    = &#91;] -&gt; null\n      - id                   = \"projects\/myterraform-project-341816\/zones\/us-central1-c\/instances\/terraform-instance\" -&gt; null\n      - instance_id          = \"2657643470062770536\" -&gt; null\n      - label_fingerprint    = \"42WmSpB8rSM=\" -&gt; null\n      - labels               = {} -&gt; null\n      - machine_type         = \"f1-micro\" -&gt; null\n      - metadata             = {} -&gt; null\n      - metadata_fingerprint = \"jHui8PFiD9s=\" -&gt; null\n      - name                 = \"terraform-instance\" -&gt; null\n      - project              = \"myterraform-project-341816\" -&gt; null\n      - resource_policies    = &#91;] -&gt; null\n      - self_link            = \"https:\/\/www.googleapis.com\/compute\/v1\/projects\/myterraform-project-341816\/zones\/us-central1-c\/instances\/terraform-instance\" -&gt; null\n      - tags                 = &#91;] -&gt; null\n      - tags_fingerprint     = \"42WmSpB8rSM=\" -&gt; null\n      - zone                 = \"us-central1-c\" -&gt; null\n.....\n<strong>Destroy complete! Resources: 2 destroyed.<\/strong><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Conclusion<\/h3>\n\n\n\n<p>Our article on How to Deploy and Instance on Google Cloud Using Terraform must come to an end. Terraform allows you to quickly deploy, release, scale, and manage the infrastructure of multi-tier application.<\/p>\n\n\n\n<p>Check out our other articles on Terraform:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/computingforgeeks.com\/how-to-install-terraform-on-amazon-linux\/\">How To Install Terraform on Amazon Linux 2<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/computingforgeeks.com\/create-google-sql-database-instance-on-gcp-using-terraform\/\">Create\u00a0Google SQL Database Instance on GCP using Terraform<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/computingforgeeks.com\/how-to-provision-virtual-machines-on-aws-using-terraform\/\">How To Provision Virtual Machines on AWS using Terraform<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Terraform is an open-source infrastructure as code(IaC) software program created by HashiCorp. HashiCorp Configuration Language, or optionally JSON, a declarative configuration language, is used by users to define and deliver data center architecture. Terraform can manage both low-level and high-level components, such as compute, storage, and networking resources, as well as DNS records and SaaS &#8230; <a title=\"How To Deploy VM Instance on Google Cloud using Terraform\" class=\"read-more\" href=\"https:\/\/computingforgeeks.com\/how-to-deploy-vm-instance-on-google-cloud-using-terraform\/\" aria-label=\"Read more about How To Deploy VM Instance on Google Cloud using Terraform\">Read more<\/a><\/p>\n","protected":false},"author":3,"featured_media":65499,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36939,6176,86],"tags":[39441,559],"cfg_series":[],"class_list":["post-65459","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-gcp","category-terraform","category-virtualization","tag-google-cloud-platform","tag-terraform"],"_links":{"self":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/posts\/65459","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/comments?post=65459"}],"version-history":[{"count":0,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/posts\/65459\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/media\/65499"}],"wp:attachment":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/media?parent=65459"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/categories?post=65459"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/tags?post=65459"},{"taxonomy":"cfg_series","embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/cfg_series?post=65459"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}