Quick breakdown in pseudo-code version. Hope this helps.
You have these two directories
/modules/
/myproject/
You have a folder within /modules/
/modules/aws_stuff/
With this file
main.tf
Data within /modules/aws_stuff/main.tf
resource “aws_instance” “host1” {
name = host1
}
resource “aws_eip” “elastic_ip” {
name = eip1
}
Now you import that module in file /myproject/main.tf
module “aws” {
source = “…/modules/aws_stuff”
}
So the big idea behind modules is it keep your code DRY and allows you to reuse large chunks of resources as well as control how infrastructure is created because maybe you could change the name of the resources but the basic layout is controlled by however your module is laid out.