Getting Error: Inappropriate value for attribute "host": string required

Hi All,

Could you please guide me how can I establish connection to all 3 servers to execute remote-exec provisioner command.

##########################################################################################

Creating 3 EC2 Instances:

##########################################################################################

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”
iam_instance_profile = “${data.aws_iam_role.iam_role.name}”

tags = {
“Name” = “Instance-${count.index}”
“Environment” = “Test”
“CreatedBy” = “Terraform”
}

provisioner “remote-exec” {
inline = [“useradd ansible”,
“echo ‘ansible:ansible’ | chpasswd”,
]

connection {
type = “ssh”
user = “ec2-user”
host = “dollar{self.*.private_ip}”
private_key = “dollar{file(var.ssh_private_key)}”
}

}

provisioner “local-exec” {
command = “ansible-playbook -i aws_ec2.yml --private_key=Keypair-01.pem --user ec2-user”
on_failure = continue
}

}

############################################################################################

Creating 3 Elastic IPs:

############################################################################################

resource “aws_eip” “eip” {
count = length(aws_instance.instance..id)
instance = element(aws_instance.instance.
.id, count.index)
public_ipv4_pool = “amazon”
vpc = true

tags = {
“Name” = “EIP-${count.index}”
}
}

############################################################################################

Creating EIP association with EC2 Instances:

############################################################################################

resource “aws_eip_association” “eip_association” {
count = length(aws_eip.eip)
instance_id = element(aws_instance.instance..id, count.index)
allocation_id = element(aws_eip.eip.
.id, count.index)
}

=======================================================================

Error:

image

I am facing the same issue. can anyone help me on this?