3
votes

Im currently working with Multiple AWS accounts within an organization. I have multiple providers setup with assume role.

Is there a way to have resources roll through all the providers to ensure everything is installed that I've defined in a Terraform module? I'm trying to avoid having a resource per provider and have one resource that would use each provider.

Hope someone can help with this or has a use case like this.

TIA

1
From what you're asking I think the answer here is no but if you could share a minimal reproducible example of what you've currently got and what you would like to do instead then someone might be able to suggest a better way of structuring things. - ydaetskcoR

1 Answers

5
votes

No, it is not possible to have just one resource block using multiple providers. The best way to do is to have different folders for different accounts in organisation. Each folder having its main.tf with the same resource block/s (as in your case), and different provider.tf. Inside your main you can call the required modules.

For your case, it might seem as a lot of redundant code but this is the best option. Refer the project structure below to get an idea.

|   Project Directory
|   
+---dev
|   |   main.tf
|   |   param.tfvars
|   |   provider.tf
|   |   terraform.tfstate
|   |   terraform.tfstate.backup
|   |   variables.tf
|   |   
+---modules
|   +---internetgateway
|   |       main.tf
|   |       outputs.tf
|   |       variables.tf
|   |       
|   +---nat
|   |       main.tf
|   |       outputs.tf
|   |       variables.tf
|   |       
+---prod
|   |   main.tf
|   |   param.tfvars
|   |   provider.tf
|   |   terraform.tfstate
|   |   terraform.tfstate.backup
|   |   variables.tf
|   |
+---test
|   |   main.tf
|   |   param.tfvars
|   |   provider.tf
|   |   terraform.tfstate
|   |   terraform.tfstate.backup
|   |   variables.tf