-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
aws_instance change to user_data no longer results in a destroy and re-create #23315
Comments
This new lifecycle behaviour also applies to changes to
Workaround: Force a recreate. |
This is likely due to this line 😞 terraform-provider-aws/internal/service/ec2/instance.go Lines 1460 to 1462 in adc1d6a
#23305 may be the correct approach |
@runesl are you able to provide the file content that is causing the error you are seeing? |
Instance user data is most commonly used to run scripts at startup, but there are other cases where it can be used. User data can be retrieved at any time using IMDS (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-add-user-data.html) So we'll need to handle both cases. |
This happens when we (colleague here) base64encode a couple of template files and then add the to the cloud-init file:
|
This change has has significant impact for our automated deployments using terraform within CI/CD. We relied on terraform replacing the instance when it saw a userdata change, so that the new userdata could run when the new instance was launched. |
we have had to pin our cicd pipes to a specific aws provider which behaves as we expect. Wr risk being forced to update due to security concerns. Can we have a resolution to this issue please? Can terraform aws once again terminate and destroy EC2s when user data hash has changed? |
It's nice that you can now update user_data and it not recreate an instance (I can see some use cases for this) but if you relied on the previous behaviour of recreating the instance on user data change there is currently no workaround besides down pinning the provider. Would be nice to be able to specify the behaviour or have some lifecycle workaround like the following hashicorp/terraform#8099 |
We have the same issue of now pinning the provider so that our CI/CD pipelines redeploys our infrastructure. Can we get a fix for this? |
Looks like it reboots instances now, we are trying to roll back to another instance provider currently. #18043 We see in our instance logs that it was rebooted, and the user data was modified, however none of the user data was run on reboot. We rely on this to update and install our packages on our instances. Is there a flag to force new? |
We are planning to work on a solution for this. We plan to add a new argument called The new argument will default to false meaning that users wanting to keep the previous behaviour will need to proactively set this argument. I will update this issue once I have a better idea of a release date. |
"-replace" was always there to force an ec2 instance replacement |
-replace also replaces resources that aren't changed so there's a subtle difference. And for those using something like Atlantis in the pipeline it's a no go. |
This functionality has been released in v4.7.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! |
I agree with @jaredfholgate; this is an unexpected and breaking change. It's not just that it changes existing behavior, it's also that it seems incorrect for the average ( There are definitely valid reasons for allowing user-data changes to not recreate the instance, and it should be supported by terraform. It just doesn't feel like that warrants a change to the default behavior given the average (maybe wrong on this) use case and long history, as people (and tools) have come to expect it. I see there is a proposal to add an |
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. |
Community Note
Terraform CLI and Terraform AWS Provider Version
Affected Resource(s)
Terraform Configuration Files
Please include all Terraform configurations required to reproduce the bug. Bug reports without a functional reproduction may be closed without investigation.
Debug Output
Panic Output
Expected Behavior
Prior to version 4.0.0 a change to the
user_data
argument resulted in the resource being destroyed and recreated.Actual Behavior
The resource is no longer destroyed and recreated when there is a change to
user_data
.Steps to Reproduce
terraform apply
Important Factoids
The docs appear to have been updated to include this line 'Updates to this field will trigger a stop/start of the EC2 instance'.
However there does not appear to be anything in the release notes about this being a breaking change, so thought I should flag it in case it is unintentional. This change causes significant impact on users that expect the previous behaviour. This is particularly the case for Terraform Cloud and Enterprise users with VCS integration who are unable to use the
-replace
command line flag.Given that
user_data
scripts are only run the first time an EC2 instance is deployed, it seemed logical that a change would result in a recreation of the resource, otherwiseuser_data
changes will not be applied which may cause confusion.References
The text was updated successfully, but these errors were encountered: