I know that provider fails if we put double quotes as above. But i dont want to put 2 resource blocks for 2 providers to create 2 S3 buckets as its not a scalable solution.
Currently resources with separate providers must be declared independently, so there is no way around having multiple blocks for the two s3 buckets. If you have many resources duplicated across different provider configurations, you can group them together in a module, and pass the desired provider configurations into multiple instances of the same module. This way you can declare the resource only once within the module, and only the module block is repeated.
So my whole requirement, i do not want to create the s3 bucket one after the other in two different regions. In other words, i do not want to run terraform apply twice for each of the modules. I wanted to run terraform apply once and want to see the buckets getting created in both the regions simultaneously.
so if i have two modules repeated as above and if have the corresponding tfvars file viz ohio.tfvars and ireland.tfvars, how can i run the whole terraform with one single terraform apply command?
I mean should we have to do terraform apply -var-file=ohio.tfvars and terraform apply -var-file=ireland.tfvars? or is there a better way where we can create the same infra in different regions with one single terraform apply command?
I tried using terragrunt, it creates one after the other too. however, it gives errors if i use terragrunt destroy.
So i wanted is to know, can we create resources in multiple regions using terraform simultaneously with one terraform apply command. If yes, can you please help me with a sample code?
What you are showing here will create both buckets concurrently, so I’m not sure why you think you need to run Terraform multiple times. Can you show an example of the problem you have with this configuration?
Ok Let me show you the problem. I wanted to just test this concurrency of resource creation in multiple regions. Hence i started off with simply creating two s3 buckets in ireland and ohio region. Below are my configuration files
Sorry @pnateri, I’m not sure how you are reaching that error once the configuration has been validated. It would help to have a complete standalone example to reproduce. I have a feeling there is something wrong with the provider configuration within the module, but I’m not exactly sure what that could be. It would also help greatly if the source was formatted properly so that it can be copied directly without errors from the post.
Hi @jbardin … I have attached the whole folder structure via a bitbucket link. Please check.
Just an FYI. terraform validate command still gives me the same error
@pnateri, the error is because the root module is referencing the provider aws.ireland, but there is no configuration for aws.ireland in the root module. All provider configuration should be done within the root module, and then passed into the individual sub-modules.
You need to move the aws.ireland and aws.ohio configurations into the root module. This is where you are referencing them to pass into the test-provider module instances. Since you are passing these configurations into the module simply as aws, within the module the default provider name can be used.