brikis98 / terraform-up-and-running-code

Code samples for the book "Terraform: Up & Running" by Yevgeniy Brikman
http://www.terraformupandrunning.com/
MIT License
2.87k stars 1.92k forks source link

Error creating IAM User X: EntityAlreadyExists: User with name X already exists #19

Closed eperdeme closed 6 years ago

eperdeme commented 6 years ago

Hello,

I was reading the book and doing this example, but if you modify the list in anyway except append it breaks badly and tries to rename existing users. Is there a fix for this?

https://github.com/brikis98/terraform-up-and-running-code/blob/2b64b2e1cd7a3405af97642bcd7a83f4267d881c/code/terraform/05-tips-and-tricks/loops-and-if-statements/live/global/three-iam-users-unique-names/vars.tf#L4

brikis98 commented 6 years ago

Yes, unfortunately, it's a limitation in Terraform :(

See https://github.com/hashicorp/terraform/issues/14275 and https://github.com/hashicorp/terraform/issues/17179 for details.

eperdeme commented 6 years ago

This is a real shame, it literally makes the tool unusable to manage large numbers of items such as subnets or firewall chains.

I guess this is why even the UK Gov terraform code just looks so copy and paste. https://github.com/alphagov/govuk-terraform-provisioning/blob/master/projects/user_management/resources/integration/users.tf

Maybe I'l have to see about some sort of template to generate the TF files, but this means more wrappers :(

brikis98 commented 6 years ago

Agreed, it's quite a painful limitation. Hopefully, there will be a solution in the next version of Terraform.

CoSellCloud commented 4 years ago

You can manage existing users using the import command now:

terraform import aws_iam_user.trinity trinity