(Terraform,GCP)创建网络时出错:googleapi:错误 403:资源项目 myProject 的权限被拒绝。详情:[], 禁止

(Terraform, GCP) Error creating Network: googleapi: Error 403: Permission denied on resource project myProject. Details:[], forbidden

我正在尝试使用下面的 Terraform 代码在 GCP 上创建 VPC :

provider "google" {
  credentials = file("myCredentials.json")
  project     = "myProject"
  region      = "asia-northeast1"
}

resource "google_compute_network" "vpc" {
  name = "main"
  auto_create_subnetworks = false
}

这是我的项目名称编号ID:

但我收到以下错误:

Error: Error creating Network: googleapi: Error 403: Permission denied on resource project myProject.
Details:
[
  {
    "@type": "type.googleapis.com/google.rpc.Help",
    "links": [
      {
        "description": "Google developer console API key",
        "url": "https://console.developers.google.com/project/myProject/apiui/credential"
      }
    ]
  },
  {
    "@type": "type.googleapis.com/google.rpc.ErrorInfo",
    "domain": "googleapis.com",
    "metadata": {
      "consumer": "projects/myProject",
      "service": "compute.googleapis.com"
    },
    "reason": "CONSUMER_INVALID"
  }
]
, forbidden

  with google_compute_network.vpc,
  on 1st.tf line 25, in resource "google_compute_network" "vpc":
  25: resource "google_compute_network" "vpc" {

我的 Terraform 代码有什么错误吗?

您应该将 项目 ID“myproject-338117” 放入 “项目” 而不是 项目名称“我的项目”:

provider "google" {
  credentials = file("myCredentials.json")
  project     = "myproject-338117" // Put the project id "myproject-338117"
  region      = "asia-northeast1"
}

resource "google_compute_network" "vpc" {
  name = "main"
  auto_create_subnetworks = false
}

实际上,键名“项目”一个项目ID并不清晰直观。很多人会错误地输入 项目名称 而不是 项目 ID