terraform-aws-modules / terraform-aws-autoscaling

Terraform module to create AWS Auto Scaling resources 🇺🇦
https://registry.terraform.io/modules/terraform-aws-modules/autoscaling/aws
Apache License 2.0
292 stars 556 forks source link

feat: Support for "Instance Refresh" #137

Closed spatel96 closed 3 years ago

spatel96 commented 3 years ago

Description

Adding the instance refresh block to the ASG, for now this is a resource that is always created and uses defaults defined in variables.

Not sure if it would make sense to attempt to place this in a dynamic block to make it an optional configuration

Motivation and Context

Instance refresh makes it such that we do not need an external entity to keep our ASGs updated.

Once such use case is a new AMI being released, causing a change in the EC2 Launch configuration attached to an ASG. Currently I've seen people have Cloudformation stacks to manage a "rolling" upgrade of the EC2 instances. There are other 3rd party tools that do this, however that is heavy weight especially since Instance Refresh has been released.

fixes https://github.com/terraform-aws-modules/terraform-aws-autoscaling/issues/130

Breaking Changes

If you have any 3rd party tools that manage the EC2 instances within an ASG then this might cause issues in respect to multiple processes attempting to update the ASG.

If this proves to be a problem, we can perhaps add a dynamic block mentioned previously to make this an optional configuration perhaps.

How Has This Been Tested?

Show Plan ```hcl Refreshing Terraform state in-memory prior to plan... The refreshed state will be used to calculate this plan, but will not be persisted to local or remote state storage. data.aws_vpc.default: Refreshing state... data.aws_ami.amazon_linux: Refreshing state... data.aws_subnet_ids.all: Refreshing state... data.aws_security_group.default: Refreshing state... ------------------------------------------------------------------------ An execution plan has been generated and is shown below. Resource actions are indicated with the following symbols: + create Terraform will perform the following actions: # aws_iam_service_linked_role.autoscaling will be created + resource "aws_iam_service_linked_role" "autoscaling" { + arn = (known after apply) + aws_service_name = "autoscaling.amazonaws.com" + create_date = (known after apply) + custom_suffix = "something" + description = "A service linked role for autoscaling" + id = (known after apply) + name = (known after apply) + path = (known after apply) + unique_id = (known after apply) } # module.example.aws_autoscaling_group.this[0] will be created + resource "aws_autoscaling_group" "this" { + arn = (known after apply) + availability_zones = (known after apply) + default_cooldown = 300 + desired_capacity = 1 + enabled_metrics = [ + "GroupDesiredCapacity", + "GroupInServiceInstances", + "GroupMaxSize", + "GroupMinSize", + "GroupPendingInstances", + "GroupStandbyInstances", + "GroupTerminatingInstances", + "GroupTotalInstances", ] + force_delete = false + health_check_grace_period = 300 + health_check_type = "EC2" + id = (known after apply) + launch_configuration = (known after apply) + max_instance_lifetime = 0 + max_size = 1 + metrics_granularity = "1Minute" + min_elb_capacity = 0 + min_size = 0 + name = (known after apply) + name_prefix = (known after apply) + protect_from_scale_in = false + service_linked_role_arn = (known after apply) + termination_policies = [ + "Default", ] + vpc_zone_identifier = [ + "subnet-3f149576", + "subnet-8cd317d7", + "subnet-908e36f7", ] + wait_for_capacity_timeout = "0" + instance_refresh { + strategy = "Rolling" + triggers = [ + "tag", ] + preferences { + min_healthy_percentage = 50 } } + tag { + key = "Environment" + propagate_at_launch = true + value = "dev" } + tag { + key = "Name" + propagate_at_launch = true + value = "example-with-ec2" } + tag { + key = "Project" + propagate_at_launch = true + value = "megasecret" } + tag { + key = "bar" + propagate_at_launch = true } + tag { + key = "extra_tag1" + propagate_at_launch = true + value = "extra_value1" } + tag { + key = "extra_tag2" + propagate_at_launch = true + value = "extra_value2" } + tag { + key = "foo" + propagate_at_launch = true } } # module.example.aws_launch_configuration.this[0] will be created + resource "aws_launch_configuration" "this" { + arn = (known after apply) + associate_public_ip_address = true + ebs_optimized = false + enable_monitoring = true + id = (known after apply) + image_id = "ami-0717dc2c13076628f" + instance_type = "t2.micro" + key_name = (known after apply) + name = (known after apply) + name_prefix = "example-lc-" + placement_tenancy = "default" + security_groups = [ + "sg-5782022f", ] + user_data_base64 = "IyEvYmluL2Jhc2gKZWNobyAiSGVsbG8gVGVycmFmb3JtISIK" + ebs_block_device { + delete_on_termination = true + device_name = "/dev/xvdz" + encrypted = (known after apply) + iops = (known after apply) + snapshot_id = (known after apply) + volume_size = 50 + volume_type = "gp2" } + metadata_options { + http_endpoint = (known after apply) + http_put_response_hop_limit = (known after apply) + http_tokens = (known after apply) } + root_block_device { + delete_on_termination = true + encrypted = (known after apply) + iops = (known after apply) + volume_size = 50 + volume_type = "gp2" } } # module.example.null_resource.tags_as_list_of_maps[0] will be created + resource "null_resource" "tags_as_list_of_maps" { + id = (known after apply) + triggers = { + "key" = "extra_tag1" + "propagate_at_launch" = "true" + "value" = "extra_value1" } } # module.example.null_resource.tags_as_list_of_maps[1] will be created + resource "null_resource" "tags_as_list_of_maps" { + id = (known after apply) + triggers = { + "key" = "extra_tag2" + "propagate_at_launch" = "true" + "value" = "extra_value2" } } # module.example.random_pet.asg_name[0] will be created + resource "random_pet" "asg_name" { + id = (known after apply) + keepers = (known after apply) + length = 2 + separator = "-" } Plan: 6 to add, 0 to change, 0 to destroy. ------------------------------------------------------------------------ Note: You didn't specify an "-out" parameter to save this plan, so Terraform can't guarantee that exactly these actions will be performed if "terraform apply" is subsequently run. ```
github-actions[bot] commented 1 year ago

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.