使用Terraform提供Digitalocean实例
我正在尝试使用Terraform提供一个数字海洋水滴。我似乎缺少连接块中的主机参数,但不确定digitalocean需要什么值 这是我的配置文件:使用Terraform提供Digitalocean实例,terraform,Terraform,我正在尝试使用Terraform提供一个数字海洋水滴。我似乎缺少连接块中的主机参数,但不确定digitalocean需要什么值 这是我的配置文件: resource "digitalocean_droplet" "test" { ima
resource "digitalocean_droplet" "test" {
image = "ubuntu-18-04-x64"
name = "test"
region = "nyc1"
size = "512mb"
private_networking = true
ssh_keys = [
"${var.ssh_fingerprint}"
]
connection {
user = "root"
type = "ssh"
private_key = "${file("~/.ssh/id_rsa")}"
timeout = "2m"
}
provisioner "remote-exec" {
inline = [
"export PATH=$PATH:/usr/bin",
# install nginx
"sudo apt-get update",
"sudo apt-get -y install nginx"
]
}
}
“terraform validate”给了我一个错误:
错误:缺少必需的参数
在资源“digitalocean_液滴”测试中的frontend.tf第11行:
11:连接{
参数“host”是必需的,但未找到定义
我胡乱琢磨,找到了答案 在连接块中,主机应为:
connection {
user = "root"
type = "ssh"
host = "${self.ipv4_address}"
private_key = "${file(var.pvt_key)}"
timeout = "2m"
}
您可以显式引用导出的变量:
connection {
user = "root"
host = "${digitalocean_droplet.test.ipv4_address}"
type = "ssh"
password = "${file(var.pvt_key)}"
}
我认为你的语法有问题 请尝试使用以下方法:
private_key = file("/home/user/.ssh/id_rsa")
我使用的是terraform版本0.12.25
祝你好运