terrraform launch template: Setting root filesystem settings

2 min read | by Jordi Prats

Converting a Launch Configuration to a Launch Template might have a no brainer direct equivalent but in some cases it requires some knowledge of the template we are going to use. That would be the case of the root_block_device dynamic block:

When you want to resize the root device (or configure any other setting) using aws_launch_configuration^you can just set the root_block_device block as follows:

resource "aws_launch_configuration" "spinnaker_microservice_alc" {
  name = "demo_lc"

  root_block_device {
    delete_on_termination = true
    encrypted             = true
    volume_size           = 15
  }

  (...)
}

When using aws_launch_template we need to know where we are going to find the device we want to resize, setting the device_name for the block_device_mappings block:

resource "aws_launch_template" "demo_lt" {
  name_prefix   = "demo_launch_tpl"

  block_device_mappings {
    device_name = "/dev/xvda"

    ebs {
      volume_size           = 15
      encrypted             = true
      delete_on_termination = true
    }
  }

  (...)
}

The root device for most AMIs it's going to be /dev/xvda, but this can change from AMI to AMI so don't take it as something that's always true.


Posted on 07/06/2022