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

aws_iam_role : "must detach all policies first" when changing role path even with force_detach_policies = true #3104

Closed
ebarault opened this issue Jan 23, 2018 · 11 comments
Labels
bug Addresses a defect in current functionality. service/iam Issues and PRs that pertain to the iam service. stale Old or inactive issues managed by automation, if no further action taken these will get closed.

Comments

@ebarault
Copy link

Terraform Version

Terraform v0.11.2
AWS provider 1.7.1

Affected Resource(s)

  • aws_iam_role

If this issue appears to affect multiple resources, it may be an issue with Terraform's core, so please mention this.

Terraform Configuration Files

resource "aws_iam_role" "role" {
    name        = "my_name"
    path        = "/my/path/"

    force_detach_policies = true

    assume_role_policy =
<<EOF
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::${var.account_id}:root"
      },
      "Action": "sts:AssumeRole"
    }
  ]
}
EOF
}

resource "aws_iam_role_policy_attachment" "policies_by_arns" {
    count      = "${length(var.policy_arns)}"
    role       = "${aws_iam_role.role.name}"
    policy_arn = "${var.policy_arns[count.index]}"
}

Expected Behavior

when changing aws_iam_role.path, the policies should be detached, then the role destroyed and created again

Actual Behavior

1 error(s) occurred:
* aws_iam_role.role (destroy): 1 error(s) occurred:
* aws_iam_role.role: DeleteConflict: Cannot delete entity, must detach all policies first.

References

Possibly linked
#2279

@bflad bflad added the service/iam Issues and PRs that pertain to the iam service. label Jan 23, 2018
@bflad
Copy link
Contributor

bflad commented Jan 23, 2018

@ebarault do you happen to have debug log output here and does this happen consistently for you? I'm thinking this doesn't have anything to do with updating the path specifically (that should just cause a regular destroy/create), but maybe we need to adjust the eventual consistency retry time currently present here: https://github.com/terraform-providers/terraform-provider-aws/blob/master/aws/resource_aws_iam_role.go#L326

@bflad bflad added the bug Addresses a defect in current functionality. label Jan 23, 2018
@bflad
Copy link
Contributor

bflad commented Jan 23, 2018

It's also unfortunate that the AWS API does not support updating an IAM role path (unlike IAM groups and users). 😄

@bflad bflad added the waiting-response Maintainers are waiting on response from community or contributor. label Jan 23, 2018
@FireballDWF
Copy link

I just encountered same issue with aws_provider 1.8.0, with only change to the resource was defining the path.

@FireballDWF
Copy link

Reproduced the problem with TF_LOG=DEBUG. Willing to send logs directly to a developer or troubleshooter, but do not want to post publicly.

@bflad bflad removed the waiting-response Maintainers are waiting on response from community or contributor. label May 31, 2018
@rodush
Copy link

rodush commented Jul 15, 2019

Similar type of error, but I am trying to add tags to aws_iam_role resource:

resource "aws_iam_role" "ecs_task_role" {
  name        = "${var.service_name}-task-role-${var.environment}"
  description = "Main role for the ${var.service_name} tasks."

  force_detach_policies = true

  assume_role_policy = "${data.aws_iam_policy_document.ecs_task_assume_role.json}"

  tags = "${local.tags}"
}

And the error I see:

2 error(s) occurred:

* aws_iam_role.task_role (destroy): 1 error(s) occurred:

* aws_iam_role.task_role: DeleteConflict: Cannot delete entity, must detach all policies first.
	status code: 409, request id: 164XXXXX-a711-......
* aws_iam_role.ecs_task_role: 1 error(s) occurred:

* aws_iam_role.ecs_task_role: Error creating IAM Role live-chat-task-role-dev: EntityAlreadyExists: Role with name live-chat-task-role-dev already exists.
	status code: 409, request id: 043XXXXX-a711-.....

@KursLabIgor
Copy link

same for me. On aws provider 2.46 version all worked fine

@derekmurawsky
Copy link

I'm also having this issue after upgrading.

@stavenko
Copy link

Have same issue when doing 'terrafom destroy'

@clemlesne
Copy link

Same issue for me when a role name is updated. This is really annoying and force me to delete manually the resources.

Same as : hashicorp/terraform#2761 and #5417.

@github-actions
Copy link

github-actions bot commented Jan 5, 2023

Marking this issue as stale due to inactivity. This helps our maintainers find and focus on the active issues. If this issue receives no comments in the next 30 days it will automatically be closed. Maintainers can also remove the stale label.

If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thank you!

@github-actions github-actions bot added the stale Old or inactive issues managed by automation, if no further action taken these will get closed. label Jan 5, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Feb 5, 2023
@github-actions
Copy link

github-actions bot commented Mar 8, 2023

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 have found a problem that seems similar to this, 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 Mar 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/iam Issues and PRs that pertain to the iam service. stale Old or inactive issues managed by automation, if no further action taken these will get closed.
Projects
None yet
Development

No branches or pull requests

8 participants