Terraform not assigning public ip to all instances

The below code should create 3 VM’s with 3 public IP’s. It is not doing that?

I have following terraform code:

resource "aws_subnet" "public_subnet" {
  count  = "3"
  vpc_id = "${aws_vpc.vpc.id}"

  cidr_block              = "${cidrsubnet("${var.vpc_cidr}", 4, count.index)}" #count.index is 3 it creates 3 subnets
  availability_zone       = "${element(var.lst_azs, count.index)}"
  map_public_ip_on_launch = true
}

```Above code creates 3 subnets and 3 different instances are attached to these 3 subnets. But only 1st instance is getting public ip. 2nd and 3rd are not getting public ip's. I have looked online and tried many things but not able to make it work.

VM creation code:

resource “aws_instance” “test” {
instance_type = "${var.micro}”

network_interface {
device_index = 0
network_interface_id = “${aws_network_interface.eth0.id}”
}
}

resource “aws_network_interface” “eth0” {
private_ips = 10.0.0.1
source_dest_check = “true”
security_groups = ["{aws_security_group.sg1.id}"] subnet_id = "{element(data.aws_subnet_ids.sub1.ids,0)}"
lifecycle {
ignore_changes = [“subnet_id”]
}
}

resource “aws_subnet” “sub1” {
count = 3
vpc_id = “{aws_vpc.test1.id}" cidr_block = "{var.security_vpc_cidr_block}, count.index}”
availability_zone = “${element(var.lst_azs, count.index)}”
map_public_ip_on_launch = true
}

data “aws_subnet_ids” “subnets1” {
vpc_id = “${aws_vpc.test1.id}”
depends_on = [“aws_subnet.subnets1”]
}