I am creating 2 ec2 instances with terraform and I want to give secondary ip address to the first instance that terraform creates.
I am using below code block
resource "aws_network_interface" "floating_private" {
subnet_id = "${var.subnet_cluster_one}"
private_ips_count = 2
}
resource "aws_instance" "instance_attrix_cluster_one" {
count = 2
instance_type = "${var.aws_instance_type}"
ami = "${var.attrix_ami}"
subnet_id = "${var.subnet_cluster_one}"
security_groups = "${var.aws_security_groups}"
key_name = "${var.ssh_key}"
tags = "${merge(var.default_tags, map("Name", "${format("attrix%02d",
count.index + 1)}-${var.env_name}"))}"
}
I tried to add below code in "aws_instance" block
network_interface = "${floating_private.id ? count.index == 0 : count.index >= 0}"
However, I am seeing the error below -
Error reading config for aws_instance[instance_attrix_cluster_one]: floating_private.id: resource variables must be three parts: TYPE.NAME.ATTR in:
${floating_private.id ? count.index == 0 : count.index >= 0}
How can I set the network_interface attribute if the count == 0?