@@ -31,10 +31,18 @@ resource "aws_autoscaling_group" "this" {
3131locals {
3232 // https://docs.aws.amazon.com/AmazonECS/latest/developerguide/bootstrap_container_instance.html
3333 // https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-agent-config.html
34- user_data = join (" \n " , [
35- " #!/bin/bash" ,
36- " echo ECS_CLUSTER=${ aws_ecs_cluster . this . name } >> /etc/ecs/ecs.config" ,
37- ])
34+ user_data = << EOF
35+ #!/bin/bash
36+
37+ # Format and mount extra disk for Docker usage
38+ mkfs -t xfs /dev/xvdcz
39+ mkdir -p /var/lib/docker
40+ echo '/dev/xvdcz /var/lib/docker xfs defaults,noatime 0 0' >> /etc/fstab
41+ mount -a
42+
43+ # Configure ECS agent
44+ echo ECS_CLUSTER=${ aws_ecs_cluster . this . name } >> /etc/ecs/ecs.config
45+ EOF
3846}
3947
4048resource "aws_launch_template" "this" {
@@ -43,6 +51,12 @@ resource "aws_launch_template" "this" {
4351 instance_type = var. node_instance_type
4452 vpc_security_group_ids = [aws_security_group . this . id ]
4553 user_data = base64encode (local. user_data )
54+ tags = local. tags
55+
56+ tag_specifications {
57+ resource_type = " instance"
58+ tags = merge (local. tags , { " Name" = " ${ local . block_name } /node" })
59+ }
4660
4761 iam_instance_profile {
4862 name = aws_iam_instance_profile. this . name
@@ -57,8 +71,15 @@ resource "aws_launch_template" "this" {
5771 }
5872 }
5973
60- // TODO: Mount volume for /dev/xvdcz (docker use) -> this can be used to tune docker image storage
61- // See https://docs.aws.amazon.com/AmazonECS/latest/developerguide/launch_container_instance.html
74+ // Additional storage volume dedicated to Docker
75+ block_device_mappings {
76+ device_name = " /dev/xvdcz"
77+
78+ ebs {
79+ volume_type = " gp3"
80+ volume_size = var. docker_volume_size
81+ }
82+ }
6283
6384 lifecycle {
6485 create_before_destroy = true
0 commit comments