Skip to content

Commit a480639

Browse files
committed
ASG: add instance lifetime and SSM in launchtemplate for auto AMI upgrade
1 parent 96253a6 commit a480639

File tree

1 file changed

+6
-19
lines changed

1 file changed

+6
-19
lines changed

modules/instance/main.tf

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,16 @@ locals {
55
}
66
}
77

8-
data "aws_ami" "ubuntu2204" {
9-
most_recent = true
10-
owners = ["099720109477"] # Canonical
11-
filter {
12-
name = "architecture"
13-
values = ["arm64"]
14-
}
15-
filter {
16-
name = "virtualization-type"
17-
values = ["hvm"]
18-
}
19-
filter {
20-
name = "name"
21-
values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-arm64-server-*"]
22-
}
23-
}
24-
258
resource "aws_launch_template" "launch_template" {
269
name_prefix = "DatadogAgentlessScannerLaunchTemplate"
27-
image_id = data.aws_ami.ubuntu2204.id
10+
image_id = "resolve:ssm:/aws/service/canonical/ubuntu/server/22.04/stable/current/arm64/hvm/ebs-gp2/ami-id"
2811
instance_type = var.instance_type
2912
user_data = base64encode(var.user_data)
3013
vpc_security_group_ids = var.vpc_security_group_ids
3114
key_name = var.key_name
3215

3316
block_device_mappings {
34-
device_name = data.aws_ami.ubuntu2204.root_device_name
17+
device_name = "/dev/sda1"
3518
ebs {
3619
delete_on_termination = true
3720
encrypted = true
@@ -82,6 +65,10 @@ resource "aws_autoscaling_group" "asg" {
8265
version = aws_launch_template.launch_template.latest_version
8366
}
8467

68+
# Instances are terminated every 24 hours and recreated with latest AMI.
69+
# This allows automated upgrade of our instances baseline.
70+
max_instance_lifetime = 24 * 3600
71+
8572
instance_refresh {
8673
strategy = "Rolling"
8774
preferences {

0 commit comments

Comments
 (0)