简体   繁体   English

GCP 与 Terraform 集成

[英]GCP integration with Terraform

I'm trying to run terraform commands to create VM in my GCP account.我正在尝试运行 terraform 命令在我的 GCP 帐户中创建 VM。

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?到我的 GCP 帐户还是服务帐户?

docs I find: https://cloud.google.com/compute/docs/troubleshooting/troubleshooting-vm-creation#insufficient_permissions我找到的文档: https://cloud.google.com/compute/docs/troubleshooting/troubleshooting-vm-creation#insufficient_permissions

(but I didn't find the answer there..) (但我没有在那里找到答案..)

thanks!谢谢!

The line project = "My First Project" is using the Project Name .project = "My First Project"正在使用Project Name Replace that with the Project ID .将其替换为Project ID

Internally Google uses the Project ID or Project Number to uniquely identity projects. Google 在内部使用项目 ID项目编号来唯一标识项目。 The Project Name is a descriptive name for your use.项目名称是供您使用的描述性名称。 Multiple projects can have the same Project Name.多个项目可以具有相同的项目名称。

Could you please check the attached link?你能检查一下所附的链接吗?

https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_instance https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_instance

There seems to be a lot of Project Id and missing information.似乎有很多项目 ID 和缺失信息。 After confirmation, try running Terraform Command again.确认后,再次尝试运行 Terraform 命令。

thank you.谢谢你。

You need to give your project id in the provider block.您需要在提供程序块中提供您的项目 ID。

provider "google" {
project     = "$PROJECT_ID"
region      = "us-east1"
}

You can check the project id using the console.您可以使用控制台检查项目 ID。

project-id项目编号

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM