terraform-provider-aws: EntityAlreadyExists: Instance Profile already exists
Community Note
- Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
- Please do not leave “+1” or “me too” comments, they generate extra noise for issue followers and do not help prioritize the request
- If you are interested in working on this issue or have submitted a pull request, please leave a comment
Terraform Version
Terraform version: 0.11.13
Go runtime version: go1.11.5
Affected Resource(s)
- aws_v1.60.0_x4
Terraform Configuration Files
This is only part of my configuration:
resource "aws_iam_instance_profile" "instance" {
provider = "aws.auto-scale-group"
name = "${var.application}-${var.environment}-${var.purpose}-instance-profile"
role = "${aws_iam_role.instance.name}"
lifecycle {
create_before_destroy = true # or false
}
}
Error Output
+ module.project-ecs-cluster.aws_iam_instance_profile.instance
id: <computed>
arn: <computed>
create_date: <computed>
name: "myproject-ecs-cluster-instance-profile"
path: "/"
role: "myproject-ecs-cluster-role"
roles.#: <computed>
unique_id: <computed>
+ module.project-ecs-cluster.aws_launch_configuration.instance
id: <computed>
associate_public_ip_address: "false"
ebs_block_device.#: <computed>
ebs_optimized: <computed>
enable_monitoring: "true"
iam_instance_profile: "myproject-ecs-cluster-instance-profile"
image_id: "ami-00921cd1ce43d567a"
instance_type: "t3.medium"
key_name: "ec2-user-docker-cluster-host"
name: <computed>
name_prefix: "myproject-ecs-cluster-lc-"
root_block_device.#: "1"
root_block_device.0.delete_on_termination: "true"
root_block_device.0.iops: <computed>
root_block_device.0.volume_size: "8"
root_block_device.0.volume_type: <computed>
security_groups.#: "1"
security_groups.2794183374: "sg-0d13250a2c3caeaf5"
user_data: "f128dd1a4d74456830249c3f2a22de9ed7ebdb8b"
Plan: 8 to add, 1 to change, 0 to destroy.
...
1 error(s) occurred:
* module.project-ecs-cluster.aws_iam_instance_profile.instance: 1 error(s) occurred:
2019-03-21T16:36:41.155Z [DEBUG] plugin.terraform-provider-aws_v1.60.0_x4: 2019/03/21 16:36:41 [ERR] plugin: plugin server: accept unix /tmp/plugin186793848: use of closed network connection
* aws_iam_instance_profile.instance: Error creating IAM instance profile myproject-ecs-cluster-instance-profile: EntityAlreadyExists: Instance Profile myproject-ecs-cluster-instance-profile already exists.
status code: 409, request id: 7db379b7-4bf7-11e9-b286-e78361536fef
Despite myproject-ecs-cluster-instance-profile doesn’t exist (verified by aws iam list-instance-profiles), before and after the run.
Expected Behavior
It should work without the error.
Actual Behavior
It errors on EntityAlreadyExists despite myproject-ecs-cluster-instance-profile instance doesn’t exist.
Steps to Reproduce
terraform planterraform apply
Check the logs in the attachment.
References
Logs
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 44
- Comments: 16 (1 by maintainers)
After spending a day. i solved it as below: run command
aws iam list-instance-profilesthen, use below command to delete profiles which you get from above command:aws iam delete-instance-profile --instance-profile-name {InstanceProfileName-from-above-command}I found a good workaround for this problem https://artem.services/?p=1105&lang=en
Exact same issue here.
Ok, the profile existed, but in another role.
I’ve followed the following steps:
userIdentity/sessionIssuer/sessionIssuer/arn.aws sts assume-role --role-arn arn:aws:iam::12345:role/DevOps --role-session-name cli.aws sts get-caller-identity.export AWS_PROFILE=DevOps, where your~/.aws/credentialscan look like:aws sts get-caller-identity.aws iam list-instance-profiles.aws iam list-instance-profiles | grep your-profile-nameaws iam delete-instance-profile --instance-profile-name your-profile-name.Then after removal, I’ve run
planandapply, but the problem repeats.I’ve tried to import role, it imports, but then it has problem reading it.
Debug file: tf-import-instance-profile.log
Has there been any progress on the issue? I have been struggling with the same. I tried manually deleting the profile but there is no such profile.
This issue is very annoying. Still with terraform 1.1.7
Yup, ended up deleting manually the instance profile in some cases, can’t really destroy all the manifest all the time 😦
Another example demonstrating this bug:
Point 1: I can’t destroy the instance profile, because it doesn’t exist:
Point 2: I can’t
applyeither, as it claims the profile already exist: