努力创建分配了静态IP的gcp实例。我可以分别创建它们,只是创建它并使VM使用它。
resource "google_compute_address" "static_ip" {
name = "terraform-static-ip"
}
resource "google_compute_instance" "vm_instance" {
name = "terraform-instance"
machine_type = "f1-micro"
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.terraform-static-ip.address"
}
}
}
遇到此错误
错误:创建实例时出错:googleapi:错误400:字段“ resource.networkInterfaces [0] .accessConfigs [0] .natIP”的值无效:“ google_compute_address.static.address”。在区域“ us-central1”中找不到指定的外部IP地址“ google_compute_address.static.address”。
任何人都知道我在做什么错。
我找到了这个线程-How to map static IP to terraform google compute engine instance?
但是没有一种解决方案对我有用。
答案 0 :(得分:1)
您有错字
access_config {
nat_ip = "google_compute_address.terraform-static-ip.address"
}
您希望该行是
access_config {
nat_ip = "google_compute_address.static-ip.address"
}
因为您的google_compute_address
资源名称为static-ip