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

New resource: aws_autoscaling_instance_refresh #14442

Closed

Conversation

roberth-k
Copy link
Contributor

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request

Closes #13785

Supersedes #13791. Representing Instance Refresh as a separate resource enables
consistent failure behaviour when waiting for refresh completion.

The aws_autoscaling_instance_refresh block includes a triggers block, which
allows additional flexibility. The default recommendation is to use the new
instance_refresh_token token attribute of the auto-scaling group, which changes
every time the ASG is modified in a way that would warrant a refresh (e.g. new
launch template or VPC configuration).

Example:

resource "aws_launch_configuration" "test" {
  image_id      = "ami-123456789"
  instance_type = "t2.micro"
}

resource "aws_autoscaling_group" "test" {
  availability_zones   = ["us-west-2"]
  min_size             = 1
  max_size             = 2
  launch_configuration = aws_launch_configuration.test.name
}

resource "aws_autoscaling_instance_refresh" "test" {
  autoscaling_group_name  = aws_autoscaling_group.test.name
  min_healthy_percentage  = 50
  instance_warmup_seconds = 5
  strategy                = "Rolling"

  triggers = {
    token = aws_autoscaling_group.test.instance_refresh_token
  }
}

Release note for CHANGELOG:

FEATURES:
- **New Resource:** `aws_autoscaling_instance_refresh`

ENHANCEMENTS:
- resource/aws_autoscaling_group: Add `instance_refresh_token` attribute

Output from acceptance testing:

$ clear && make testacc TESTARGS='-run=TestAccAWSAutoscalingInstanceRefresh_'
==> Checking that code complies with gofmt requirements...
--- PASS: TestAccAWSAutoscalingInstanceRefresh_alreadyOngoing (143.95s)
--- PASS: TestAccAWSAutoscalingInstanceRefresh_cancelOnTimeout (160.09s)
--- PASS: TestAccAWSAutoscalingInstanceRefresh_basic (346.45s)
--- PASS: TestAccAWSAutoscalingInstanceRefresh_disappears (348.04s)
PASS
ok      github.com/terraform-providers/terraform-provider-aws/aws       349.391s

$ make testacc TESTARGS='-run=TestAccAWSAutoScalingGroup_'
==> Checking that code complies with gofmt requirements...
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_LaunchTemplate_Override_WeightedCapacity (146.81s)
--- PASS: TestAccAWSAutoScalingGroup_basic (231.18s)
--- PASS: TestAccAWSAutoScalingGroup_InstanceRefresh_Triggers (267.39s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_LaunchTemplate_Override_InstanceType (43.81s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_LaunchTemplate_LaunchTemplateSpecification_Version (44.19s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_LaunchTemplate_LaunchTemplateSpecification_LaunchTemplateName (42.14s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstancesDistribution_SpotMaxPrice (45.88s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstancesDistribution_SpotInstancePools (44.02s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstancesDistribution_SpotAllocationStrategy (42.42s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstancesDistribution_OnDemandPercentageAboveBaseCapacity (44.06s)
--- PASS: TestAccAWSAutoScalingGroup_ALB_TargetGroups_ELBCapacity (290.56s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstancesDistribution_UpdateToZeroOnDemandBaseCapacity (43.24s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstancesDistribution_OnDemandBaseCapacity (41.67s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstancesDistribution_OnDemandAllocationStrategy (41.97s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy (42.13s)
--- PASS: TestAccAWSAutoScalingGroup_LaunchTemplate_IAMInstanceProfile (56.35s)
--- PASS: TestAccAWSAutoScalingGroup_launchTemplate_update (82.41s)
--- PASS: TestAccAWSAutoScalingGroup_classicVpcZoneIdentifier (55.51s)
--- PASS: TestAccAWSAutoScalingGroup_launchTemplate (44.47s)
--- PASS: TestAccAWSAutoScalingGroup_launchTempPartitionNum (44.54s)
--- PASS: TestAccAWSAutoScalingGroup_enablingMetrics (140.59s)
--- PASS: TestAccAWSAutoScalingGroup_initialLifecycleHook (187.04s)
--- PASS: TestAccAWSAutoScalingGroup_TargetGroupArns (180.74s)
--- PASS: TestAccAWSAutoScalingGroup_ALB_TargetGroups (112.25s)
--- PASS: TestAccAWSAutoScalingGroup_MaxInstanceLifetime (44.74s)
--- PASS: TestAccAWSAutoScalingGroup_serviceLinkedRoleARN (50.89s)
--- PASS: TestAccAWSAutoScalingGroup_withMetrics (43.21s)
--- PASS: TestAccAWSAutoScalingGroup_VpcUpdates (48.13s)
--- PASS: TestAccAWSAutoScalingGroup_LoadBalancers (663.40s)
--- PASS: TestAccAWSAutoScalingGroup_suspendingProcesses (170.76s)
--- PASS: TestAccAWSAutoScalingGroup_withPlacementGroup (129.83s)
--- PASS: TestAccAWSAutoScalingGroup_terminationPolicies (70.89s)
--- PASS: TestAccAWSAutoScalingGroup_tags (199.31s)
--- PASS: TestAccAWSAutoScalingGroup_WithLoadBalancer (303.30s)
--- PASS: TestAccAWSAutoScalingGroup_WithLoadBalancer_ToTargetGroup (363.79s)
--- PASS: TestAccAWSAutoScalingGroup_autoGeneratedName (41.13s)
--- PASS: TestAccAWSAutoScalingGroup_namePrefix (51.76s)
PASS
ok      github.com/terraform-providers/terraform-provider-aws/aws       1500.890s

@roberth-k roberth-k requested a review from a team July 31, 2020 22:45
@ghost ghost added size/XXL Managed by automation to categorize the size of a PR. needs-triage Waiting for first response or review from a maintainer. provider Pertains to the provider itself, rather than any interaction with AWS. service/autoscaling Issues and PRs that pertain to the autoscaling service. documentation Introduces or discusses updates to documentation. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels Jul 31, 2020
@jamroks
Copy link

jamroks commented Aug 14, 2020

Hi, would be great to have this merge , since I don't see anything blocking it technically speaking , maybe I'm missing something .

thanks for the work on this @roberth-k

@teamterraform
Copy link

Notification of Recent and Upcoming Changes to Contributions

Thank you for this contribution! There have been a few recent development changes that affect this pull request. We apologize for the inconvenience, especially if there have been long review delays up until now. Please note that this is automated message from an unmonitored account. See the FAQ for additional information on the maintainer team and review prioritization.

If you are unable to complete these updates, please leave a comment for the community and maintainers so someone can potentially continue the work. The maintainers will encourage other contributors to use the existing contribution as the base for additional changes as appropriate. Otherwise, contributions that do not receive updated code or comments from the original contributor may be closed in the future so the maintainers can focus on active items.

For the most up to date information about Terraform AWS Provider development, see the Contributing Guide. Additional technical debt changes can be tracked with the technical-debt label on issues.

As part of updating a pull request with these changes, the most current unit testing and linting will run. These may report issues that were not previously reported.

Terraform 0.12 Syntax

Reference: #8950
Reference: #14417

Version 3 and later of the Terraform AWS Provider, which all existing contributions would potentially be added, only supports Terraform 0.12 and later. Certain syntax elements of Terraform 0.11 and earlier show deprecation warnings during runs with Terraform 0.12. Documentation and test configurations, such as those including deprecated string interpolations (some_attribute = "${aws_service_thing.example.id}") should be updated to the newer syntax (some_attribute = aws_service_thing.example.id). Contribution testing will automatically fail on older syntax in the near future. Please see the referenced issues for additional information.

Action Required: Terraform Plugin SDK Version 2

Reference: #14551

The Terraform AWS Provider has been upgraded to the latest version of the Terraform Plugin SDK. Generally, most changes to contributions should only involve updating Go import paths in source code files. Please see the referenced issue for additional information.

Action Required: Removal of website/aws.erb File

Reference: #14712

Any changes to the website/aws.erb file are no longer necessary and should be removed from this contribution to prevent merge issues in the near future when the file is removed from the repository. Please see the referenced issue for additional information.

Upcoming Change of Git Branch Naming

Reference: #14292

Development environments will need their upstream Git branch updated from master to main in the near future. Please see the referenced issue for additional information and scheduling.

Upcoming Change of GitHub Organization

Reference: #14715

This repository will be migrating from https://github.com/terraform-providers/terraform-provider-aws to https://github.com/hashicorp/terraform-provider-aws. No practitioner or developer action is anticipated and most GitHub functionality will automatically redirect to the new location. Go import paths including terraform-providers can remain for now. Please see the referenced issue for additional information and scheduling.

@roberth-k roberth-k force-pushed the f-aws_autoscaling_instance_refresh branch from 9fcb0c2 to ba8135e Compare August 22, 2020 10:01
@ghost ghost added service/cognito dependencies Used to indicate dependency changes. labels Aug 22, 2020
@roberth-k roberth-k force-pushed the f-aws_autoscaling_instance_refresh branch from ba8135e to 5004831 Compare August 22, 2020 10:03
@ghost
Copy link

ghost commented Aug 22, 2020

Hello, and thank you for your contribution!

This project recently upgraded to V2 of the Terraform Plugin SDK

This pull request appears to include at least one V1 import path of the SDK ("github.com/hashicorp/terraform-plugin-sdk/helper/resource"). Please import the V2 path github.com/hashicorp/terraform-plugin-sdk/v2/helper/PACKAGE

To resolve this situation without losing any existing work, you may be able to Git rebase your branch against the current master branch (example below); replacing any remaining old import paths with the newer ones.

$ git fetch --all
$ git rebase origin/master

Another option is to create a new branch from the current master with the same code changes (replacing the import paths), submit a new pull request, and close this existing pull request.

We apologize for this inconvenience and appreciate your effort. Thank you for contributing and helping make the Terraform AWS Provider better for everyone.

@roberth-k roberth-k force-pushed the f-aws_autoscaling_instance_refresh branch from 5004831 to 4e09c3f Compare August 22, 2020 10:13
@sanspace
Copy link

Would this one ever get merged!? 😨

@brewkode
Copy link

Does someone know when this will be merged ?

@roberth-k roberth-k force-pushed the f-aws_autoscaling_instance_refresh branch from 4e09c3f to fe0f39b Compare September 15, 2020 19:40
@roberth-k roberth-k force-pushed the f-aws_autoscaling_instance_refresh branch from fe0f39b to 6e1894c Compare September 15, 2020 22:25
@gdavison
Copy link
Contributor

Hi @roberth-k, thanks for the two PRs for this feature. We've been putting a lot of thought into the best way to address instance refresh. I'll follow up with you later this week

@gdavison gdavison removed needs-triage Waiting for first response or review from a maintainer. service/cognito labels Sep 16, 2020
@gdavison gdavison self-assigned this Sep 17, 2020
@ishworg
Copy link

ishworg commented Sep 18, 2020

I feel like a lot of folks out there (including myself) are waiting on this pull request to land on a release for a while now.
Here's my two cent how I currently do it using awscli:

docker run --rm \
    -e AWS_ACCESS_KEY_ID \
    -e AWS_SECRET_ACCESS_KEY \
    -e AWS_REGION \
    awscli:latest \
      aws --region ${AWS_REGION} \
        autoscaling start-instance-refresh \
        --auto-scaling-group-name "my-${bg_active_stack}" \
        --preferences '{"InstanceWarmup": 600, "MinHealthyPercentage": 90}'

Hope it helps.

@smiller171
Copy link

@gdavison Did that follow-up happen?

Currently we're using CloudFormation (through Terraform) to handle ASGs specifically for these kinds of rolling updates

@bflad bflad removed the dependencies Used to indicate dependency changes. label Oct 2, 2020
@tsalinguepumpkin
Copy link

@gdavison any update on the matter ?

aws_autoscaling_instance_refresh - fix fmt/validate checks
@roberth-k roberth-k requested a review from a team as a code owner November 6, 2020 23:00
@nelg
Copy link

nelg commented Nov 9, 2020

Tested this (compiled and tested locally), works OK for me.

It would be good to get this merged

@nbmustafa
Copy link

any progress here? is it going to be merged anytime soon?

@ghost
Copy link

ghost commented Jan 18, 2021

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Jan 18, 2021
@roberth-k roberth-k deleted the f-aws_autoscaling_instance_refresh branch January 16, 2022 20:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Introduces or discusses updates to documentation. provider Pertains to the provider itself, rather than any interaction with AWS. service/autoscaling Issues and PRs that pertain to the autoscaling service. size/XXL Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support ASG Instance Refresh