如何将文件配置器与 google

编程入门 行业动态 更新时间:2024-10-27 14:18:26
本文介绍了如何将文件配置器与 google_compute_instance_template 一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

使用 Terraform,我需要将文件复制到 Google Compute Engine 实例模板.为此,我通常使用 file provisioner,但它不起作用,因为它取决于 SSH 连接,由于需要外部可访问的主机地址而失败.由于实例模板的动态特性,我不知道如何为实例分配外部可访问的主机地址.

Using Terraform, I need to copy files to Google Compute Engine instance templates. For this I normally use the file provisioner, but it doesn't work since it depends on SSH connections, which fail due to requiring externally accessible host addresses. Due to the dynamic nature of instance templates, I don't know how to assign externally accessible host addresses to instances.

如何将文件复制到通过实例模板(通过 Terraform)创建的 GCE 实例?

How can I implement copying of files to GCE instances created through instance templates (via Terraform)?

resource "google_compute_instance_template" "node" { name = "kubernetes-node-template" machine_type = "g1-small" can_ip_forward = true tags = ["staging", "node"] network_interface { network = "default" } provisioner "file" { source = "worker/assets/kubelet.service" destination = "/etc/systemd/system/kubelet.service" } connection { user = "core" type = "ssh" private_key = "${file("~/.ssh/id_rsa")}" } }

推荐答案

我能够通过以下配置解决此问题.

I was able to resolve this issue with the following configuration.

resource "google_compute_instance" "hubmud" { name = "hubmud" machine_type = "f1-micro" tags = ["buildserver", "jenkins", "central", "terraformer"] tags = [ "http-server" ] zone = "us-central1-b" disk { image = "ubuntu-1404-trusty-v20160406" } network_interface { network = "default" access_config {} } provisioner "file" { source = "installations.sh" destination = "installations.sh" connection { type = "ssh" user = "ubuntu" private_key = "${file("~/.ssh/google_compute_engine")}" } } provisioner "remote-exec" { inline = [ "chmod +x ~/installations.sh", "cd ~", "./installations.sh" ] connection { type = "ssh" user = "ubuntu" private_key = "${file("~/.ssh/google_compute_engine")}" } } service_account { scopes = ["userinfo-email", "compute-ro", "storage-ro"] } }

我使用的 SSH 密钥是由 gcloud 实例生成的,要复制的文件必须采用如图所示的格式.我确实遇到了使用 ~/ 或仅使用 ./ 来指定文件位置的问题.还需要注意的是,复制的文件是在ubuntu"帐户下的,这似乎是 GCE 默认在镜像上拥有的 ubuntu 上的默认帐户.

The SSH key I used was the one generated by the gcloud instance, and the file to copy has to be in the format as shown. I did run into problems with using ~/ or just ./ to designate where the file is. It's also important to note that the file copied under the "ubuntu" account, which appears to be a default account on ubuntu that GCE has on the image by default.

请注意,我还添加了 type = "ssh" 即使这是连接类型的默认值,因此不需要.我喜欢在我的配置文件中详细说明一些内容,所以我添加了它.

Just to note, I also added the type = "ssh" even though that is the default for the connection type, so it isn't needed. I like to be verbose with some things in my configuration files though, so I added it.

更多推荐

如何将文件配置器与 google

本文发布于:2023-11-08 09:36:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1569019.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何将   文件   google

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!