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.

40 lines
1.1KB

  1. ####
  2. # Extra EBS
  3. ####
  4. locals {
  5. should_create_extra_volumes = var.extra_volume_count > 0 && var.use_autoscaling_group == false
  6. }
  7. resource "aws_volume_attachment" "this_extra" {
  8. count = local.should_create_extra_volumes ? var.extra_volume_count : 0
  9. device_name = element(var.extra_volume_device_names, count.index)
  10. volume_id = element(aws_ebs_volume.this_extra.*.id, count.index)
  11. instance_id = aws_instance.this.*.id[0]
  12. }
  13. resource "aws_ebs_volume" "this_extra" {
  14. count = local.should_create_extra_volumes ? var.extra_volume_count : 0
  15. availability_zone = local.availability_zones[0]
  16. size = element(var.extra_volume_sizes, count.index)
  17. type = element(var.extra_volume_types, count.index)
  18. encrypted = true
  19. kms_key_id = local.volume_kms_key_arn
  20. tags = merge(
  21. {
  22. "Name" = format("%s%s", var.prefix, local.use_incremental_names ? format(
  23. "%s-%0${var.num_suffix_digits}d",
  24. var.extra_volume_name,
  25. count.index + local.num_suffix_starting_index + 1
  26. ) : var.extra_volume_name)
  27. },
  28. var.tags,
  29. var.extra_volume_tags,
  30. local.tags,
  31. )
  32. }