{"action":"opened","issue":{"url":"https://api.github.com/repos/hashicorp/terraform/issues/8184","repository_url":"https://api.github.com/repos/hashicorp/terraform","labels_url":"https://api.github.com/repos/hashicorp/terraform/issues/8184/labels{/name}","comments_url":"https://api.github.com/repos/hashicorp/terraform/issues/8184/comments","events_url":"https://api.github.com/repos/hashicorp/terraform/issues/8184/events","html_url":"https://github.com/hashicorp/terraform/issues/8184","id":171138425,"number":8184,"title":"Terraform doesn't reuse an AWS Role it just created and fails?","user":{"login":"matamouros","id":96463,"avatar_url":"https://avatars.githubusercontent.com/u/96463?v=3","gravatar_id":"","url":"https://api.github.com/users/matamouros","html_url":"https://github.com/matamouros","followers_url":"https://api.github.com/users/matamouros/followers","following_url":"https://api.github.com/users/matamouros/following{/other_user}","gists_url":"https://api.github.com/users/matamouros/gists{/gist_id}","starred_url":"https://api.github.com/users/matamouros/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matamouros/subscriptions","organizations_url":"https://api.github.com/users/matamouros/orgs","repos_url":"https://api.github.com/users/matamouros/repos","events_url":"https://api.github.com/users/matamouros/events{/privacy}","received_events_url":"https://api.github.com/users/matamouros/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-08-15T09:36:15Z","updated_at":"2016-08-15T09:36:15Z","closed_at":null,"body":"Hi,\r\n\r\nI have a neat Terraform structure where each environment (dev, stg, prod) has its very own state file. To execute each plan, I need to apply each environment individually (check `dev` dir below).\r\n\r\nI then have a series of modules for handling AWS ECS and ECS services, as well as all the necessary infra to support that. Those are obviously reused between all the environments.\r\n\r\nThis in theory seemed a very good idea, but I've hit something which I don't know if its an anti-pattern of some sort or a shortcoming of Terraform or just something I'm missing. The `ecs-services` dir has all the different services modules. These essentially have the necessary specific config for each different service, e.g., `container_definitions`, etc. which vary from service to service. Then there is, also inside `ecs-services` a `shared` dir which is a module used by the services modules (nested module) and which essentially encapsulates all the common stuff to actually create an ECS service (create task, service, ELB for that service, add roles, etc). Each service module essentially uses this nested module and passes the necessary config to it.\r\n\r\nThe problem I have is that this nested module is apparently trying to create every time the shared `ecs-service-role` that was created by the first service module that ran:\r\n\r\n> Error creating IAM Role ecs-service-role: EntityAlreadyExists: Role with name ecs-service-role already exists.\r\n\r\nI would like for Terraform to not try to create again a role that already exists, and instead reuse it. Is there any way to do this?\r\n\r\nI know I can just flatten everything out and it would be fine, but kind of misses the point of modularising this for proper reuse. Would be grateful for some help, and if this is a Terraform shortcoming does it make sense to consider this as a feature request? Below is the file structure I'm using for this.\r\n\r\n```\r\n├── README.md\r\n├── dev\r\n│   ├── dev.tf\r\n│   ├── main.tf\r\n│   ├── qa.tf\r\n│   ├── terraform.tfstate\r\n│   ├── terraform.tfstate.backup\r\n│   └── terraform.tfvars\r\n├── modules\r\n│   ├── ecs\r\n│   │   ├── main.tf\r\n│   │   └── roles.tf\r\n│   ├── ecs-services\r\n│   │   ├── broker\r\n│   │   │   └── main.tf\r\n│   │   ├── elasticsearch\r\n│   │   │   └── main.tf\r\n│   │   ├── mysql\r\n│   │   │   └── main.tf\r\n│   │   ├── nginx\r\n│   │   │   └── main.tf\r\n│   │   ├── php-fpm\r\n│   │   │   └── main.tf\r\n│   │   └── shared\r\n│   │       ├── main.tf\r\n│   │       └── roles.tf\r\n│   ├── shared\r\n│   │   └── variables.tf\r\n│   ├── vpc-private\r\n│   │   └── main.tf\r\n│   └── vpc-public\r\n│       └── main.tf\r\n├── prod\r\n├── stg\r\n│   └── demo.tf\r\n```"}}
{"actor":{"display_login":"matamouros"}}