Skip to content

Commit

Permalink
Replaces launch configuration resources with launch template (#54) (#29)
Browse files Browse the repository at this point in the history
Recommended by AWS. Required to use fuller range of instance types.

Co-authored-by: Mark Cooper <mark.c.cooper@outlook.com>
  • Loading branch information
dbernstein and mark-cooper authored Dec 13, 2024
1 parent d29cd49 commit 97e04cd
Show file tree
Hide file tree
Showing 7 changed files with 232 additions and 119 deletions.
51 changes: 34 additions & 17 deletions mill/audit-worker.tf
Original file line number Diff line number Diff line change
@@ -1,29 +1,46 @@
# config the audit worker launch config, autoscaling group, alarms, etc

resource "aws_launch_configuration" "audit_worker_launch_config" {
name_prefix = "${var.stack_name}-audit-worker-launch-config_"
image_id = local.node_image_id
instance_type = var.worker_instance_class
iam_instance_profile = data.aws_iam_instance_profile.duracloud.name
security_groups = [aws_security_group.mill_instance.id]
key_name = var.ec2_keypair
spot_price = var.worker_spot_price
user_data = templatefile("${path.module}/resources/cloud-init.tpl", merge(local.cloud_init_props, { node_type = "audit-worker" }))
root_block_device {
volume_type = "gp2"
volume_size = 60
resource "aws_launch_template" "audit_worker_launch_template" {
name_prefix = "${var.stack_name}-audit-worker-launch-template_"
image_id = local.node_image_id
instance_type = var.worker_instance_class
vpc_security_group_ids = [aws_security_group.mill_instance.id]
key_name = var.ec2_keypair
user_data = base64encode(templatefile("${path.module}/resources/cloud-init.tpl", merge(local.cloud_init_props, { node_type = "audit-worker" })))

block_device_mappings {
device_name = "/dev/sda1"
ebs {
volume_size = 60
volume_type = "gp2"
}
}

iam_instance_profile { name = data.aws_iam_instance_profile.duracloud.name }

instance_market_options {
market_type = "spot"
spot_options {
max_price = var.worker_spot_price
}
}

lifecycle {
create_before_destroy = true
}
}

resource "aws_autoscaling_group" "audit_worker_asg" {
name = "${var.stack_name}-audit-worker-asg"
launch_configuration = aws_launch_configuration.audit_worker_launch_config.name
vpc_zone_identifier = [data.aws_subnet.duracloud_a.id, data.aws_subnet.duracloud_c.id, data.aws_subnet.duracloud_d.id]
max_size = var.audit_worker_max
min_size = 1
name = "${var.stack_name}-audit-worker-asg"
vpc_zone_identifier = [data.aws_subnet.duracloud_a.id, data.aws_subnet.duracloud_c.id, data.aws_subnet.duracloud_d.id]
max_size = var.audit_worker_max
min_size = 1

launch_template {
id = aws_launch_template.audit_worker_launch_template.id
version = aws_launch_template.audit_worker_launch_template.latest_version
}

tag {
key = "Name"
value = "${var.stack_name}-audit-worker"
Expand Down
53 changes: 35 additions & 18 deletions mill/bit-report-worker.tf
Original file line number Diff line number Diff line change
@@ -1,33 +1,50 @@
# config the bit_report worker launch config, autoscaling group, alarms, etc

resource "aws_launch_configuration" "bit_report_worker_launch_config" {
name_prefix = "${var.stack_name}-bit_report-worker-launch-config_"
image_id = local.node_image_id
instance_type = var.worker_instance_class
iam_instance_profile = data.aws_iam_instance_profile.duracloud.name
security_groups = [aws_security_group.mill_instance.id]
key_name = var.ec2_keypair
spot_price = var.worker_spot_price
user_data = templatefile("${path.module}/resources/cloud-init.tpl",
resource "aws_launch_template" "bit_report_worker_launch_template" {
name_prefix = "${var.stack_name}-bit_report-worker-launch-template_"
image_id = local.node_image_id
instance_type = var.worker_instance_class
vpc_security_group_ids = [aws_security_group.mill_instance.id]
key_name = var.ec2_keypair
user_data = base64encode(templatefile("${path.module}/resources/cloud-init.tpl",
merge(local.cloud_init_props, {
node_type = "bit-report-worker"
max_worker_threads = var.bit_report_max_worker_threads
}))
root_block_device {
volume_type = "gp2"
volume_size = 20
})))

block_device_mappings {
device_name = "/dev/sda1"
ebs {
volume_size = 20
volume_type = "gp2"
}
}

iam_instance_profile { name = data.aws_iam_instance_profile.duracloud.name }

instance_market_options {
market_type = "spot"
spot_options {
max_price = var.worker_spot_price
}
}

lifecycle {
create_before_destroy = true
}
}

resource "aws_autoscaling_group" "bit_report_worker_asg" {
name = "${var.stack_name}-bit_report-worker-asg"
launch_configuration = aws_launch_configuration.bit_report_worker_launch_config.name
vpc_zone_identifier = [data.aws_subnet.duracloud_a.id, data.aws_subnet.duracloud_c.id, data.aws_subnet.duracloud_d.id]
max_size = 1
min_size = 0
name = "${var.stack_name}-bit_report-worker-asg"
vpc_zone_identifier = [data.aws_subnet.duracloud_a.id, data.aws_subnet.duracloud_c.id, data.aws_subnet.duracloud_d.id]
max_size = 1
min_size = 0

launch_template {
id = aws_launch_template.bit_report_worker_launch_template.id
version = aws_launch_template.bit_report_worker_launch_template.latest_version
}

tag {
key = "Name"
value = "${var.stack_name}-bit-report-worker"
Expand Down
51 changes: 34 additions & 17 deletions mill/bit-worker.tf
Original file line number Diff line number Diff line change
@@ -1,29 +1,46 @@
# config the bit worker launch config, autoscaling group, alarms, etc

resource "aws_launch_configuration" "bit_worker_launch_config" {
name_prefix = "${var.stack_name}-bit-worker-launch-config_"
image_id = local.node_image_id
instance_type = var.worker_instance_class
iam_instance_profile = data.aws_iam_instance_profile.duracloud.name
security_groups = [aws_security_group.mill_instance.id]
key_name = var.ec2_keypair
spot_price = var.worker_spot_price
user_data = templatefile("${path.module}/resources/cloud-init.tpl", merge(local.cloud_init_props, { node_type = "bit-worker" }))
root_block_device {
volume_type = "gp2"
volume_size = 60
resource "aws_launch_template" "bit_worker_launch_template" {
name_prefix = "${var.stack_name}-bit-worker-launch-template_"
image_id = local.node_image_id
instance_type = var.worker_instance_class
vpc_security_group_ids = [aws_security_group.mill_instance.id]
key_name = var.ec2_keypair
user_data = base64encode(templatefile("${path.module}/resources/cloud-init.tpl", merge(local.cloud_init_props, { node_type = "bit-worker" })))

block_device_mappings {
device_name = "/dev/sda1"
ebs {
volume_size = 60
volume_type = "gp2"
}
}

iam_instance_profile { name = data.aws_iam_instance_profile.duracloud.name }

instance_market_options {
market_type = "spot"
spot_options {
max_price = var.worker_spot_price
}
}

lifecycle {
create_before_destroy = true
}
}

resource "aws_autoscaling_group" "bit_worker_asg" {
name = "${var.stack_name}-bit-worker-asg"
launch_configuration = aws_launch_configuration.bit_worker_launch_config.name
vpc_zone_identifier = [data.aws_subnet.duracloud_a.id, data.aws_subnet.duracloud_c.id, data.aws_subnet.duracloud_d.id]
max_size = var.bit_worker_max
min_size = 0
name = "${var.stack_name}-bit-worker-asg"
vpc_zone_identifier = [data.aws_subnet.duracloud_a.id, data.aws_subnet.duracloud_c.id, data.aws_subnet.duracloud_d.id]
max_size = var.bit_worker_max
min_size = 0

launch_template {
id = aws_launch_template.bit_worker_launch_template.id
version = aws_launch_template.bit_worker_launch_template.latest_version
}

tag {
key = "Name"
value = "${var.stack_name}-bit-worker"
Expand Down
51 changes: 34 additions & 17 deletions mill/high-priority-dup-worker.tf
Original file line number Diff line number Diff line change
@@ -1,29 +1,46 @@
# config the high priority dup worker launch config, autoscaling group, alarms, etc

resource "aws_launch_configuration" "high_priority_dup_worker_launch_config" {
name_prefix = "${var.stack_name}-high_priority_dup-worker-launch-config_"
image_id = local.node_image_id
instance_type = var.worker_instance_class
iam_instance_profile = data.aws_iam_instance_profile.duracloud.name
security_groups = [aws_security_group.mill_instance.id]
key_name = var.ec2_keypair
spot_price = var.worker_spot_price
user_data = templatefile("${path.module}/resources/cloud-init.tpl", merge(local.cloud_init_props, { node_type = "dup-worker" }))
root_block_device {
volume_type = "gp2"
volume_size = 60
resource "aws_launch_template" "high_priority_dup_worker_launch_template" {
name_prefix = "${var.stack_name}-high_priority_dup-worker-launch-template_"
image_id = local.node_image_id
instance_type = var.worker_instance_class
vpc_security_group_ids = [aws_security_group.mill_instance.id]
key_name = var.ec2_keypair
user_data = base64encode(templatefile("${path.module}/resources/cloud-init.tpl", merge(local.cloud_init_props, { node_type = "dup-worker" })))

block_device_mappings {
device_name = "/dev/sda1"
ebs {
volume_size = 60
volume_type = "gp2"
}
}

iam_instance_profile { name = data.aws_iam_instance_profile.duracloud.name }

instance_market_options {
market_type = "spot"
spot_options {
max_price = var.worker_spot_price
}
}

lifecycle {
create_before_destroy = true
}
}

resource "aws_autoscaling_group" "high_priority_dup_worker_asg" {
name = "${var.stack_name}-high_priority_dup-worker-asg"
launch_configuration = aws_launch_configuration.high_priority_dup_worker_launch_config.name
vpc_zone_identifier = [data.aws_subnet.duracloud_a.id, data.aws_subnet.duracloud_c.id, data.aws_subnet.duracloud_d.id]
max_size = var.high_priority_dup_worker_max
min_size = 0
name = "${var.stack_name}-high_priority_dup-worker-asg"
vpc_zone_identifier = [data.aws_subnet.duracloud_a.id, data.aws_subnet.duracloud_c.id, data.aws_subnet.duracloud_d.id]
max_size = var.high_priority_dup_worker_max
min_size = 0

launch_template {
id = aws_launch_template.high_priority_dup_worker_launch_template.id
version = aws_launch_template.high_priority_dup_worker_launch_template.latest_version
}

tag {
key = "Name"
value = "${var.stack_name}-high-priority-duplicate-worker"
Expand Down
51 changes: 34 additions & 17 deletions mill/low-priority-dup-worker.tf
Original file line number Diff line number Diff line change
@@ -1,29 +1,46 @@
# config the low priority dup worker launch config, autoscaling group, alarms, etc

resource "aws_launch_configuration" "low_priority_dup_worker_launch_config" {
name_prefix = "${var.stack_name}-low_priority_dup-worker-launch-config_"
image_id = local.node_image_id
instance_type = var.worker_instance_class
iam_instance_profile = data.aws_iam_instance_profile.duracloud.name
security_groups = [aws_security_group.mill_instance.id]
key_name = var.ec2_keypair
spot_price = var.worker_spot_price
user_data = templatefile("${path.module}/resources/cloud-init.tpl", merge(local.cloud_init_props, { node_type = "dup-worker" }))
root_block_device {
volume_type = "gp2"
volume_size = 60
resource "aws_launch_template" "low_priority_dup_worker_launch_template" {
name_prefix = "${var.stack_name}-low_priority_dup-worker-launch-template_"
image_id = local.node_image_id
instance_type = var.worker_instance_class
vpc_security_group_ids = [aws_security_group.mill_instance.id]
key_name = var.ec2_keypair
user_data = base64encode(templatefile("${path.module}/resources/cloud-init.tpl", merge(local.cloud_init_props, { node_type = "dup-worker" })))

block_device_mappings {
device_name = "/dev/sda1"
ebs {
volume_size = 60
volume_type = "gp2"
}
}

iam_instance_profile { name = data.aws_iam_instance_profile.duracloud.name }

instance_market_options {
market_type = "spot"
spot_options {
max_price = var.worker_spot_price
}
}

lifecycle {
create_before_destroy = true
}
}

resource "aws_autoscaling_group" "low_priority_dup_worker_asg" {
name = "${var.stack_name}-low_priority_dup-worker-asg"
launch_configuration = aws_launch_configuration.low_priority_dup_worker_launch_config.name
vpc_zone_identifier = [data.aws_subnet.duracloud_a.id, data.aws_subnet.duracloud_c.id, data.aws_subnet.duracloud_d.id]
max_size = var.low_priority_dup_worker_max
min_size = 0
name = "${var.stack_name}-low_priority_dup-worker-asg"
vpc_zone_identifier = [data.aws_subnet.duracloud_a.id, data.aws_subnet.duracloud_c.id, data.aws_subnet.duracloud_d.id]
max_size = var.low_priority_dup_worker_max
min_size = 0

launch_template {
id = aws_launch_template.low_priority_dup_worker_launch_template.id
version = aws_launch_template.low_priority_dup_worker_launch_template.latest_version
}

tag {
key = "Name"
value = "${var.stack_name}-low-priority-duplicate-worker"
Expand Down
43 changes: 27 additions & 16 deletions mill/sentinel.tf
Original file line number Diff line number Diff line change
@@ -1,27 +1,38 @@
# config the sentinel
resource "aws_launch_configuration" "sentinel_launch_config" {
name_prefix = "${var.stack_name}-sentinel-launch-config_"
image_id = local.node_image_id
instance_type = var.sentinel_instance_class
iam_instance_profile = data.aws_iam_instance_profile.duracloud.name
security_groups = [aws_security_group.mill_instance.id]
key_name = var.ec2_keypair
user_data = templatefile("${path.module}/resources/cloud-init.tpl", merge(local.cloud_init_props, { node_type = "sentinel" }))
root_block_device {
volume_type = "gp2"
volume_size = 20
resource "aws_launch_template" "sentinel_launch_template" {
name_prefix = "${var.stack_name}-sentinel-launch-template_"
image_id = local.node_image_id
instance_type = var.sentinel_instance_class
vpc_security_group_ids = [aws_security_group.mill_instance.id]
key_name = var.ec2_keypair
user_data = base64encode(templatefile("${path.module}/resources/cloud-init.tpl", merge(local.cloud_init_props, { node_type = "sentinel" })))

block_device_mappings {
device_name = "/dev/sda1"
ebs {
volume_size = 20
volume_type = "gp2"
}
}

iam_instance_profile { name = data.aws_iam_instance_profile.duracloud.name }

lifecycle {
create_before_destroy = true
}
}

resource "aws_autoscaling_group" "sentinel_asg" {
name = "${var.stack_name}-sentinel-asg"
launch_configuration = aws_launch_configuration.sentinel_launch_config.name
vpc_zone_identifier = [data.aws_subnet.duracloud_a.id, data.aws_subnet.duracloud_c.id, data.aws_subnet.duracloud_d.id]
max_size = 1
min_size = 1
name = "${var.stack_name}-sentinel-asg"
vpc_zone_identifier = [data.aws_subnet.duracloud_a.id, data.aws_subnet.duracloud_c.id, data.aws_subnet.duracloud_d.id]
max_size = 1
min_size = 1

launch_template {
id = aws_launch_template.sentinel_launch_template.id
version = aws_launch_template.sentinel_launch_template.latest_version
}

tag {
key = "Name"
value = "${var.stack_name}-sentinel"
Expand Down
Loading

0 comments on commit 97e04cd

Please sign in to comment.