Google cloud platform Terraform:将文件复制到GCP计算实例

Google cloud platform Terraform:将文件复制到GCP计算实例,google-cloud-platform,terraform,devops,Google Cloud Platform,Terraform,Devops,这肯定不会那么复杂吧?我尝试过很多方法,但都失败了 简单地使用文件供应器将是最简单的选择,但没有任何效果。问题是,Compute实例没有配置为标准的密码,并且没有密钥 因此,这让我尝试了这样的事情: resource "google_compute_instance" "test-build" { ... metadata { ssh-keys = "jon:${file("./gcloud_instance.pub")}" } ... provisioner "file" {

这肯定不会那么复杂吧?我尝试过很多方法,但都失败了

简单地使用
文件供应器
将是最简单的选择,但没有任何效果。问题是,Compute实例没有配置为标准的密码,并且没有密钥

因此,这让我尝试了这样的事情:

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"
  }
}
再说一次,也没用。(仅供参考,密钥对是我创建的,我确认公钥正在推送到计算实例)

我甚至试着把它分解成模块,然后一个接一个地运行。。但是我们似乎不能在空资源中使用文件提供程序。所以这也行不通


有人找到了有效的方法吗?

取消,我已经解决了。。它有助于我添加用户!回答这个问题,而不是删除它,因为我在网上找不到其他类似的例子,所以它可能对其他人有用

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"
  }
}
}