Google cloud platform Terraform GCP在创建实例模板时,获取源映像的相对路径时出错
我在设置GCP实例模板方面遇到了一个新问题。我推测terraform gcp提供商有更新Google cloud platform Terraform GCP在创建实例模板时,获取源映像的相对路径时出错,google-cloud-platform,terraform,devops,terraform-provider-gcp,Google Cloud Platform,Terraform,Devops,Terraform Provider Gcp,我在设置GCP实例模板方面遇到了一个新问题。我推测terraform gcp提供商有更新 resource "google_compute_instance_template" "backend-template" { name = "${var.platform_name}-backend-instance-template" description = "Template used for backend instance
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"]
}
}
这是运行脚本后的当前错误。但是,映像后端打包机映像已创建并存在于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
今天我遇到了完全相同的问题,我必须直接查看pull请求以找到正确使用它的方法
因此,我得出的结论是:
在键入此命令之前,必须首先确保位于项目中,否则如果是自定义图像,将找不到要查找的图像:
gcloud compute images list --uri | grep "your image name"
像这样,你将有你的图像的uri,然后你可以把它完全为图像,它将工作
用source\u 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"]
}
}
resource“谷歌计算实例模板”“后端模板”{
name=“${var.platform_name}-后端实例-
模板“
description=“用于后端实例的模板”
实例描述=“后端实例”
机器类型=“n1-standard-1”
metadata_startup_script=“${lookup(var.startup_scripts,“后端服务器”)}”
圆盘{
boot=“true”
源_图像=”https://www.googleapis.com/compute/v1/projects//global/images/backend-packer-image"
}
元数据{
APP_SETTINGS=“${var.APP_SETTINGS}”
URL_STAGING=“${var.URL_STAGING}”
API_URL_STAGING=“${var.API_URL_STAGING}”
URL\u PRODUCTION=“${var.URL\u PRODUCTION}”
API_URL_PRODUCTION=“${var.API_URL_PRODUCTION}”
LOGIN_URL=“${var.LOGIN_URL}”
API_URL=“${var.API_URL}”
vault_服务器_IP=“${lookup(var.static_ips,“vault服务器”)}”
environment=“${var.environment}”
}
网络接口{
subnetwork=“${google\u compute\u subnetwork.private fe be.self\u link}”
}
生命周期{
在销毁之前创建=真
}
标记=[“无ip”,“后端服务器”]
服务帐户{
范围=[“云平台”]
}
}
也可以将terraform脚本绑定到以前的版本
provider "google"{
version = "<= 1.17"
credentials = "${var.service_account_path}"
project = "${var.gcloud_project}"
region = "${var.gcloud_region}"
}
提供商“谷歌”{
版本="看起来这是一个已知的问题,正在@ydaetskcoR上跟踪。谢谢,到目前为止,它确实有一天的历史了。它在几个小时前就工作了,我也没有做任何更改。它在1.17.1
中工作正常吗?在中也有一条关于这一点的说明,但除非有错误,否则它看起来不应该在这里应用。我也有点担心令人惊讶的是,在v2版本中它并没有被推迟,因为它对我来说似乎是一个突破性的改变(即使可能只是针对某些配置),但我不太了解GCP提供商。