You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I suspect this is a timing issue and I was not running Terraform with TF_LOG at the time. Because of changes made to the platform account I was using terraform under, I can't attempt to reproduce this.
Expected Behavior
Terraform successfully persists resources it created to state.
Actual Behavior
Terraform outputs Error creating IAM instance profile [profile name]: EntityAlreadyExists: Instance Profile [profile name] already exists. because it created the resource but did not persist it to its state.
Steps to Reproduce
Attempt to apply the above code.
Hit a limits error during deployment of the VPC.
Attempt to apply again.
Additional Context
I was running this code on 5 separate hosts in parallel with different parameters that would prevent intentional collisions due to naming. The outcome of each is described below. The numbers don't indicate execution order.
Each apply was creating an AWS VPC along with other stuff (roles, permissions, dns, etc). AWS limits accounts to 10 VPCs by default, trying to create more results in an error.
Hit a VPC limits error. Raised limits and continued deployment to completion without error.
Hit a VPC limits error. After limit raise, plan/apply hit EntityAlreadyExists.
Hit a VPC limits error. After limit raise, plan/apply hit EntityAlreadyExists.
Hit a VPC limits error. After limit raise, plan/apply hit EntityAlreadyExists.
Did not hit VPC limits error. Deployment continued to completion without error.
For each with an EntityAlreadyExists I manually check the state file and AWS. In all cases, the resource had been created in AWS but was missing from the state file.
Looking at an instance that hit problem 2, 3, or 4 above shows the following series of events:
terraform plan -out somefile
terraform apply somefile
Terraform prints messages indicating it is creating the resources printed above. It specifically mentioned the names of resources shown in my snippet above. Here is one such message: module.vpc_common.module.role_provisioning.aws_iam_role.cfnprovision: Creation complete after 1s [id=role-name-censored].
Terraform prints an error that a VPC limit was hit and exits with status 1.
VPC limit is raised in the target account
terraform apply (no plan file this time) hits the EntityAlreadyExists error. Here is the exact error mentioning the role name printed in the previous execution:
Error: Error creating IAM Role role-name-censored: EntityAlreadyExists: Role with name role-name-censored already exists.
status code: 409, request id: xxxxxxxxxxxxxxxxxxxxxxx
on ../../modules/role_provisioning/main.tf line 18, in resource "aws_iam_role" "cfnprovision":
18: resource "aws_iam_role" "cfnprovision" {
This looks and smells like the resource already existed prior to using Terraform. I am confident that this is not the case.
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.
ghost
locked and limited conversation to collaborators
Apr 1, 2020
This issue was closed.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Terraform Version
Terraform Configuration Files
Debug Output
I suspect this is a timing issue and I was not running Terraform with TF_LOG at the time. Because of changes made to the platform account I was using terraform under, I can't attempt to reproduce this.
Expected Behavior
Terraform successfully persists resources it created to state.
Actual Behavior
Terraform outputs
Error creating IAM instance profile [profile name]: EntityAlreadyExists: Instance Profile [profile name] already exists.
because it created the resource but did not persist it to its state.Steps to Reproduce
Additional Context
I was running this code on 5 separate hosts in parallel with different parameters that would prevent intentional collisions due to naming. The outcome of each is described below. The numbers don't indicate execution order.
Each apply was creating an AWS VPC along with other stuff (roles, permissions, dns, etc). AWS limits accounts to 10 VPCs by default, trying to create more results in an error.
EntityAlreadyExists
.EntityAlreadyExists
.EntityAlreadyExists
.For each with an
EntityAlreadyExists
I manually check the state file and AWS. In all cases, the resource had been created in AWS but was missing from the state file.Looking at an instance that hit problem 2, 3, or 4 above shows the following series of events:
terraform plan -out somefile
terraform apply somefile
module.vpc_common.module.role_provisioning.aws_iam_role.cfnprovision: Creation complete after 1s [id=role-name-censored]
.terraform apply
(no plan file this time) hits theEntityAlreadyExists
error. Here is the exact error mentioning the role name printed in the previous execution:This looks and smells like the resource already existed prior to using Terraform. I am confident that this is not the case.
I was unable to workaround this issue by importing the orphaned resource due to hashicorp/terraform-provider-aws#8040.
The text was updated successfully, but these errors were encountered: