【发布时间】:2019-04-05 11:22:32
【问题描述】:
我正在使用以下 terraform 脚本创建一个 LINUX Debian 实例。
resource "template_dir" "config" {
source_dir = "${path.module}/config.d/"
destination_dir = "/tmp/fluent-templates"
vars = {
instance-name = "${var.instance_name}"
}
}
resource "google_compute_instance" "default" {
name = "${var.instance_name}"
project = "${var.project}"
machine_type = "${var.machine_type}"
zone = "${var.zone}"
boot_disk {
initialize_params {
image = "${var.boot_disk_image}"
}
}
network_interface {
network = "default"
access_config {
// Ephemeral IP
}
}
#StackDriver must be installed before this command runs,
#as it will create the "/etc/google-fluentd/config.d" directory,
#which is supposed to be replaced by the below provisioner
provisioner "file" {
source = "${template_dir.config.destination_dir}"
destination = "/etc/google-fluentd/config.d"
}
}
我想使用 Terraform 在这些 Debian/Ubuntu 上安装 StackDriver Logging Agent 以避免手动 SSH 并在每次启动实例时安装它。
我尝试使用remote-exec,但它对我不起作用。下面是remote-exec的代码:
provisioner "remote-exec" {
inline = [
"curl -sSO https://dl.google.com/cloudagents/install-logging-agent.sh",
"bash install-logging-agent.sh",
]
}
将上述代码放入我的 terraform 脚本中的 google_compute_instance 资源中不起作用,并在大约 5 分钟后无法连接并出现以下错误:
* google_compute_instance.default:
timeout - last error: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain
我不确定如何连接到服务器以使用 remote-exec。
【问题讨论】:
-
如果您想使用它进行远程配置,您需要为实例设置
sshauth。
标签: google-compute-engine terraform stackdriver google-cloud-stackdriver