Create vm Google Cloud using Terraform

Everton Araújo
1 min readJan 4, 2023

--

Create single instance using terraform

To create a virtual machine (VM) on Google Cloud using Terraform, you will need to define a google_compute_instance resource in your Terraform configuration. Here is an example of how you could create a VM using Terraform:

resource "google_compute_instance" "example" {
name = "example-vm"
machine_type = "n1-standard-1"
zone = "us-central1-a"

boot_disk {
initialize_params {
image = "ubuntu-1604-lts"
}
}

network_interface {
network = "default"

access_config {
// Include this section to give the VM an external IP address
}
}

metadata = {
foo = "bar"
}

service_account {
// Include this section to specify a service account and attach
// scopes to it
}
}

This will create a new VM named “example-vm” in the us-central1-a zone, using a machine type of n1-standard-1 and a boot disk based on the ubuntu-1604-lts image.

To use this configuration, you will need to have Terraform installed on your system and have configured the Google Cloud provider. You will also need to have a Google Cloud service account with the appropriate permissions to create and manage Compute Engine resources.

--

--

Everton Araújo
Everton Araújo

No responses yet