terraform: use AWS launch templates

This commit is contained in:
Leonard Cohnen 2022-10-24 23:35:28 +02:00 committed by 3u13r
parent 3dce7de0f1
commit 7e385c4c86

View File

@ -12,26 +12,28 @@ locals {
} }
resource "aws_launch_configuration" "control_plane_launch_config" { resource "aws_launch_template" "launch_template" {
name_prefix = local.name name_prefix = local.name
image_id = var.image_id image_id = var.image_id
instance_type = var.instance_type instance_type = var.instance_type
iam_instance_profile = var.iam_instance_profile iam_instance_profile {
security_groups = var.security_groups name = var.iam_instance_profile
}
vpc_security_group_ids = var.security_groups
metadata_options { metadata_options {
http_tokens = "required" http_endpoint = "enabled"
http_tokens = "required"
instance_metadata_tags = "enabled"
} }
root_block_device { block_device_mappings {
encrypted = true device_name = "/dev/sdb"
} ebs {
volume_size = var.state_disk_size
ebs_block_device { volume_type = var.state_disk_type
device_name = "/dev/sdb" # Note: AWS may adjust this to /dev/xvdb, /dev/hdb or /dev/nvme1n1 depending on the disk type. See: https://docs.aws.amazon.com/en_us/AWSEC2/latest/UserGuide/device_naming.html encrypted = true
volume_size = var.state_disk_size delete_on_termination = true
volume_type = var.state_disk_type }
encrypted = true
delete_on_termination = true
} }
lifecycle { lifecycle {
@ -40,13 +42,15 @@ resource "aws_launch_configuration" "control_plane_launch_config" {
} }
resource "aws_autoscaling_group" "control_plane_autoscaling_group" { resource "aws_autoscaling_group" "control_plane_autoscaling_group" {
name = local.name name = local.name
launch_configuration = aws_launch_configuration.control_plane_launch_config.name launch_template {
min_size = 1 id = aws_launch_template.launch_template.id
max_size = 10 }
desired_capacity = var.instance_count min_size = 1
vpc_zone_identifier = [var.subnetwork] max_size = 10
target_group_arns = var.target_group_arns desired_capacity = var.instance_count
vpc_zone_identifier = [var.subnetwork]
target_group_arns = var.target_group_arns
lifecycle { lifecycle {
create_before_destroy = true create_before_destroy = true