我试图将EC2实例的属性用作变量,但它会一直失败或无法正常工作。如下所示,我想将实例的私有IP插入到将被复制到实例的配置文件中。然后,remote-exec脚本将文件移动到位(/etc/vault.d/server-config.json)
instances.tf
resource "template_file" "tpl-vault-server-config" {
template = "${file("${path.module}/templates/files/vault-server-config.json.tpl")}"
vars {
aws_private_ip = "${aws_instance.ec2-consul-server.private_ip}"
}
}
provisioner "file" {
source = "${template_file.tpl-vault-server-config.rendered}"
destination = "/tmp/vault-server-config.json"
}
拱顶 - 服务器 - config.json.tpl
backend "consul" {
address = "127.0.0.1:8500"
path = "vault"
tls_enable = 1
tls_ca_file = "/etc/consul.d/ssl/ca.cert"
tls_cert_file = "/etc/consul.d/ssl/consul.cert"
tls_key_file = "/etc/consul.d/ssl/consul.key"
}
listener "tcp" {
address = "${aws_private_ip}:8200"
tls_cert_file = "/etc/consul.d/ssl/consul.cert"
tls_key_file = "/etc/consul.d/ssl/consul.key"
}
terraform plan
上的错误是:
* aws_instance.ec2-consul-server: missing dependency: template_file.tpl-vault-server-config
问题:
提前致谢。
答案 0 :(得分:0)
我意识到我在当前资源中定义了template_file资源,这是问题的一部分。当我解决这个问题时,事情变得更容易了。