Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: Use launch_template_id instead of launch_template_name, raise MSV of AWS provider and Terraform to 5.0 and 1.0 respectively #204

Merged
merged 10 commits into from
Oct 9, 2023

Conversation

dhoppe
Copy link
Contributor

@dhoppe dhoppe commented Aug 17, 2022

Description

  • launch_template_id is used in place of launch_template_name. If using an external launch template, you will need to now pass a launch_template_id instead of launch_template_name
  • Minimum supported version of AWS provider raised to v5.0 and Terraform raised to v1.0
  • Previously scaling_policies step_adjustment argument accepted a single map and has since changed to accept multiple maps of scaling step adjustments

In case the value of launch_template_name changes, a new launch template will be created but the auto scaling group still points to the old launch template.

If you execute terraform apply a second time, the auto scaling group tries to change the name of the launch template, but keeps the id of the old launch template which is not valid anymore.

Using the launch_template_id instead of launch_template_name everything is working as expected.

Motivation and Context

Breaking Changes

  • Yes;
    • launch_template_id is used in place of launch_template_name. If using an external launch template, you will need to now pass a launch_template_id instead of launch_template_name
    • Minimum supported version of AWS provider raised to v5.0 and Terraform raised to v1.0
    • Previously scaling_policies step_adjustment argument accepted a single map and has since changed to accept multiple maps of scaling step adjustments

How Has This Been Tested?

  • I have updated at least one of the examples/* to demonstrate and validate my change(s)
  • I have tested and validated these changes using one or more of the provided examples/* projects
  • I have executed pre-commit run -a on my pull request

@dhoppe dhoppe changed the title Use launch_template_id instead of launch_template_name fix: Use launch_template_id instead of launch_template_name Aug 17, 2022
@dhoppe dhoppe force-pushed the launch_template_name branch from 08c537d to 8e4561a Compare September 1, 2022 09:40
@dhoppe
Copy link
Contributor Author

dhoppe commented Sep 1, 2022

@antonbabenko What do you think about this fix?

@antonbabenko
Copy link
Member

@bryantbiggs WDYT?

@bryantbiggs
Copy link
Member

it seems valid - I haven't had a chance to test before/after change to see if that introduces any interruption to current launch templates (i.e. - breaking change)

main.tf Outdated Show resolved Hide resolved
@dhoppe
Copy link
Contributor Author

dhoppe commented Sep 16, 2022

I am back from vacation and ran a few tests.

Create Auto Scaling Group based on version 6.5.2:

...
  # aws_autoscaling_group.this[0] will be created
  + resource "aws_autoscaling_group" "this" {
      + arn                       = (known after apply)
      + availability_zones        = (known after apply)
      + default_cooldown          = (known after apply)
      + desired_capacity          = 1
      + enabled_metrics           = [
          + "GroupDesiredCapacity",
          + "GroupInServiceInstances",
          + "GroupMaxSize",
          + "GroupMinSize",
          + "GroupPendingInstances",
          + "GroupStandbyInstances",
          + "GroupTerminatingInstances",
          + "GroupTotalInstances",
        ]
      + force_delete              = false
      + force_delete_warm_pool    = false
      + health_check_grace_period = 300
      + health_check_type         = (known after apply)
      + id                        = (known after apply)
      + max_size                  = 2
      + metrics_granularity       = "1Minute"
      + min_size                  = 1
      + name                      = "example-dev"
      + name_prefix               = (known after apply)
      + protect_from_scale_in     = false
      + service_linked_role_arn   = (known after apply)
      + termination_policies      = [
          + "OldestInstance",
          + "OldestLaunchTemplate",
        ]
      + vpc_zone_identifier       = [
          + "subnet-010d8727ed0731858",
          + "subnet-0277536173302342b",
          + "subnet-061b8068f8143f3cd",
        ]
      + wait_for_capacity_timeout = "10m"

      + instance_refresh {
          + strategy = "Rolling"
          + triggers = [
              + "tag",
            ]

          + preferences {
              + min_healthy_percentage = 90
              + skip_matching          = false
            }
        }

      + launch_template {
          + id      = (known after apply)
          + name    = "1st-example-dev"
          + version = "$Latest"
        }

      + tag {
          + key                 = "Contact"
          + propagate_at_launch = true
          + value               = "Dennis Hoppe"
        }
      + tag {
          + key                 = "Environment"
          + propagate_at_launch = true
          + value               = "dev"
        }
      + tag {
          + key                 = "Name"
          + propagate_at_launch = true
          + value               = "example-dev"
        }
      + tag {
          + key                 = "Project"
          + propagate_at_launch = true
          + value               = "Atlassian"
        }

      + timeouts {}
    }
...
  # aws_launch_template.this[0] will be created
  + resource "aws_launch_template" "this" {
      + arn                    = (known after apply)
      + default_version        = (known after apply)
      + id                     = (known after apply)
      + image_id               = "ami-096800910c1b781ba"
      + instance_type          = "t3.medium"
      + key_name               = "atlassian-dev"
      + latest_version         = (known after apply)
      + name                   = "1st-example-dev"
      + name_prefix            = (known after apply)
      + tags                   = {
          + "Contact"     = "Dennis Hoppe"
          + "Environment" = "dev"
          + "Project"     = "Atlassian"
        }
      + tags_all               = {
          + "Contact"     = "Dennis Hoppe"
          + "Environment" = "dev"
          + "Project"     = "Atlassian"
        }
      + update_default_version = true
      + user_data              = "IyEvdXNyL2Jpbi9lbnYgYmFzaAphcHQgdXBkYXRlCmFwdCBpbnN0YWxsIC15IG5naW54CgpJTlNUQU5DRV9JRD1gY3VybCBodHRwOi8vMTY5LjI1NC4xNjkuMjU0L2xhdGVzdC9tZXRhLWRhdGEvaW5zdGFuY2UtaWRgCnNlZCAtaSAicy9uZ2lueFwhL25naW54XCEgKCRJTlNUQU5DRV9JRCkvZyIgL3Zhci93d3cvaHRtbC9pbmRleC5uZ2lueC1kZWJpYW4uaHRtbAoKc3lzdGVtY3RsIGVuYWJsZSBuZ2lueApzeXN0ZW1jdGwgc3RhcnQgbmdpbngK"
      + vpc_security_group_ids = [
          + "sg-0b0a601122357afe3",
        ]

      + block_device_mappings {
          + device_name = "/dev/sda1"
          + no_device   = "0"

          + ebs {
              + delete_on_termination = "true"
              + encrypted             = "true"
              + iops                  = (known after apply)
              + throughput            = (known after apply)
              + volume_size           = 80
              + volume_type           = "gp3"
            }
        }
      + block_device_mappings {
          + device_name = "/dev/xvdf"
          + no_device   = "1"

          + ebs {
              + delete_on_termination = "true"
              + encrypted             = "true"
              + iops                  = (known after apply)
              + throughput            = (known after apply)
              + volume_size           = 200
              + volume_type           = "gp3"
            }
        }

      + iam_instance_profile {
          + arn  = (known after apply)
          + name = (known after apply)
        }

      + metadata_options {
          + http_endpoint               = (known after apply)
          + http_protocol_ipv6          = (known after apply)
          + http_put_response_hop_limit = (known after apply)
          + http_tokens                 = (known after apply)
          + instance_metadata_tags      = (known after apply)
        }

      + monitoring {
          + enabled = true
        }
    }
...

1st_asg

1st_lt

Change name of Launch Template based on version 6.5.2:

...
  # aws_autoscaling_group.this[0] will be updated in-place
  ~ resource "aws_autoscaling_group" "this" {
        id                        = "example-dev"
        name                      = "example-dev"
        # (23 unchanged attributes hidden)

      ~ launch_template {
            id      = "lt-08331c40be1bda486"
          ~ name    = "1st-example-dev" -> "2nd-example-dev"
            # (1 unchanged attribute hidden)
        }

        # (6 unchanged blocks hidden)
    }
...
  # aws_launch_template.this[0] must be replaced
+/- resource "aws_launch_template" "this" {
      ~ arn                     = "arn:aws:ec2:eu-west-1:590606209411:launch-template/lt-08331c40be1bda486" -> (known after apply)
      ~ default_version         = 1 -> (known after apply)
      - disable_api_stop        = false -> null
      - disable_api_termination = false -> null
      ~ id                      = "lt-08331c40be1bda486" -> (known after apply)
      ~ latest_version          = 1 -> (known after apply)
      ~ name                    = "1st-example-dev" -> "2nd-example-dev" # forces replacement
      + name_prefix             = (known after apply)
      - security_group_names    = [] -> null
        tags                    = {
            "Contact"     = "Dennis Hoppe"
            "Environment" = "dev"
            "Project"     = "Atlassian"
        }
        # (7 unchanged attributes hidden)

      ~ block_device_mappings {
            # (2 unchanged attributes hidden)

          ~ ebs {
              ~ iops                  = 0 -> (known after apply)
              ~ throughput            = 0 -> (known after apply)
                # (4 unchanged attributes hidden)
            }
        }
      ~ block_device_mappings {
            # (2 unchanged attributes hidden)

          ~ ebs {
              ~ iops                  = 0 -> (known after apply)
              ~ throughput            = 0 -> (known after apply)
                # (4 unchanged attributes hidden)
            }
        }

      ~ iam_instance_profile {
            # (1 unchanged attribute hidden)
        }

      + metadata_options {
          + http_endpoint               = (known after apply)
          + http_protocol_ipv6          = (known after apply)
          + http_put_response_hop_limit = (known after apply)
          + http_tokens                 = (known after apply)
          + instance_metadata_tags      = (known after apply)
        }

        # (1 unchanged block hidden)
    }
...

2nd_asg

2nd_asg_activity

2nd_lt

Change name of Launch Template (Error) based on version 6.5.2:

...
  # aws_autoscaling_group.this[0] will be updated in-place
  ~ resource "aws_autoscaling_group" "this" {
        id                        = "example-dev"
        name                      = "example-dev"
        # (23 unchanged attributes hidden)

      ~ launch_template {
            id      = "lt-08331c40be1bda486"
          ~ name    = "1st-example-dev" -> "2nd-example-dev"
            # (1 unchanged attribute hidden)
        }

        # (6 unchanged blocks hidden)
    }
...

3rd_asg

Change name of Launch Template (Success) based on branch launch_template_name:

...
  # aws_autoscaling_group.this[0] will be updated in-place
  ~ resource "aws_autoscaling_group" "this" {
        id                        = "example-dev"
        name                      = "example-dev"
        # (23 unchanged attributes hidden)

      ~ launch_template {
          ~ id      = "lt-08331c40be1bda486" -> "lt-044be7e5004489352"
            name    = "1st-example-dev"
            # (1 unchanged attribute hidden)
        }

        # (6 unchanged blocks hidden)
    }
...

4th_asg

4th_lt

As you can see, the pull request works as expected. Even if the diff still shows the old name of the launch template, the output has been updated accordingly.

Outputs:

autoscaling_group_arn = "arn:aws:autoscaling:eu-west-1:590606209411:autoScalingGroup:b1f8d5a5-d5f1-4f5e-a2d9-666e9b355511:autoScalingGroupName/example-dev"
autoscaling_group_availability_zones = toset([
  "eu-west-1a",
  "eu-west-1b",
  "eu-west-1c",
])
autoscaling_group_default_cooldown = 300
autoscaling_group_desired_capacity = 1
autoscaling_group_enabled_metrics = toset([
  "GroupDesiredCapacity",
  "GroupInServiceInstances",
  "GroupMaxSize",
  "GroupMinSize",
  "GroupPendingInstances",
  "GroupStandbyInstances",
  "GroupTerminatingInstances",
  "GroupTotalInstances",
])
autoscaling_group_health_check_grace_period = 300
autoscaling_group_health_check_type = "EC2"
autoscaling_group_id = "example-dev"
autoscaling_group_load_balancers = toset([])
autoscaling_group_max_size = 2
autoscaling_group_min_size = 1
autoscaling_group_name = "example-dev"
autoscaling_group_target_group_arns = toset([])
autoscaling_group_vpc_zone_identifier = toset([
  "subnet-010d8727ed0731858",
  "subnet-0277536173302342b",
  "subnet-061b8068f8143f3cd",
])
autoscaling_policy_arns = {}
autoscaling_schedule_arns = {}
iam_instance_profile_arn = "arn:aws:iam::590606209411:instance-profile/ec2/example-dev"
iam_instance_profile_id = "example-dev"
iam_instance_profile_unique = "AIPAYTAW7SGBXFX47HQPG"
iam_role_arn = "arn:aws:iam::590606209411:role/ec2/example-dev"
iam_role_name = "example-dev"
iam_role_unique_id = "AROAYTAW7SGBZFQYKY3SJ"
launch_template_arn = "arn:aws:ec2:eu-west-1:590606209411:launch-template/lt-044be7e5004489352"
launch_template_default_version = 1
launch_template_id = "lt-044be7e5004489352"
launch_template_latest_version = 1
launch_template_name = "2nd-example-dev"

@dhoppe dhoppe requested review from antonbabenko and removed request for bryantbiggs September 16, 2022 11:42
@dhoppe dhoppe force-pushed the launch_template_name branch from 8e4561a to c5cfa97 Compare September 16, 2022 14:23
@dhoppe dhoppe force-pushed the launch_template_name branch from c5cfa97 to adbc394 Compare September 16, 2022 14:46
@dhoppe dhoppe requested review from bryantbiggs and antonbabenko and removed request for antonbabenko and bryantbiggs September 16, 2022 15:48
Copy link
Member

@antonbabenko antonbabenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not spent a significant amount of time reading and thinking about this PR, but I have a few comments:

  1. Changes to variables like rename are breaking changes that we should try to avoid.
  2. If necessary, we can use data-source aws_launch_template to get ID from the name (just as an idea).
  3. We can add another variable and mark existing as deprecated so that we remove it during the next more significant update.
  4. It is ok to have 4 y.o. kid learning more about AWS/Terraform. Don't ask how I know about it :)

@dhoppe
Copy link
Contributor Author

dhoppe commented Sep 16, 2022

@antonbabenko I really tried to avoid introducing breaking changes, but right now I am out of ideas.

The resource aws_autoscaling_group only allows the argument launch_template_id or launch_template_name. In that case adding an additional local variable does not help.

I also tried to use the data source aws_launch_template, but there are examples which do not provide a value for var.launch_template which causes an error message.

I do not know how common it is for someone to change the name of a launch template or not manage the launch template with this Terraform module, but in the end this is a bug.

I wonder how long it will take for your kid to work on the first Issues / Pull Requests. I am pretty sure you can use all the help you can get ;)

@github-actions
Copy link

This PR has been automatically marked as stale because it has been open 30 days
with no activity. Remove stale label or comment or this PR will be closed in 10 days

@bryantbiggs bryantbiggs changed the title fix: Use launch_template_id instead of launch_template_name feat!: Use launch_template_id instead of launch_template_name, raise MSV of AWS provider and Terraform to 5.0 and 1.0 respectively Oct 9, 2023
Copy link
Member

@bryantbiggs bryantbiggs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for your patience!

@bryantbiggs bryantbiggs merged commit 1d988c0 into terraform-aws-modules:master Oct 9, 2023
8 checks passed
@antonbabenko
Copy link
Member

This PR is included in version 7.0.0 🎉

antonbabenko pushed a commit that referenced this pull request Oct 9, 2023
## [7.0.0](v6.10.0...v7.0.0) (2023-10-09)

### ⚠ BREAKING CHANGES

* Use `launch_template_id` instead of `launch_template_name`, raise MSV of AWS provider and Terraform to 5.0 and 1.0 respectively (#204)

### Features

* Use `launch_template_id` instead of `launch_template_name`, raise MSV of AWS provider and Terraform to 5.0 and 1.0 respectively ([#204](#204)) ([1d988c0](1d988c0))
Copy link

github-actions bot commented Nov 9, 2023

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants