如何设置与 google_compute_instance_template 的自连接以进行文件配置

how to setup self connection to google_compute_instance_template for file provisioning

我正在尝试使用下面显示的方法将文件配置到 google_compute_instance_template

...
  provisioner "file" {
      source = file("${path.module}/../scripts/infrastructure/circleci/docker-compose.production.yml")
      destination = "/tmp/docker_compose_file"

      connection {
        host = google_compute_instance_template.media_apps_template.self_link.public_ip
        agent = false
        type = "ssh"
        user = "ubuntu"
        private_key = "${file("./creds/media_apps")}"
      }
  }

....

parent google_compute_instance_template 看起来像这样

resource "google_compute_instance_template" "media_apps_template" {

}

我得到的错误是 Can't access attributes on a primitive-typed value (string).

如何配置主机部分

试试这个

 ​   ​connection​ { 
 ​     type ​=​ ​"​ssh​" 
 ​     user ​=​ ​"​ubuntu​" 
 ​     private_key ​=​ ​file​(​"​./creds/media_apps​.pem"​) 
 ​     host ​=​ google_compute_instance_template.self_link.public_ip