Skip to content

Commit 6124535

Browse files
committed
Enabling encryption at rest with optional KMS key for EBS and EFS; Allowing multiple architecture for AMI and updating to Amazon linux 2
1 parent e6b8e57 commit 6124535

File tree

5 files changed

+22
-21
lines changed

5 files changed

+22
-21
lines changed

_data.tf

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@ data "aws_ami" "amzn" {
55

66
filter {
77
name = "name"
8-
values = ["amzn-ami-*"]
8+
values = ["amzn2-ami-ecs-hvm*"]
99
}
1010

11-
name_regex = ".+-amazon-ecs-optimized$"
11+
filter {
12+
name = "architecture"
13+
values = [var.architecture]
14+
}
15+
16+
name_regex = ".+-ebs$"
1217
}
1318

1419
data "aws_caller_identity" "current" {}

_variables.tf

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ variable "instance_type_3" {
1616
description = "Instance type for ECS workers (third priority)"
1717
}
1818

19+
variable "architecture" {
20+
default = "x86_64"
21+
description = "Architecture to select the AMI, x86_64 or arm64"
22+
}
23+
1924
variable "on_demand_percentage" {
2025
description = "Percentage of on-demand intances vs spot"
2126
default = 100
@@ -159,12 +164,7 @@ variable "autoscaling_default_cooldown" {
159164

160165
variable "instance_volume_size" {
161166
description = "Volume size for docker volume (in GB)"
162-
default = 22
163-
}
164-
165-
variable "instance_volume_size_root" {
166-
description = "Volume size for root volume (in GB)"
167-
default = 16
167+
default = 30
168168
}
169169

170170
variable "lb_access_logs_bucket" {
@@ -217,3 +217,9 @@ variable "alarm_prefix" {
217217
description = "String prefix for cloudwatch alarms. (Optional)"
218218
default = ""
219219
}
220+
221+
variable "kms_key_arn" {
222+
type = string
223+
description = "ARN of a KMS Key to use on EFS and EBS volumes"
224+
default = ""
225+
}

ec2-launch-template.tf

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,10 @@ resource "aws_launch_template" "ecs" {
2020
block_device_mappings {
2121
device_name = "/dev/xvda"
2222

23-
ebs {
24-
volume_size = var.instance_volume_size_root
25-
}
26-
}
27-
28-
block_device_mappings {
29-
device_name = "/dev/xvdcz"
30-
3123
ebs {
3224
volume_size = var.instance_volume_size
25+
encrypted = true
26+
kms_key_id = var.kms_key_arn != "" ? var.kms_key_arn : null
3327
}
3428
}
3529

efs.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
resource "aws_efs_file_system" "ecs" {
22
creation_token = "ecs-${var.name}"
33
encrypted = true
4+
kms_key_id = var.kms_key_arn != "" ? var.kms_key_arn : null
45

56
throughput_mode = var.throughput_mode
67
provisioned_throughput_in_mibps = var.provisioned_throughput_in_mibps

userdata.tpl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ yum update -y
1818
yum install -y amazon-efs-utils aws-cli
1919

2020

21-
echo "### INSTALL SSM AGENT"
22-
cd /tmp
23-
yum install -y https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_amd64/amazon-ssm-agent.rpm
24-
restart amazon-ssm-agent
25-
2621
echo "### SETUP EFS"
2722
EFS_DIR=/mnt/efs
2823
EFS_ID=${tf_efs_id}

0 commit comments

Comments
 (0)