1
votes

i have variable cidr=10.11.12.0/16

And resource with count

resource "aws_network_interface" "first" {
  count     = "${length(var.instance_names)}"
  provider  = "aws.base"

  subnet_id = "${var.cidr}"

  private_ips = ["${concat(
      list(var.first_network_interface_private_ip),
      var.first_network_interface_private_ip_additional
  )}"]

  source_dest_check = "${var.first_network_interface_source_dest_check_enabled}"

security_groups = [
     "${concat(
      list(aws_security_group.this.id),
      var.first_network_interface_security_group_additional
    )}"
  ]

  depends_on = [
    "aws_security_group.this",
  ]

  tags = "${merge(
    var.tags_global,
    var.tags_module,
    map("Name", format("%s - First Interface", element(var.instance_names, count.index))),
    map("Description", format("%s", element(var.instance_names, count.index)))
  )}"
}

i want for every iteration in count to get different IP

i ran into this and don't know how to extract first three octets from

10.11.12. ,probably need to use regular expressions to get octets from CIDR ?, or there is other solution for my problem ?

1

1 Answers

0
votes

Figured it out

  private_ips = ["${concat(
      list(cidrhost(var.cidr , count.index + 249)),
      var.first_network_interface_private_ip_additional
  )}"]

getting 10.11.12.249/250 IPs for both machines