Automate Terraform Module Generation

Sushil Saini
3 min readSep 27, 2022

--

With Terraform you can automate majority of your day to day tasks. However, to do that, you first need to write component specific modules and its often confusing on what parameters or variable any module can support. Unless its documented properly or demonstrated with examples, its hard to write a complete module.

Well not anymore. Use Terraform Generator.

With Terraform Generator you can get complete set of supported modules by any Terraform provider in the terraform registry https://registry.terraform.io/browse/providers.

Once you generate the required modules, you can customize them as per your environment and automate any of your service catalog items. So be it Azure, AWS, Google or any other cloud, be it AD, VMware or any other product, if there’s a Terraform provider, you can generate and get all the supported module within minutes.

Here are the steps:

  • Note down the source and version:
  • Go to https://github.com/sushil46in/terraform_modules.git and check if any folder exist with the required source and version combination. In this example folder name will be ‘azurestack_1.0.0’
  • If it exists you can download the required folder and all the modules will be there:
  • Each module will have three files, the module, the variables and the outputs.
  • If your required provider is not there in this repository, then follow the steps below to generate them automatically within minutes.
  • Login to your Github account the fork the repository https://github.com/sushil46in/terraform_modules.git by clicking on fork in right corner:
  • This will create a copy of this repository to your Github account. Open the forked repository in your account and edit the request_provider.txt file, append the required provider to the end of this file. For example, if the source in the example above is “hashicorp/azurestack” and version is “1.0.0!, then the entry to be added will be:

hashicorp/azurestack:1.0.0

  • Multiple providers can be added at a time. Commit the changes by adding relevant comment:
  • Once committed, open a new pull request to sync these changes back to the original repository:
  • The pull request will go for approval and once approved, the modules for newly added providers will be available in the original repository within minutes of approval:
  • Now you can download this folder directly from the original repository of sync it back to your forked repository:

Hopefully these modules will help you automate your tasks and save a lot of time for you. Feel free to drop in your comments on any improvements/suggestions.

--

--