google-cloud-platform - Terraform:将文件复制到 GCP 计算实例
问题描述
这肯定不会那么复杂吧?我尝试了多种方法,但都失败了。
简单地使用file provisioner
将是最简单的选择,但无济于事。问题是,计算实例没有配置为标准的密码,也没有密钥。
因此,这导致我尝试这样的事情:
resource "google_compute_instance" "test-build" {
...
metadata {
ssh-keys = "jon:${file("./gcloud_instance.pub")}"
}
...
provisioner "file" {
source = "test/test_file"
destination = "/tmp/test_file.txt"
connection {
type = "ssh"
private_key = "${file("./gcloud_instance")}"
agent = "false"
}
}
再次,无济于事。(仅供参考,密钥对是我创建的,我确认公钥正在被推送到计算实例)
我什至尝试将其拆分为模块,然后一个接一个地运行.. 但似乎我们不能在 null_resource 中使用文件提供程序。所以这也行不通。
有没有人找到一种有效地做到这一点的方法?
解决方案
取消它,我解决了..如果我添加用户会有所帮助!回答这个问题,而不是删除它,因为我在网上找不到很多像这样的例子,所以它可能对其他人有用。
resource "google_compute_instance" "test-build" {
project = "artifactory-staging"
name = "file-transfer-test"
machine_type = "n1-standard-2"
zone = "europe-west3-b"
allow_stopping_for_update = "true"
boot_disk {
initialize_params {
image = "centos-7-v20181210"
}
}
network_interface {
subnetwork = "default"
subnetwork_project = "artifactory-staging"
access_config = {}
}
metadata {
ssh-keys = "jon:${file("./creds/gcloud_instance.pub")}"
}
provisioner "file" {
source = "creds/test_file"
destination = "/tmp/test_file"
connection {
type = "ssh"
user = "jon"
private_key = "${file("./creds/gcloud_instance")}"
agent = "false"
}
}
}
推荐阅读
- java - 在java中声明嵌套泛型
- php - 使用 Laravel、Vue、Axios 和 Nginx 的意外 301 重定向,具有不同的 url 相同的调用
- spring-boot - 将实体分配给持久性单元(spring-boot,spring-data-jpa)
- autohotkey - 在按下其他键时发送一个键不会向按下的键发送垃圾邮件
- flutter - Flutter PointerEvent vs OnTap,一个有效,另一个无效
- ember.js - 仍在检索时导航时出现模型问题
- java - 当我尝试创建我的 Android 项目时显示错误
- c++ - 为什么是 numeric_limits
::max() 不等于 -1? - java - 编写正确的 jUnit 测试
- c++ - 为什么没有一个 istream get 函数在这个 c 字符串中存储任何东西?