【问题标题】:Error loading zone 'europe-west1-a': googleapi: Error 404: The resource 'projects/google-project-id/zones/europe-west1-a' was not found, notFound加载区域'europe-west1-a'时出错:googleapi:错误404:找不到资源'projects/google-project-id/zones/europe-west1-a',notFound
【发布时间】:2020-05-25 06:33:59
【问题描述】:

出现此错误,让我发疯......我无法使用它创建超过 1 个具有静态 IP 的 VM。

这是我的 main.tf

provider "google" {
  credentials = file("terraform-key.json")
  project = var.project
  region  = var.region
  zone    = var.zone
}

terraform {
  backend "gcs" {
    bucket = "my-bucket"
    prefix = "terraform"
    credentials = "terraform-key.json"
   }
}

resource "google_compute_network" "vpc_network" {
  name = "new-terraform-network"
}

resource "google_container_cluster" "primary" {
  name     = "prod-cluster"
  location = var.zone
  remove_default_node_pool = true
  initial_node_count       = 1

  master_auth {
    username = ""
    password = ""

    client_certificate_config {
      issue_client_certificate = false
    }
  }
}

resource "google_container_node_pool" "primary_preemptible_nodes" {
  name       = "pool-1"
  location   = var.zone
  cluster    = google_container_cluster.primary.name
  node_count = 3

  node_config {
    preemptible  = true
    machine_type = "n1-standard-1"
    disk_size_gb = 10
    disk_type = "pd-standard"


    metadata = {
      disable-legacy-endpoints = "true"
    }

    oauth_scopes = [
      "https://www.googleapis.com/auth/logging.write",
      "https://www.googleapis.com/auth/monitoring",
    ]
  }
}
resource "google_compute_address" "vm-host"{
  count =  var.vm-host-number
  region  =  var.vm-host-region
  name  = "vm-host-${count.index}"
}


resource "google_compute_instance" "vm-host" {
  name         = "vm-host-${count.index}"
  machine_type = "f1-micro"
  zone         = "europe-west1-a"
  count        =  var.vm-host-number

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

  network_interface {
    network = google_compute_network.vpc_network.name
    access_config {
        nat_ip = "google_compute_address.vm-host-${count.index}.address"
    }
  }
}

我的变量文件

variable "project" {
  default = "my-project"
}

variable "region" {
  default = "us-central1"
}

variable "zone"  {
  default = "us-central1-c"
}

variable "cidr_ip" {
  default = "10.0.0.0/16"
}

variable "vm-host-number"{
  default = "2"
}

variable "vm-host-region"{
   default = "us-central1"
}
variable  "vm-host-zone"{
   default = "europe-west1-a"
}

错误-

Error: Error loading zone 'europe-west1-a': googleapi: Error 404: The resource 'projects/GoogleProjectID/zones/europe-west1-a' was not found, notFound

  on main.tf line 65, in resource "google_compute_instance" "vm-host":
  65: resource "google_compute_instance" "vm-host" {

不明白为什么它不会创建虚拟机,如果我尝试同样的方法来创建 1 个虚拟机,没有变量/计数它工作正常 >

编辑 -

下一个问题是我无法为每个虚拟机创建静态 IP。

resource "google_compute_address" "vm-host" {
  count =  var.vm-host-number
  #region  =  var-vm-host-region
   region = "us-central1-a"
   name  = "vm-host-${count.index}"
}

resource "google_compute_instance" "vm-host-vms" {
  name         = "vm-host-${count.index}"
  machine_type = "f1-micro"
  zone         = "us-central1-a"
  count        =  var.vm-host-number

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

  network_interface {
    network = google_compute_network.vpc_network.name
    access_config {
        nat_ip = "google_compute_address.vm-host-${count.index}.address"
    }
  }
}

nat_ip = "google_compute_address.vm-host-${count.index}.address" 行需要是 google_compute_address.resourcename.address,但是,

我试过了——

resource "google_compute_address" "vm-host-${count.index}" {
  count =  var.vm-host-number
   region = "us-central1-a"
   name  = "vm-host-${count.index}"
}



resource "google_compute_address" "vm-host-$${count.index}" {
  count =  var.vm-host-number

   region = "us-central1-a"
   name  = vm-host-${count.index}"
}

但无论我做什么,它都行不通。有什么特殊的语法吗?

【问题讨论】:

    标签: google-cloud-platform terraform terraform-provider-gcp


    【解决方案1】:

    区域“europe-west1-a”不存在。

    您可以使用命令gcloud compute zones list 获取现有区域的列表:

    CloudShell:$ gcloud compute zones list --filter=region=europe-west1
    NAME            REGION        STATUS
    europe-west1-b  europe-west1  UP
    europe-west1-d  europe-west1  UP
    europe-west1-c  europe-west1  UP
    

    【讨论】:

    • 嗨,是的,我已经想通了 - 现在正在努力获取要创建的公共静态地址,其中资源名称随计数递增。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-17
    相关资源
    最近更新 更多