Error: Invalid value for region: project: required field is not set

Error: Invalid value for region: project: required field is not set

GCP 上,我正在尝试创建 一个云 运行 服务一个无服务器网络端点组 具有以下 Terraform 代码:

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

resource "google_cloud_run_service" "default" {
  name     = "hello-world"
  location = "asia-northeast1"

  template {
    spec {
      containers {
        image = "gcr.io/myproject-813137/hello-world:latest"
      }
    }
  }

  traffic {
    percent         = 100
    latest_revision = true
  }
}

data "google_iam_policy" "noauth" {
  binding {
    role = "roles/run.invoker"
    members = [
      "allUsers",
    ]
  }
}

resource "google_cloud_run_service_iam_policy" "noauth" {
  location    = google_cloud_run_service.default.location
  project     = google_cloud_run_service.default.project
  service     = google_cloud_run_service.default.name

  policy_data = data.google_iam_policy.noauth.policy_data
}

resource "google_compute_region_network_endpoint_group" "cloudrun_neg" {
  provider              = google-beta
  name                  = "neg"
  network_endpoint_type = "SERVERLESS"
  region                = "asia-northeast1"
  cloud_run {
    service = google_cloud_run_service.default.name
  }
}

但是我得到了这个错误:

Error: Invalid value for region: project: required field is not set

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

"google_compute_region_network_endpoint_group":

中删除 "provider = google-beta"
resource "google_compute_region_network_endpoint_group" "cloudrun_neg" {
  # provider              = google-beta // Here to remove
  name                  = "neg"
  network_endpoint_type = "SERVERLESS"
  region                = "asia-northeast1"
  cloud_run {
    service = google_cloud_run_service.default.name
  }
}

即使您已经在下面定义了 provider "google",您重新定义了 "provider = google-beta""google_compute_region_network_endpoint_group":

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

这就是您收到此错误的原因:

Error: Invalid value for region: project: required field is not set