英文:
How to use google_compute_instance_from_template?
问题
这是我尝试使用Terraform的第一天,需要一些帮助。
我有一个GCP实例模板,我想在我的.tf文件中指定并创建一个实例。
resource "google_compute_instance_from_template" "tpl" {
name = "k8-node-4-from-tf"
source_instance_template = "k8-node"
project = "myproject"
zone = "us-west4-b"
}
当我应用时,我遇到了这个错误:
googleapi: Error 404: 未找到资源'projects/myproject/regions/us-west4/instanceTemplates/k8-node',notFound
我看到实例模板的self链接是这样的:
"selfLink": "projects/myproject/global/instanceTemplates/k8-node"
如何解决这个错误?在.tf中指定一个区域是强制性的。
当我尝试使用"global"作为区域时,会出现错误:区域"global"不存在。
英文:
This is my day 1 trying out terraform and needed some help.
I have a gcp instance template which I want to specify in my .tf and create an instance
resource "google_compute_instance_from_template" "tpl" {
name = "k8-node-4-from-tf"
source_instance_template = "k8-node"
project = "myproject"
zone = "us-west4-b"
}
I encountered this error when applying this
googleapi: Error 404: The resource 'projects/myproject/regions/us-west4/instanceTemplates/k8-node' was not found, notFound
The self link I see for the instance template is this,
"selfLink": "projects/myproject/global/instanceTemplates/k8-node"
How can I resolve this error ?
Specifying a zone on .tf is mandatory.
When I try "global" for zone, this errors out : Zone global doesn't exist
答案1
得分: 2
"zone" 指的是 VM 将被创建的位置,而不是模板的位置。
因此,您可以将模板引用为:
resource "google_compute_instance_from_template" "tpl" {
name = "k8-node-4-from-tf"
source_instance_template = "projects/myproject/global/instanceTemplates/k8-node"
project = "myproject"
zone = "us-west4-b"
}
或者如果模板在您的 TF 文件中定义:
resource "google_compute_instance_from_template" "tpl" {
name = "k8-node-4-from-tf"
source_instance_template = google_compute_instance_template.<your_instance_template_name>.self_link_unique
project = "myproject"
zone = "us-west4-b"
}
文档中包含了所有信息,因此当您开始使用新东西时,强烈建议您首先阅读文档,因为大多数情况下,您会在那里找到示例。
英文:
The zone refers to where the VM will be created, not where the template is.
So you can refer to the template as:
resource "google_compute_instance_from_template" "tpl" {
name = "k8-node-4-from-tf"
source_instance_template = "projects/myproject/global/instanceTemplates/k8-node"
project = "myproject"
zone = "us-west4-b"
}
or if the template is defined in your TF files:
resource "google_compute_instance_from_template" "tpl" {
name = "k8-node-4-from-tf"
source_instance_template = google_compute_instance_template.<your_instance_template_name>.self_link_unique
project = "myproject"
zone = "us-west4-b"
}
Everything is in the documentation so when you start with something new, it's highly recommended that you read that first since most of the time you'll find samples there.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论