Search code examples
google-cloud-platformterraformterraform-provider-gcp

Terraform apply throwing an Error while create a VM using GCP provider


I am trying to create a VM on GCP using terraform but i am getting an error when i run the script. This is the script i have used. I have created a service account and then given it compute admin role

provider "google" {
  project = "http-loadbalancer-352011"
  credentials = "${file("credentials.json")}"
  region  = "us-west1"
  zone    = "us-west1-a"
}
# Create a single Compute Engine instance
resource "google_compute_instance" "vm_instance" {
  name         = "flask-vm"
  machine_type = "e2-micro"

  boot_disk {
    initialize_params {
      image = "debian-cloud/debian-9"
    }
  }

  network_interface {
    network = "default"
    access_config {
      # Include this section to give the VM an external IP address
    }
  }
}

Error which i am getting while running terraform apply

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

google_compute_instance.vm_creation: Creating...

Error: Error loading zone 'us-west1-a': Get 
"https://compute.googleapis.com/compute/v1/projects/http-loadbalancer-352011/zones/us-west1-a? 
alt=json&prettyPrint=false": oauth2: cannot fetch token: unexpected EOF

  on main.tf line 8, in resource "google_compute_instance" "vm_instance":
   8: resource "google_compute_instance" "vm_instance" {

Solution

  • The issue was there a security software installed on my device and that was blocking the communication between GCP provider and terraform. I had to disable this from services once that was done it was working fine.