Comments on How to create a Terraform module
In this article, we will see how to create reusable modules in Terraform. Modules allow us to avoid code duplication. It means the same code can be used to create resources of the same type. By using modules you do not need to copy-paste your code to create multiple resources of the same type.
6 Comment(s)
Comments
Nice Detailed description!
Great Post. The information you provided is really wonderful. Keep up the good work.
Very well explained.
So, do we create 2 main.tf files ?
Which folder do i create the second main.tf ?
Still not clear on how to create terraform modules
@Rajesh.
Yes, we create 2 main.tf files.
1st in the module.
2nd contains call to the module.
In this case, we have source = "./modules/aws-s3" in 2nd main.tf. This can be anywhere, but you would need to then pass the path to source accordingly.
Why is the bucket_name declaration repeated? You have it declared in both root variables.tf and the module level variables.tf