无法使用 terraform 将内部 ip 附加到计算引擎

时间:2021-07-27 10:44:00

标签: terraform terraform-provider-gcp

我想启动一台带有静态内部 IP 的机器,该 IP 连接到我的虚拟机,以便我在资源下方创建

provider "google" {
  project     = "fit-visitor-305606"
  credentials = "${file("C:/Users/Rohan/Desktop/gvpc/fit.json")}"
  region      = "us-central1-a"
}
resource "google_compute_network" "default" {
  name = "my-network"
}
resource "google_compute_subnetwork" "default" {
  name          = "my-subnet"
  ip_cidr_range = "10.0.0.0/16"  
  region        = "us-central1"
  network       = google_compute_network.default.id
}
resource "google_compute_address" "internal_with_subnet_and_address" {
  name         = "my-internal-address"
  subnetwork   = google_compute_subnetwork.default.id
  address_type = "INTERNAL"
  address      = "10.0.1.0"
  region       = "us-central1"
  project  = "fit-visitor-305606" 
}
resource "google_compute_instance" "default" {
  name         = "test"
  machine_type = "e2-micro"
  zone         = "us-central1-a"
    boot_disk {
    initialize_params {
      image = "debian-cloud/debian-9"
    }  }
  scratch_disk {
    interface = "SCSI"
  }

  network_interface {
    network_ip = google_compute_address.internal_with_subnet_and_address.address
    subnetwork_project = "fit-visitor-305606"
    network = google_compute_network.default.id
    subnetwork = google_compute_subnetwork.default.id
    access_config {
      nat_ip = google_compute_address.internal_with_subnet_and_address.address
    }
  }
  }

但是一旦我运行我的代码,它就会向我显示以下错误

Error: Error creating instance: googleapi: Error 400: Invalid value for field resource.networkInterfaces[0].accessConfigs[0].natIP': '10.0.1.0'. The specified external IP address '10.0.1.0' was not found in region 'us-central1'.

感谢您的任何建议或帮助

0 个答案:

没有答案