Getting Error: host for provisioner cannot be empty

Hi All,

Please let me know where I’ve made mistake. Tried to figure out, but no luck. PFA snap as well.

===========================================================
resource “aws_instance” “instance” {
count = length(aws_subnet.public_subnet..id)
ami = var.ami_id
instance_type = var.instance_type
subnet_id = element(aws_subnet.public_subnet.
.id, count.index)
security_groups = [aws_security_group.sg.id, ]
key_name = “Keypair-01”
user_data = “${file(“user_data.sh”)}”

provisioner “remote-exec” {
inline = [
“useradd ansible”,
“echo ‘ansible’ | passwd --stdin ansible”,
“sh user_data.sh”,
]
}

connection {
type = “ssh”
user = “ec2-user”
host = element(self.*.public_ip, count.index)
private_key = file(var.key_pair_path)
}
}

image