-
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
[Bug]: aws_iam_role role_last_used has changed outside of Terraform #30861
Comments
Community NoteVoting for Prioritization
Volunteering to Work on This Issue
|
This is a super annoying bug as this will constantly update the terraform state when that role is being used which is constantly... Please give this the proper priority if you can |
Hi there, I am currently working on a fix, PR should be ready to review soon |
@jburgess777 OS Ubuntu 23.04 What I have done
Am I missing something? Is this OS related? |
I can confirm it's happening in one of our projects with Terraform Core 1.1.9. |
Currently experiencing this with terraform version 1.4.6 and provider hashicorp/aws v4.64.0 I don't see these changes when running |
Hello, I also have this problem when running terraform in Github Actions using terraform 1.3.3 and provider hashicorp/aws v4.65.0 Note: Objects have changed outside of Terraform
Terraform detected the following changes made outside of Terraform since the
last "terraform apply" which may have affected this plan:
# module.environment.aws_iam_role.ecs_instance_role has changed
~ resource "aws_iam_role" "ecs_instance_role" {
id = "ecs-instance-role"
name = "ecs-instance-role"
~ role_last_used = [
~ {
~ last_used_date = "2023-05-04T07:49:36Z" -> "2023-05-04T08:49:03Z"
# (1 unchanged element hidden)
},
]
tags = {}
# (9 unchanged attributes hidden)
} |
Hi. I have this issue as well while using https://registry.terraform.io/modules/terraform-aws-modules/eks/aws/latest where the IAM role created constantly shows up as "changed" because of the last used timestamp. Super annoying, and would be great if can be fixed. |
Adding another variant: |
Any updates on the PR to fix this? The issue for me is that it creates a false drift detection in Terraform, it is hard to know if there is an actual problem or just normal usage of the platform. From my understanding this has been fixed in the past and recently came back. |
I haven't been able to reproduce this on the latest version(s) of either terraform and the AWS provider. |
@anthonybouton since it is a field that we cannot update (at least per the documentation) should it be saved in the state? Every time someone uses a role AWS will update that field causing the issue. But I am not very familiar on how providers work, just how to use them :) |
That is what I am attempted to believe, however I am not able to reproduce this, neither on my small repo, or on other client's projects where terraform with the AWS provider is being used heavily. I've taken a look at the code and the required IGNORE attributes seem to be present for this particular attribute. |
@anthonybouton do you think it could be a configuration issue? Like should I add a |
Maybe, we have a similar setup ( using BitBucket instead of GitHub ) and not seeing the issue neither. |
@gabrielrinaldi adding a lifecycle entry did not solve it for me, it just added this sort of ironic warning:
For info I'm using the most recent version of Terraform |
@anthonybouton I am using the latest @sammccants does it happen for all roles for you? |
Regarding Spent some time digging into our various terraform targets, their current plans and when the provider was upgraded, and whether or not they've been applied since. My theory was that some targets had not been applied since the provider was upgraded (our CICD will skip apply if plan has no changes), and applying them once fixes the With this in mind, I checked a couple of more deployment targets, and targets where the state file had not been modified since the provider update and inspected the state file seeing that there is no Hoping this can help some others! I don't know if there's any relation to the issue when not using what I was doing and writing before coming up with ☝🏻In our/my case it is not limited to any specific set of roles as far as I can tell. I have roles used in IAM Roles for Service Accounts, roles used by EC2 instances and datadog integration roles etc. We reuse the same terraform with different variables for multiple environments. Using terraform 1.4.6, and various AWS provider versions .65, .66, .67
For B stg, running Regarding It does indeed show as changes made outside of Terraform each time, which is noisy. But I suppose this is expected. Similar behavior exists in other resources like |
Would someone be able to share their lifecycle policies used to ignore changes to the IAM role As others have mentioned, this causes a lot of false alarms and noise in our Terraform drift detection alerts. |
The below does not appear to work @eduardoasantana, I'd love to know how to ignore it too!
I've also tried just |
Hi everyone - Thanks for your reports, and apologies for any frustration or confusion this addition has caused. To restate my understanding of the issue, the Under the hood, Terraform core is handling what changes are displayed at plan time. A core change introduced in
A previous comment in this thread documents how changes to this computed attribute are correctly hidden in later versions of the Terraform CLI. A similar reproduction on a different computed attribute can be found in this issue comment, which explicitly shows the differences between plan outputs across Terraform CLI versions. In summary, upgrading to Terraform CLI >= Edit: For anyone experiencing plan differences (not just a note about changes outside Terraform on a plan with no changes), or still observing displayed differences on Terraform versions > |
Could you please share the relevant Terraform configuration and plan output? |
see above, there are several references |
Drift detection is a new feature from HashiCorp and all computed values that change show up as drift as the feature is currently implemented. This is something that we've brought up with the team in the past but is currently expected behavior. Have we seen it show up in a later version than 1.2 in a TF plan? |
Which I somewhat understand, thats fundamentally how Terraform works - this is why I raised the question of reverting the changes made in #30750. It doesn't appear that it was a highly requested feature addition and it doesn't fit within the Terraform model. If we know that a computed value, that is not controlled by Terraform, is always going to change and keep changing, why is that a valuable addition to the provider? |
That's a great question. First off, I added it to the provider to use it in the new continuous validation feature from Terraform so we can get notified on unused roles. As far as computed values go, these are all over the place in TF. Oftentimes they don't change (like the AWS generated AROA unique ID for an AWS IAM role as an example), but there are some computed attributes that change frequently (the |
I think thats a bit heavy handed to state - computed values that DO change are most likely changing for a reason and that change will trigger cascading effect to its dependencies (i.e. - if computed value If a value is changing, Terraform will detect that and make it known in the plan/apply - that is the premise of Terraform. I believe you are trying to mix declarative with dynamic/imperative (i.e. - if this happens, do this) and that is not what Terraform was designed for (@apparentlymart please correct me if I am wrong) |
100% agree. In the case that you outline, |
When I first saw this behavior, I obviously thought of it as a feature similar to the detection of external changes in many other resources/attributes. E.g. those who don't want to see it, should be able to ignore that part. However, as @ollytheninja mentioned above, this doesn't work by design for read-only attributes:
After stumbling upon this discussion, I'm more inclined to consider this a "bug" as well for the following reasons:
|
After consideration of community feedback, we've decided to remove the
Please let us know if you have any questions or concerns with this proposed change. Thanks! |
This functionality has been released in v5.1.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'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. |
Terraform Core Version
1.1.4
AWS Provider Version
4.64.0
Affected Resource(s)
Expected Behavior
We expect
role_last_used
to change frequently. The value is not controlled by Terraform so I don't think it should be reported as a change to the resource when generating the plan.Actual Behavior
Relevant Error/Panic Output Snippet
No response
Terraform Configuration Files
It looks like this would appear for any IAM role created by Terraform
Steps to Reproduce
Apply terraform plan which creates an AWS IAM role
Use the role
Might need to wait some time for AWS to update the role usage metadata
Run plan again
Debug Output
No response
Panic Output
No response
Important Factoids
No response
References
role_last_used
is a new feature in the 4.64 release: #30750Would you like to implement a fix?
None
The text was updated successfully, but these errors were encountered: