英文:
How to use count with null-resource?
问题
我已经定义了一个名为null_resource
的资源,如下所示:
resource "null_resource" "mynull-resource" {
triggers = {
always-update = timestamp()
}
# Connection Block for Provisioners to connect to EC2 Instance
connection {
type = "ssh"
host = aws_instance.web[count.index].public_ip #Giving error
user = "ec2-user"
password = ""
private_key = file("ec2keypair.pem")
}
}
错误信息:
The "count" object can only be used in "module", "resource", and "data" blocks, and only when the "count" argument is set.
我该如何更新connection block
以连接到多个主机?
我尝试使用spat operator
,但是host = aws_instance.web.*.public_ip
不起作用。
英文:
I have defined a null resource
which looks as below:
resource "null_resource" "mynull-resource" {
triggers = {
always-update = timestamp()
}
# Connection Block for Provisioners to connect to EC2 Instance
connection {
type = "ssh"
host = aws_instance.web[count.index].public_ip #Giving error
user = "ec2-user"
password = ""
private_key = file("ec2keypair.pem")
}
Error:
The "count" object can only be used in "module", "resource", and "data" blocks, and only when the "count" argument is set.
How can I update the connection block
to connect to multiple hosts?
I have tried using spat operator
but it is not working host = aws_instance.web.*.public_ip
答案1
得分: 1
在resource
下使用count
:
resource "null_resource" "mynull-resource" {
count = length(aws_instance.web)
triggers = {
always-update = timestamp()
}
# Provisioners连接到EC2实例的连接块
connection {
type = "ssh"
host = aws_instance.web[count.index].public_ip #出现错误
user = "ec2-user"
password = ""
private_key = file("ec2keypair.pem")
}
}
请注意,我只提供了代码的翻译部分,不包括其他内容。
英文:
Use count
under resource
:
resource "null_resource" "mynull-resource" {
count = length(aws_instance.web)
triggers = {
always-update = timestamp()
}
# Connection Block for Provisioners to connect to EC2 Instance
connection {
type = "ssh"
host = aws_instance.web[count.index].public_ip #Giving error
user = "ec2-user"
password = ""
private_key = file("ec2keypair.pem")
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论