这是我为模板运行的 tf 脚本,为了帮助调试,我对其进行了精简:
# Credentials
provider "google" {
credentials = "${var.credentials}"
project = "${var.project}"
region = "${var.region}"
}
# Regional MIG
resource "google_compute_instance_group_manager" "rmig" {
name = "${var.rmig_name}"
instance_template = "${google_compute_instance_template.cit.self_link}"
base_instance_name = "${var.base_instance_name}"
#region = "${var.region}"
zone = "${var.zone}"
target_size = 7
}
# Template creation
resource "google_compute_instance_template" "cit" {
name_prefix = "${var.prefix}"
description = "${var.desc}"
project = "${var.project}"
region = "${var.region}"
tags = "${var.tags}"
instance_description = "${var.desc_inst}"
machine_type = "${var.machine_type}"
can_ip_forward = false // Whether to allow sending and receiving of packets with non-matching source or destination IPs. This defaults to false.
// Create a new boot disk from an image (Lets use one created by Packer)
disk {
source_image = "${var.source_image}"
auto_delete = true
boot = true
}
network_interface {
network = "${var.network}"
# Give a Public IP to instance(s)
access_config {
// Ephemeral IP
}
}
我指定从模板创建 7 台虚拟机。在 GCP 中,它确实创建了 7 台虚拟机,这是正确的,但其中 4 台已关闭,几分钟后,它删除了已关闭的虚拟机,因此我只剩下 3 台已打开的虚拟机。
如果我尝试通过 GCP UI 启动已关闭的虚拟机,我会收到错误:
“启动虚拟机实例‘apache-d2dv’失败。错误:Google Compute Engine 尚未准备好在项目中使用。如果刚刚启用 Google Compute Engine,或者这是您第一次在项目中使用 Google Compute Engine,则可能需要几分钟时间。”
这是 GCP 的问题(在这种情况下我必须更换提供商),还是我的 tf 代码的问题?
[附图]
答案1
我查看了其他出现相同错误消息的情况(“错误:Google Compute Engine 尚未准备好……”),它们指出您的 GCP 项目中存在计费问题。您可能想先查看一下。(您最近是否从免费帐户升级?)