X EC2 (or 1 ASG X:X); X external volumes; X network interfaces; KMS key for volumes; Key pair
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
2.2KB

  1. ####
  2. # Network Interfaces
  3. ####
  4. locals {
  5. should_create_extra_network_interface = var.extra_network_interface_count > 0 && var.use_autoscaling_group == false
  6. extra_network_interface_security_group_ids = var.extra_network_interface_security_group_ids == null ? local.security_group_ids : var.extra_network_interface_security_group_ids
  7. extra_network_interface_num_suffix_starting_index = local.num_suffix_starting_index + var.extra_network_interface_num_suffix_offset
  8. }
  9. resource "aws_network_interface" "this_extra" {
  10. count = local.should_create_extra_network_interface ? var.extra_network_interface_count : 0
  11. description = "Extra network interface ${count.index} for ${var.name} instance."
  12. subnet_id = local.subnet_ids[0]
  13. private_ips = element(var.extra_network_interface_private_ips, count.index)
  14. private_ips_count = element(var.extra_network_interface_private_ips_counts, count.index)
  15. source_dest_check = element(var.extra_network_interface_source_dest_checks, count.index)
  16. tags = merge(
  17. {
  18. "Name" = format("%s%s", var.prefix, local.use_incremental_names ? format(
  19. "%s-%0${var.num_suffix_digits}d",
  20. var.extra_network_interface_name,
  21. count.index + local.extra_network_interface_num_suffix_starting_index
  22. ) : var.extra_network_interface_name)
  23. },
  24. var.tags,
  25. var.extra_network_interface_tags,
  26. local.tags,
  27. )
  28. }
  29. resource "aws_network_interface_attachment" "this_extra" {
  30. count = local.should_create_extra_network_interface ? var.extra_network_interface_count : 0
  31. instance_id = aws_instance.this.*.id[0]
  32. network_interface_id = aws_network_interface.this_extra.*.id[count.index]
  33. device_index = count.index + 1
  34. }
  35. resource "aws_network_interface_sg_attachment" "this_extra" {
  36. count = local.should_create_extra_network_interface ? var.extra_network_interface_security_group_count * var.extra_network_interface_count : 0
  37. security_group_id = element(local.extra_network_interface_security_group_ids, count.index)
  38. network_interface_id = element(aws_network_interface.this_extra.*.id, floor(count.index / var.extra_network_interface_security_group_count) % var.extra_network_interface_count)
  39. }