Closed kenorb closed 7 months ago
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/credentials
can look like:$ cat ~/.aws/credentials
[default]
aws_access_key_id = KEYID
aws_secret_access_key = SECRETKEY
[DevOps]
role_arn = arn:aws:iam::12345:role/DevOps
source_profile = default
region = eu-west-1
aws sts get-caller-identity
.aws iam list-instance-profiles
.aws iam list-instance-profiles | grep your-profile-name
aws iam delete-instance-profile --instance-profile-name your-profile-name
.Then after removal, I've run plan
and apply
, but the problem repeats.
I've tried to import role, it imports, but then it has problem reading it.
module.project-ecs-cluster.aws_iam_instance_profile.instance AIPAI55FATXTPKUXN5XIS
Project environment project
module.project-ecs-cluster.aws_iam_instance_profile.instance: Importing from ID "AIPAI55FATXTPKUXN5XIS"...
module.project-ecs-cluster.aws_iam_instance_profile.instance: Import complete!
Imported aws_iam_instance_profile (ID: AIPAI55FATXTPKUXN5XIS)
module.project-ecs-cluster.aws_iam_instance_profile.instance: Refreshing state... (ID: AIPAI55FATXTPKUXN5XIS)
Error: module.project-ecs-cluster.aws_iam_instance_profile.instance (import id: AIPAI55FATXTPKUXN5XIS): 1 error(s) occurred:
* import module.project-ecs-cluster.aws_iam_instance_profile.instance result: AIPAI55FATXTPKUXN5XIS: import module.project-ecs-cluster.aws_iam_instance_profile.instance (id: AIPAI55FATXTPKUXN5XIS): Terraform detected a resource with this ID doesn't
exist. Please verify the ID is correct. You cannot import non-existent
resources using Terraform import.
Releasing state lock. This may take a few moments...
Debug file: tf-import-instance-profile.log
2019/03/21 21:29:34 [DEBUG] [aws-sdk-go] DEBUG: Response iam/GetInstanceProfile Details:
---[ RESPONSE ]--------------------------------------
HTTP/1.1 404 Not Found
Connection: close
Content-Length: 299
Content-Type: text/xml
Date: Thu, 21 Mar 2019 21:29:34 GMT
X-Amzn-Requestid: 6bcfb6f4-4c20-11e9-a9dc-034f8fd4cf2c
Another example demonstrating this bug:
Point 1: I can't destroy the instance profile, because it doesn't exist:
$ terraform destroy module.project-ecs-cluster.aws_iam_instance_profile.instance
Project environment project/env
data.aws_iam_policy_document.instance: Refreshing state...
aws_iam_role.instance: Refreshing state... (ID: myproject-ecs-cluster-role)
Destroy complete! Resources: 0 destroyed.
Releasing state lock. This may take a few moments...
Point 2: I can't apply
either, as it claims the profile already exist:
$ terraform apply -target module.project-ecs-cluster.aws_iam_instance_profile.instance
Project environment project/env
Releasing state lock. This may take a few moments...
module.project-ecs-cluster.aws_iam_instance_profile.instance: Creating...
arn: "" => "<computed>"
create_date: "" => "<computed>"
name: "" => "myproject-ecs-cluster-instance-profile"
path: "" => "/"
role: "" => "myproject-ecs-cluster-role"
roles.#: "" => "<computed>"
unique_id: "" => "<computed>"
Releasing state lock. This may take a few moments...
Error: Error applying plan:
1 error(s) occurred:
* module.project-ecs-cluster.aws_iam_instance_profile.instance: 1 error(s) occurred:
* 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: 689321f1-4c23-11e9-b894-73b7f6be78e7
Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.
Any ideas? This is now blocking us too.
Exact same issue here.
I found a good workaround for this problem https://artem.services/?p=1105&lang=en
Yeah I'm seeing this as well. Is the only workaround really a manual deletion of the terraform-created instance profile?
edit: terraform destroy
seems to take care of it if you want to go nuclear
Yeah I'm seeing this as well. Is the only workaround really a manual deletion of the terraform-created instance profile?
edit:
terraform destroy
seems to take care of it if you want to go nuclear
Yup, ended up deleting manually the instance profile in some cases, can't really destroy all the manifest all the time :(
I'm seeing the same issue, manually deleting the profile in console then terraform apply
does not resolve for me.
Discovered that an interrupted terraform destroy
had left the offending resource orphaned outside the statefile. Killing it from the AWS console was insufficient, but killing it via commandline restored expected behavior
Encountered this today with:
terraform --version Terraform v0.12.21
Interestingly I did NOT encounter this problem on terraform cloud free tier I stood up as a greenfield test - may be fixed in a subsequent release?
The only information I could glean from TFC:
Terraform v0.12.25 Initializing plugins and modules... 2020/05/20 01:05:54 [DEBUG] Using modified User-Agent: Terraform/0.12.25 TFC/d33daf519f
After spending a day. i solved it as below:
run command
aws iam list-instance-profiles
then, use below command to delete profiles which you get from above command:
aws iam delete-instance-profile --instance-profile-name {InstanceProfileName-from-above-command}
When trouble-shooting, I found that it could have been handy to use taint:
TF_VAR_environment=dr AWS_DEFAULT_REGION=us-east-1 terraform taint aws_iam_role.ecs_instance_role
TF_VAR_environment=dr AWS_DEFAULT_REGION=us-east-1 terraform apply -target aws_iam_role.ecs_instance_role
.. but in this case, it wasn't enough.
This is how I was able to move forward:
TF_VAR_environment=dr AWS_DEFAULT_REGION=us-east-1 terraform destroy -target aws_iam_role.ecs_instance_role
TF_VAR_environment=dr AWS_DEFAULT_REGION=us-east-1 terraform apply -target aws_iam_role.ecs_instance_role
I noticed that when I ran this, other resources were destroyed:
aws_iam_role_policy_attachment.ec2-policy-role-attachment: Destroying... [id=compeat-ecs-instances-role-20200808181214960100000002] aws_iam_role_policy_attachment.ecs-policy-role-attachment: Destroying... [id=compeat-ecs-instances-role-20200808181214979000000003] aws_launch_template.adv2_latest_launch_template: Destroying... [id=lt-0515d8b83a6f7645f] aws_iam_role_policy_attachment.ec2-policy-role-attachment: Destruction complete after 0s aws_iam_role_policy_attachment.ecs-policy-role-attachment: Destruction complete after 0s aws_launch_template.adv2_latest_launch_template: Destruction complete after 0s aws_iam_role.ecs_instance_role: Destroying... [id=compeat-ecs-instances-role] aws_iam_role.ecs_instance_role: Destruction complete after 1s
In my case, I did not see the offending role when I listed the profiles.
This issue is very annoying. Still with terraform 1.1.7
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.
same with aws provider 5.0.1, you have to
manually delete instance profile to fix this.
Same with terraform version: 1.5.4 and aws provider 5.19.0
As maintainers of the Terraform AWS Provider, we’ve reached a decision to close this longstanding issue. We want to assure you that this decision was made after careful consideration, and we’re committed to transparency in our actions.
A few items to note:
resource "aws_launch_configuration" "test" {
name = "tf-acc-test-8675309"
iam_instance_profile = aws_iam_instance_profile.test.name
image_id = data.aws_ami.amzn2-ami-minimal-hvm-ebs-x86_64.id
instance_type = "t2.micro"
}
resource "aws_iam_instance_profile" "test" {
name = "tf-acc-test-8675309"
role = aws_iam_role.test.name
tags = {
Name = "tf-acc-test-8675309"
}
}
data "aws_ami" "amzn2-ami-minimal-hvm-ebs-x86_64" {
most_recent = true
owners = ["amazon"]
filter {
name = "name"
values = ["amzn2-ami-minimal-hvm-*"]
}
filter {
name = "root-device-type"
values = ["ebs"]
}
filter {
name = "architecture"
values = ["x86_64"]
}
}
resource "aws_iam_role" "test" {
name = "tf-acc-test-8675309-role"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": [
"ec2.amazonaws.com"
]
},
"Action": [
"sts:AssumeRole"
]
}
]
}
EOF
}
At this time, I cannot reproduce the issue which may or may not mean it has been fixed in the interim. We lack clarity on how many users are still affected and the precise nature of the remaining issues. Given these uncertainties and our limited resources, it’s difficult for us to effectively address the problem in its current state.
However, we value community feedback immensely. If you’re still encountering issues (such as @tmpm697 and @ChenTsungYu), we encourage you to open a new, focused issue outlining the specific problems you’re facing. We especially need a minimal reproduction configuration. We understand the frustration of having to restart the discussion, but the long history of this particular issue necessitates a fresh approach. A new, well-defined problem statement will greatly increase the likelihood of prompt attention from maintainers or fellow community members.
Ultimately, our goal is to ensure that the Terraform AWS Provider remains a dependable tool for realizing your infrastructure goals. Regrettably, this prolonged issue no longer contributes to that objective. By closing it, we aim to clear the path for more effective problem-solving and a smoother experience for all users. We appreciate your understanding and continued support as we work towards a better future for your provider.
[!WARNING] This issue has been closed, meaning that any additional comments are hard for our team to see. Please assume that the maintainers will not see them.
Ongoing conversations amongst community members are welcome, however, the issue will be locked after 30 days. Moving conversations to another venue, such as the AWS Provider forum, is recommended. If you have additional concerns, please open a new issue, referencing this one where needed.
This functionality has been released in v5.43.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. 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.
Community Note
Terraform Version
Affected Resource(s)
Terraform Configuration Files
This is only part of my configuration:
Error Output
Despite
myproject-ecs-cluster-instance-profile
doesn't exist (verified byaws 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 plan
terraform apply
Check the logs in the attachment.
References
7274
Logs