英文:
How to use count with null-resource?
问题
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
英文:
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
使用count
在resource
下面:
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")
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论