Modules in Terraform are used to group multiple resources. You can reuse this grouping multiple times. You can also configure modules with variables, and modules can return output that you can pass to other resources and modules.
To get started with modules, create a folder named modules in the same folder as the template.tf. Inside this folder, create another one, named application. In this folder, we will keep the module responsible for creating all the resources required by a single application, be it MightyTrousers, CrazyFoods, or anything else.
A module is a regular Terraform template, so just create the ./modules/application/application.tf file with the following contents:
resource "aws_security_group" ...