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

Reapply changes to avoid destroying instance on user_data updates #18043

Merged
merged 3 commits into from
Feb 18, 2022

Conversation

rogerhu
Copy link
Contributor

@rogerhu rogerhu commented Mar 11, 2021

Community Note

Reapplying changes from #16011 to address #23

This change will update user_data/user_data_base64 and reboot the instance instead of destroying the instance.

The code that deals with shutting down the instance and updating the attributes is consolidated into one function.

Relates to #16011 and #7863
Closes #23

Output from acceptance testing:

$ make testacc TESTARGS='-run=TestAccAWSInstance_userDataChange'

TF_ACC=1 go test ./aws -v -count 1 -parallel 20 -run=TestAccAWSInstance_userDataChange -timeout 120m
=== RUN   TestAccAWSInstance_userDataChange
=== PAUSE TestAccAWSInstance_userDataChange
=== CONT  TestAccAWSInstance_userDataChange
--- PASS: TestAccAWSInstance_userDataChange (234.00s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	235.562s

@rogerhu rogerhu requested a review from a team as a code owner March 11, 2021 06:17
@ghost ghost added size/L Managed by automation to categorize the size of a PR. service/ec2 Issues and PRs that pertain to the ec2 service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels Mar 11, 2021
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Mar 11, 2021
@rogerhu
Copy link
Contributor Author

rogerhu commented Mar 30, 2021

Can someone take a look?

@rogerhu
Copy link
Contributor Author

rogerhu commented Apr 10, 2021

Checking in again :)

@rogerhu
Copy link
Contributor Author

rogerhu commented Apr 24, 2021

Ping again. :). Anyone home?

@rogerhu
Copy link
Contributor Author

rogerhu commented Apr 24, 2021

@anGie44 @bflad @YakDriver if you have a chance

@korenlev
Copy link

korenlev commented Aug 9, 2021

please take a look at this PR , waiting long time for this

@nsvijay04b1
Copy link

Hello..

when can we expect this ? thanks!

@breathingdust breathingdust added enhancement Requests to existing resources that expand the functionality or scope. and removed needs-triage Waiting for first response or review from a maintainer. labels Sep 8, 2021
@GoodMirek
Copy link

@bflad @YakDriver @hashicorp-cloud Any chance to review this enhacement?
The related issue and its predecessor have been opened for over 6 years, since 2015. Justification for this enhacement is e.g. in this comment.

@ricardo-aspira
Copy link

Hello @ewbankkit,
Isn't it a good feature that we could release for the community?
I have seen a couple of use cases with our customers.

Thanks for your time.

@zhelding
Copy link
Contributor

Pull request #21306 has significantly refactored the AWS Provider codebase. As a result, most PRs opened prior to the refactor now have merge conflicts that must be resolved before proceeding.

Specifically, PR #21306 relocated the code for all AWS resources and data sources from a single aws directory to a large number of separate directories in internal/service, each corresponding to a particular AWS service. This separation of code has also allowed for us to simplify the names of underlying functions -- while still avoiding namespace collisions.

We recognize that many pull requests have been open for some time without yet being addressed by our maintainers. Therefore, we want to make it clear that resolving these conflicts in no way affects the prioritization of a particular pull request. Once a pull request has been prioritized for review, the necessary changes will be made by a maintainer -- either directly or in collaboration with the pull request author.

For a more complete description of this refactor, including examples of how old filepaths and function names correspond to their new counterparts: please refer to issue #20000.

For a quick guide on how to amend your pull request to resolve the merge conflicts resulting from this refactor and bring it in line with our new code patterns: please refer to our Service Package Refactor Pull Request Guide.

@anGie44
Copy link
Contributor

anGie44 commented Feb 18, 2022

Hi @rogerhu, thank you for your contribution and continuing the work in #7863. I'll be reviewing this PR and before getting started i'll rebase this if the Allow Maintainer Edits checkbox is checked.

@anGie44 anGie44 force-pushed the rogerh/ec2-instance-userdata-update2 branch 3 times, most recently from 683de20 to 4137c27 Compare February 18, 2022 04:28
@@ -1719,12 +1680,86 @@ func resourceInstanceUpdate(d *schema.ResourceData, meta interface{}) error {
}
}

if shouldStopInstanceForUpdate {
Copy link
Contributor

Choose a reason for hiding this comment

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

unfortunately we'll need to update attributes individually as the API will return an error such as

InvalidParameterCombination: Fields for multiple attribute types specified: instanceType,userData

@github-actions github-actions bot added size/XL Managed by automation to categorize the size of a PR. and removed size/L Managed by automation to categorize the size of a PR. labels Feb 18, 2022
@anGie44 anGie44 force-pushed the rogerh/ec2-instance-userdata-update2 branch from 050fe62 to 05903dd Compare February 18, 2022 06:10
@anGie44 anGie44 force-pushed the rogerh/ec2-instance-userdata-update2 branch from 05903dd to e53957f Compare February 18, 2022 06:23
@anGie44 anGie44 force-pushed the rogerh/ec2-instance-userdata-update2 branch from e53957f to d4fee8f Compare February 18, 2022 06:29
@anGie44
Copy link
Contributor

anGie44 commented Feb 18, 2022

Output of acceptance tests:

--- PASS: TestAccEC2Instance_userDataBase64 (103.52s)
--- PASS: TestAccEC2Instance_userDataBase64_update (287.10s)

--- PASS: TestAccEC2Instance_UserData (103.57s)
--- PASS: TestAccEC2Instance_UserData_emptyStringToUnspecified (129.45s)
--- PASS: TestAccEC2Instance_UserData_unspecifiedToEmptyString (139.80s)
--- PASS: TestAccEC2Instance_UserData_update (186.83s)

--- PASS: TestAccEC2Instance_changeInstanceType (338.25s)
--- PASS: TestAccEC2Instance_changeInstanceTypeAndUserData (267.82s)
--- PASS: TestAccEC2Instance_changeInstanceTypeAndUserDataBase64 (244.71s)

Copy link
Contributor

@anGie44 anGie44 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 again @rogerhu , LGTM 🚀

@anGie44 anGie44 added this to the v4.2.0 milestone Feb 18, 2022
@anGie44 anGie44 merged commit 4ebef08 into hashicorp:main Feb 18, 2022
anGie44 added a commit that referenced this pull request Feb 18, 2022
…-instance-args

docs/ec2/instance: add stop/start behavior related to changes in #18043
@github-actions
Copy link

This functionality has been released in v4.2.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@danorchard82
Copy link

Is there a way to opt-out of this behavior change? I (as I'm sure many) have been relying on instances being destroyed/created when the user data changes, to result in an instance with the given user data executed. This is a breaking change to me.

@v4de
Copy link

v4de commented Mar 8, 2022

This is causing tons of problems in our CI/CD pipelines where changes in user data are NOT forcing a replacement. This change should be only for people that do NOT have idempotent infrastructure and should be a FLAG. @anGie44 @rogerhu

This issue has been opened and the workaround is to use an older version of this provider. #23315

@github-actions
Copy link

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 May 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/ec2 Issues and PRs that pertain to the ec2 service. size/XL 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.

Feature Request: Stop, don't destroy instance on user-data update
10 participants