Cloud/Terraform/Disks
Module
Vars for disks
variable "disk_root" { description = "The root device map." type = list(map(string)) default = [] } variable "disks_additional" { description = "Additional block devices to attach to the vm" type = list(map(string)) default = [] }
main.tf - AWS
/***** * Additional EBS volume - xvdf / sdf *****/ resource "aws_ebs_volume" "extra" { for_each = { for ebs in var.ebs_block_devices : ebs.device_name => ebs } availability_zone = aws_instance.this.availability_zone #size = each.value.size size = lookup(each.value, "size", lookup(each.value, "volume_size", "")) encrypted = lookup(each.value, "encrypted", true) iops = lookup(each.value, "iops", null) # Only for type io1, io2, gp3 snapshot_id = lookup(each.value, "snapshot_id", null) type = lookup(each.value, "type", lookup(each.value, "volume_type", "gp3")) tags = merge( module.common_tags.tags, var.custom_volume_tags, var.tags_volume, { "Name" = join("_", [var.hostname, each.value.device_name]) }, ) } resource "aws_volume_attachment" "ebs_att" { for_each = { for ebs in var.ebs_block_devices : ebs.device_name => ebs } device_name = each.value.device_name volume_id = aws_ebs_volume.extra[each.value.device_name].id instance_id = aws_instance.this.id }
Use Module
e.g.
root_block_device = [{ volume_size = 65 # >65GiB minimum for MS-SQL instance type. volume_type = "gp3" encrypted = true }] # https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/device_naming.html # start at /dev/xvdf for extra ebs # Changes in ebs_block_device argument will be ignored. Use aws_volume_attachment resource to attach and detach volumes from AWS EC2 instances. ### ebs_block_device = [ ] ebs_block_devices = [ { # D: Data "device_name": "/dev/sdf", "volume_size": 60, "volume_type": "gp3", "encrypted": "true", }, { # E: SQLLogs "device_name": "/dev/sdg", "volume_size": 100, "volume_type": "gp3", "encrypted": "true", }, { # F SQLDump "device_name": "/dev/sdh", "volume_size": 50, "volume_type": "gp3", "encrypted": "true", }, { # G SQL "device_name": "/dev/sdi", "volume_size": 50, "volume_type": "gp3", "encrypted": "true", }, { # T: Temp "device_name": "/dev/sdj", "volume_size": 10, "volume_type": "gp3", "encrypted": "true", }, ]