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)

Add comment

Please register in our forum first to comment.

Comments

By: Tushar Kulkarni

Nice Detailed description!

By: baizid

Great Post. The information you provided is really wonderful. Keep up the good work.

By: Oneteam by Scalefusion

Very well explained.

By: Rajesh

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

By: Rahul Shivalkar

@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.

 

By: Stochastic Parrot

Why is the bucket_name declaration repeated? You have it declared in both root variables.tf and the module level variables.tf