Terraform code to create a virtual machine (VM) instance in GCP

In this example, the `provider` block specifies the GCP project and region to use. The `resource` block specifies the `google_compute_instance` resource to create, with various configuration settings such as the machine type, disk image, and network settings.

Once you have written this code, you can run `terrafrom init`, `terraform plan` and `terraform apply`  commands to initialize the Terraform working directory, generate an execution plan, and apply the changes to create the VM instance on GCP.

below example of Terraform code to create a virtual machine (VM) instance in Google Cloud Platform (GCP):

terraform
provider "google" {
  project = "your-project-id"
  region  = "us-central1"
}
resource "google_compute_instance" "vm_instance" {
  name         = "my-vm-instance"
  machine_type = "n1-standard-1"
  zone         = "us-central1-a"
  boot_disk {
    initialize_params {
      image = "debian-cloud/debian-9"
    }
  }
  network_interface {
    network = "default"
    access_config {
    }
  }
}


Next Post Previous Post
No Comment
Add Comment
comment url