Skip to content

Commit

Permalink
OPS-5932: Migrate to launch template
Browse files Browse the repository at this point in the history
  • Loading branch information
vikkasyousaf committed May 31, 2024
1 parent 785ef1b commit a0dda90
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ Default:
| <a name="output_bastion_asg_name"></a> [bastion\_asg\_name](#output\_bastion\_asg\_name) | Autoscaling group name of the bastion host. (or empty string if bastion host is disabled) |
| <a name="output_bastion_elb_fqdn"></a> [bastion\_elb\_fqdn](#output\_bastion\_elb\_fqdn) | The auto-generated FQDN of the bastion ELB. |
| <a name="output_bastion_elb_security_group_id"></a> [bastion\_elb\_security\_group\_id](#output\_bastion\_elb\_security\_group\_id) | The ID of the SSH security group of the bastion host that can be attached to any other private instance in order to ssh into it. (or empty string if bastion host is disabled) |
| <a name="output_bastion_launch_config_name"></a> [bastion\_launch\_config\_name](#output\_bastion\_launch\_config\_name) | Launch configuration name of the bastion host. (or empty string if bastion host is disabled) |
| <a name="output_bastion_launch_template_name"></a> [bastion\_launch\_template\_name](#output\_bastion\_launch\_template\_name) | Launch template name of the bastion host. (or empty string if bastion host is disabled) |
| <a name="output_bastion_route53_public_dns_name"></a> [bastion\_route53\_public\_dns\_name](#output\_bastion\_route53\_public\_dns\_name) | The route53 public dns name of the bastion ELB if set. |
| <a name="output_bastion_security_group_id"></a> [bastion\_security\_group\_id](#output\_bastion\_security\_group\_id) | The ID of the SSH security group of the bastion host that can be attached to any other private instance in order to ssh into it. (or empty string if bastion host is disabled) |
| <a name="output_cgw_ids"></a> [cgw\_ids](#output\_cgw\_ids) | List of IDs of Customer Gateway |
Expand Down
29 changes: 16 additions & 13 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -128,31 +128,31 @@ resource "aws_security_group" "bastion" {
)
}

resource "aws_launch_configuration" "bastion" {
resource "aws_launch_template" "bastion" {
count = var.vpc_enable_bastion_host ? 1 : 0

name_prefix = local.bastion_lc_name
image_id = data.aws_ami.bastion[0].image_id
instance_type = var.bastion_instance_type
security_groups = [aws_security_group.bastion[0].id]
enable_monitoring = false
user_data = templatefile("${path.module}/user_data.sh.tftpl",
name_prefix = local.bastion_lc_name
image_id = data.aws_ami.bastion[0].image_id
instance_type = var.bastion_instance_type
vpc_security_group_ids = [aws_security_group.bastion[0].id]
user_data = base64encode(templatefile("${path.module}/user_data.sh.tftpl",
{
ssh_user = "ec2-user"
ssh_keys = join("\n", var.bastion_ssh_keys)
}
)
))

metadata_options {
http_tokens = "required"
http_put_response_hop_limit = 1
http_endpoint = "enabled"
}

associate_public_ip_address = false

root_block_device {
volume_size = "8"
block_device_mappings {
device_name = "/dev/sda1"
ebs {
volume_size = "8"
}
}

lifecycle {
Expand All @@ -174,7 +174,10 @@ resource "aws_autoscaling_group" "bastion" {
health_check_type = "EC2"
force_delete = false
wait_for_capacity_timeout = 0
launch_configuration = aws_launch_configuration.bastion[0].name
launch_template {
id = aws_launch_template.bastion[0].id
version = aws_launch_template.bastion[0].latest_version
}

load_balancers = [module.aws_elb.id]

Expand Down
6 changes: 3 additions & 3 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ output "bastion_asg_name" {
value = join(",", aws_autoscaling_group.bastion.*.name)
}

output "bastion_launch_config_name" {
description = "Launch configuration name of the bastion host. (or empty string if bastion host is disabled)"
value = join(",", aws_launch_configuration.bastion.*.name)
output "bastion_launch_template_name" {
description = "Launch template name of the bastion host. (or empty string if bastion host is disabled)"
value = join(",", aws_launch_template.bastion.*.name)
}

# -------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit a0dda90

Please sign in to comment.