-
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
IAM eventual consistency race condition for aws_iam_role leaves lambda function in defunct state #3972
Comments
PR submitted to retry on this condition during update (was only present during creation): #3988 |
The fix has been merged into master and will release with v1.14.0 of the AWS provider, in a week most likely. |
Thanks for that @bflad |
It turns out my problem was actually more general than this and related to create_before_destroy not working as expected. It was creating a new dependency (the role), destroying the old one, THEN updating Lambda's reference to it last. This meant that for a while the Lambda function was still referring to an already deleted role. The failure of Lambda to update due to this IAM race condition caused infrastructure changes to halt at this temporarily broken state. This applies more generally than Lambda or even AWS and is an issue with the core engine, that I've lodged as hashicorp/terraform#17735 I agree that the change you have made is a good one and will help in some cases, it just turns out my problem was more general. |
This has been released in version 1.14.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. |
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! |
To ensure continued functioning of my system through changes which require role replacement, I have used create_before_destroy = true with my lambda function lifecycles. However, I have found that in general, changes which require the role to be replaced fail on terraform apply with the error
A second run a short time later it succeeds. When I look in the AWS console, between usages of apply, it appears to leave my Lambda in an indeterminate state with no execution role. When I look at Terraform's output, what has happened is:
It looks like this might be because AWS returns from the role creation call before the new role is completely available to trusted AWS services such as Lambda.
I have been able to work around this issue by adding a sleep provisioner to every one of my roles, but this is not a tidy workaround:
Terraform Version
Terraform v0.11.5
Affected Resource(s)
Expected Behavior
IAM role replacement with create_before_destroy = true provides zero downtime for AWS Lambda.
Actual Behavior
Lambda function left in indeterminate state, unable to execute.
Steps to Reproduce
Refer to this IAM role resource with a aws_lambda_function resource. Create and apply this infrastructure. Now change the name_prefix field in aws_iam_role.
The text was updated successfully, but these errors were encountered: