Cannot create secondary ip on aws_instance self created ENI

We need to be able to have a secondary ip on an aws_instance and are able to do this using aws_network_interface, but that adds and creates it on a second ENI. We need it to be on the primary ENI that is created with the aws_instance. I cant find anywhere how I can do that.

I can do this via console, but would like to have this part scripted. Is this possible?

Yes, looks like you can create the interface yourself first, and then refer to it as eth0: https://www.terraform.io/docs/providers/aws/r/instance.html#network-interfaces

If you retrieve the ENI id with a data source for the instance then the ENI itself is not a resource managed by Terraform and thus you won’t be able to change it.

This comes from the descriptive nature of Terraform.

Ahh, thanks for nudging me in the right direction. I thought it was possible to create the ENI, then reference its id, in the aws_instance, but I was trying to assign it like

network_interface_id = “${aws_network_interface.myinterface.id}”

as a root variable of aws_instance, where it needs to be part of network_interface block in aws_instance like:

network_interface {
    device_index = 0
    network_interface_id = "${aws_network_interface.myinterface.id}"
}

I also had to comment subnet_id, vpc_security_group_ids, and associate_public_ip_address, since the aws_network_interface takes care of that.

Again, many thanks!