这肯定不会那么复杂吗?我尝试过许多方法,但都失败了。
仅使用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中使用文件提供程序。所以那也不行。
有人找到有效的方法吗?
答案 0 :(得分:1)
取消,我解决了..如果添加用户,它会有所帮助!回答这个问题,而不是删除它,因为像这样的例子我在网上找不到很多其他东西,因此它可能对其他人有用。
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"
}
}
}