Can I create 2 AWS ASG using one terraform file with a module? Please guide me with terraform code. And do we need 2 ELBs or 1 ELB to set this up?

- 27,240
- 15
- 95
- 114

- 77
- 2
- 3
- 9
-
1Welcome to SO, in general we do not do homework for you, but try to guide and point you into the right direction. So we are not going to set the terraform code for you, but if you try to set it up and fail and have questions, we are going to try to help you to fix it. – Elzo Valugi May 17 '19 at 21:30
1 Answers
You can have 2 ASG created within one terraform module. You can have everything in one file, but the best practice is to separate module files into a separate module folder. Apart from these you can create your ASGs in one or more separate files depending on how do you want to organize your application. Terraform does not care, it joins all the files and builds a dependency tree before executing, the physical organization is not important. In terms of AWS architecture you can have 2 ASGs with 1, 2 or even without ELBs. ELBs are having a different function and logic, and even though most of the time you have an ELB in front of an ASG, that is not a requirement and is totally dependent of the architecture. I had cases where ELB do not have ASGs associated - you can load balance 2 fixed instances, and cases where ASGs did not have an ELB in front of them - as they do not receive traffic, just process tasks from a queue for exampel
You can find documentation on how to create a module in the official documentation.

- 27,240
- 15
- 95
- 114