Complete the code to define infrastructure as code using Terraform.
resource "google_compute_instance" "vm_instance" { name = "example-instance" machine_type = "[1]" zone = "us-central1-a" }
The machine_type must be a valid GCP machine type like n1-standard-1 to create the VM.
Complete the code to specify the network interface for the VM instance.
resource "google_compute_instance" "vm_instance" { network_interface { network = "[1]" } }
The default network in GCP is named default. This is the common network used for VMs.
Fix the error in the Terraform code to correctly set the boot disk image.
boot_disk {
initialize_params {
image = "[1]"
}
}The image must be specified with the full path including project and image name for Terraform to find it.
Fill both blanks to create a firewall rule allowing HTTP traffic.
resource "google_compute_firewall" "http_firewall" { name = "allow-http" network = "[1]" allow { protocol = "[2]" ports = ["80"] } }
The firewall must be attached to the default network and allow tcp protocol for HTTP port 80.
Fill all three blanks to output the VM instance's external IP address.
output "instance_ip" { value = google_compute_instance.[1].network_interface[[2]].access_config[[3]].nat_ip }
The output references the VM instance resource name, and the first network interface and access config indexes are 0.