1

我在设置 GCP 实例模板时遇到了新问题。我假设 terraform gcp 提供程序有更新。

resource "google_compute_instance_template" "backend-template" {
  name                    = "${var.platform_name}-backend-instance-template"
  description             = "Template used for backend instances"
  instance_description    = "backend Instance"
  machine_type            = "n1-standard-1"
  metadata_startup_script = "${lookup(var.startup_scripts,"backend-server")}"

disk {
  boot         = "true"
  source_image = "backend-packer-image"
}

metadata {
  APP_SETTINGS        = "${var.app_settings}"
  URL_STAGING         = "${var.url_staging}"
  API_URL_STAGING     = "${var.api_url_staging}"
  URL_PRODUCTION      = "${var.url_production}"
  API_URL_PRODUCTION  = "${var.api_url_production}"
  LOGIN_URL           = "${var.login_url}"
  API_URL             = "${var.api_url}"
  vault_server_IP     = "${lookup(var.static_ips, "vault-server")}"
  environment         = "${var.environment}"
}

network_interface {
  subnetwork = "${google_compute_subnetwork.private-fe-be.self_link}"
}

lifecycle {
  create_before_destroy = true
}

tags = ["no-ip", "backend-server"]

service_account {
  scopes = ["cloud-platform"]
}
}

这是运行脚本后的当前错误。但是,该映像backend-packer-image已创建并存在于 GCP 上

* google_compute_instance_template.backend-template: 1 error(s) occurred:

* google_compute_instance_template.backend-template: error flattening disks: Error getting relative path for source image: String was not a self link: global/images/backend-packer-image
4

2 回答 2

1

我今天遇到了完全相同的问题,我不得不直接查看拉取请求以找到正确使用它的方法。

所以,我带来的是这样的:在输入此命令之前,您必须首先确保在您的项目中,否则如果它是自定义图像,您将找不到您要查找的图像:

gcloud compute images list --uri | grep "your image name"

像这样,您将拥有图像的 uri,然后您可以将其完全放入图像中,它将起作用。

用 URI 替换图像名称source_image

resource "google_compute_instance_template" "backend-template" {
  name                    = "${var.platform_name}-backend-instance- 
  template"
  description             = "Template used for backend instances"
  instance_description    = "backend Instance"
  machine_type            = "n1-standard-1"
  metadata_startup_script = "${lookup(var.startup_scripts,"backend-server")}"

  disk {
  boot         = "true"
  source_image = "https://www.googleapis.com/compute/v1/projects/<project-name>/global/images/backend-packer-image"
}

metadata {
  APP_SETTINGS        = "${var.app_settings}"
  URL_STAGING         = "${var.url_staging}"
  API_URL_STAGING     = "${var.api_url_staging}"
  URL_PRODUCTION      = "${var.url_production}"
  API_URL_PRODUCTION  = "${var.api_url_production}"
  LOGIN_URL           = "${var.login_url}"
  API_URL             = "${var.api_url}"
  vault_server_IP     = "${lookup(var.static_ips, "vault-server")}"
  environment         = "${var.environment}"
}

network_interface {
  subnetwork = "${google_compute_subnetwork.private-fe-be.self_link}"
}

lifecycle {
  create_before_destroy = true
}

tags = ["no-ip", "backend-server"]

service_account {
  scopes = ["cloud-platform"]
}
}
于 2018-09-19T16:55:10.200 回答
1

也可以绑定 terraform 脚本来运行以前的版本

provider "google"{
  version     = "<= 1.17"
  credentials = "${var.service_account_path}"
  project     = "${var.gcloud_project}"
  region      = "${var.gcloud_region}"
}
于 2018-09-19T19:21:37.363 回答