I’m trying to run terraform commands to create VM in my GCP account.
the code :
provider "google" {
project = "My First Project"
region = "us-east1"
}
resource "google_compute_instance" "vm_instance" {
name = "terraform-instance"
machine_type = "f1-micro"
zone = "us-east1-c"
boot_disk {
initialize_params {
image = "debian-cloud/debian-9"
}
}
network_interface {
# A default network is created for all GCP projects
network = "default"
access_config {
}
}
}
Error:
Error: Error loading zone 'us-east1-c': googleapi: Error 403: Permission denied on resource project My First Project., forbidden
which role I need to add ?
where to add it ? to my GCP account or to service account ?
docs I find :
https://cloud.google.com/compute/docs/troubleshooting/troubleshooting-vm-creation#insufficient_permissions
(but I didn’t find the answer there..)
thanks!
3
Answers
Could you please check the attached link?
https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_instance
There seems to be a lot of Project Id and missing information.
After confirmation, try running Terraform Command again.
thank you.
The line project = "My First Project" is using the Project Name. Replace that with the Project ID.
Internally Google uses the Project ID or Project Number to uniquely identity projects. The Project Name is a descriptive name for your use. Multiple projects can have the same Project Name.
You need to give your project id in the provider block.
You can check the project id using the console.
project-id