Skip to content

Create IAM role causes ConcurrentModification error

0

I use terraform to manage my infrastructure and often see an error

Error: creating IAM Role (my-role-name): operation error IAM: CreateRole, https response error StatusCode: 409, RequestID: ..., ConcurrentModification

I double and triple checked - role name is unique. Other roles being created almost the same time, but they have different names, should not be a problem. CloudWatch doesn't give additional information besides error "ConcurrentModification". Any ideas why it happens? Retry helps, but ideally do not have this error

  • Can you share all the relevant tf code that relates to the role including any policy attachments and creation etc

asked 2 years ago855 views

2 Answers
1

I suggest you open the CloudTrail console, switch to the us-east-1 region (N. Virginia), and set the event filter to match "Event name" = "CreateRole". Expose the "Error code" column in the list view (under the gear symbol). Look for the event with the non-empty error code, and check if there are other CreateRole calls made just moments earlier. If so, check if the role name is the same (even though it wouldn't be expected to be).

If not, then change the Event name filter to match "DeleteRole" instead. Check if a role by the same name has been deleted shortly before the event timestamp that was shown for the failed CreateRole attempt.

The primary copy of IAM is in us-east-1, but data there is replicated to all the other enabled regions in the partition, so if Terraform just deleted the role moments earlier, IAM might not have reached eventual consistency by the time the new CreateRole attempt is made.

EXPERT

answered 2 years ago

EXPERT

reviewed 2 years ago

  • Well, this might be a good advice, it made me become even better with CloudTrail. But no, it do not correspond to what I experience. Just analyzed 4 cases and no one had close another create/delete role with same name. One very light suspect - I create a policy and role with same name, could they conflict? They should not at least. This is my only suspect

  • The names of IAM roles and managed policies don't share a namespace, so I don't believe they could conflict. It's rather common to see roles dedicated to a specific purpose, like serving as a Lambda execution role, sharing a name with the single policy that is attached.

0

There's a similar report from a bit under a year ago in the Github repo for the AWS provider for Terraform: https://github.com/hashicorp/terraform-provider-aws/issues/34371

It discusses several things, including changes AWS made to IAM back then and possibly rolled back, but the main conclusion is that the ConcurrentModification errors were returned when making multiple changes to the same IAM resource simultaneously, such as when attaching multiple managed policies to a role without waiting each attachment to be completed before requesting the next one.

A workaround that worked for one user was to tell Terraform not to parallelise requests with:

terraform apply -parallelism=1 

but since the report is from a long time ago, I'd suggest you check first that you're using the latest versions of Terraform and the AWS provider, and if the error persists, try the -parallelism=1 option to narrow down if we're likely seeing the same or similar problem.

EXPERT

answered 2 years ago

EXPERT

reviewed 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.