跳到主要内容

没有资源的配置器

如果你需要运行不直接与特定资源关联的配置器,你可以将它们与 terraform_data 关联。

terraform_data 的实例被视为普通资源,但它们不执行任何操作。与任何其他资源类型一样,你可以在 terraform_data 资源上配置 配置器连接详细信息。你还可以使用它的 input 参数、triggers_replace 参数以及任何元参数来控制其配置器将在依赖关系图中的确切位置运行。

示例用法

代码块
resource "aws_instance" "cluster" {
count = 3

# ...
}

resource "terraform_data" "cluster" {
# Replacement of any instance of the cluster requires re-provisioning
triggers_replace = aws_instance.cluster.[*].id

# Bootstrap script can run on any instance of the cluster
# So we just choose the first in this case
connection {
host = aws_instance.cluster.[0].public_ip
}

provisioner "remote-exec" {
# Bootstrap script called with private_ip of each node in the cluster
inline = [
"bootstrap-cluster.sh ${join(" ", aws_instance.cluster.*.private_ip)}",
]
}
}