This is the fifth day of my participation in the November Gwen Challenge. Check out the details: The last Gwen Challenge 2021

Use Terraform Registry

The folder structure recommended by the Terraform module repo is shown below. The root module configuration file is located at the root of the repository directory, in this case, storage-Account. We also have a readme.md in the root folder. This is a Markdown file that contains information about the module.

It is recommended that you configure the readme.md file for each Terraform configuration to describe what it is and how to use it. Next, we have our modules folder, which contains any sub-modules that will need to perform additional tasks, such as configuring private links or setting up a static website. We also have a sample directory, which should contain examples of each possible scenario for the module.

Finally, we have our tests folder, which includes the test files written in Golang, to test our modules with the examples in the samples folder:

Storage - account └ ─ ─ the README. Md └ ─ ─ main. Tf └ ─ ─ the variables. The tf └ ─ ─ outputs. The tf ├ ─ ─ ─ modules │ ├ ─ ─ private cc-link │ │ └ ─ ─ TXT TXT TXT TXT TXT TXT TXT TXT TXT TXT TXT TXT TXT TXT TXT TXT TXT TXT TXT TXT TXT TXT TXT TXT TXT TXT TXT TXT TXT TXT TXT TXT TXT TXT TXT TXT TXT TXT TXT TXT TXT TXT TXT TXT TXT TXT └ ─ ─ outputs. Tf │ └ ─ ─ the variables. The tf ├ ─ ─ ─ examples │ ├ ─ ─ ─ public │ │ └ ─ ─ the README. Md │ │ └ ─ ─ main. Tf │ │ └ ─ ─ outputs. The tf │ │ └ ─ ─ ├── ├─ elctron. TXT ├─ elctron. TXT ├─ elctron. TXT ├─ elctron. TXT └ ─ ─ the static - website │ └ ─ ─ the README. Md │ └ ─ ─ main. Tf │ └ ─ ─ outputs. The tf │ └ ─ ─ the variables. The tf └ ─ ─ ─ the test └ ─ ─ sa_public_test. Go └ ─ ─ Sa_private_test. Go └ ─ ─ sa_static_website_test. GoCopy the code

This module structure is how we create production-level Terraform modules that can be used for each project. Creating a module seems like a lot of work, and can be quite onerous; But start small and build your modules slowly. A complex module may take an experienced developer several months to build.

Building a module can take a long time; However, you can leverage the thousands of modules shared by the community by using them as a base or by themselves. The Terraform Registry is the focal point for community-produced Terraform modules.

It is a good idea to check Terraform Registry before building your own modules to save time. It’s also a great learning tool, because you can also view the project on GitHub to see how the modules are accomplished and the logic behind them.

A Terraform registry can also be private and used through the Terraform Cloud. Modules in the public Terraform Registry can be used by referencing them in the < namespace >/< name >/< provider > format. In the following example, we use a module to deploy Azure functionality from the Terraform registry:

resource "azurerm_resource_group" "rg" { name = "rg-MyFirstTerraform" location = "westus" } module "function-app" { The source = "InnovationNorway/function - app/azurerm" version = "0.1.2 function_app_name =" func - terrademo "" resource_group_name = azurerm_resource_group.rg.name location = azurerm_resource_group.rg.location }Copy the code

When we run Terraform Init, the module will be automatically downloaded and used during the Terraform application.

Eight, the conclusion

In this article, we learned about modules and how to use them to abstract the Terraform configuration. We discussed how to create a module and how to reference its output.

We also looked at how to store modules in Git repositories, such as GitHub and Azure Repos. Finally, we learned about the Terraform registry and the community making module stored there.


Boy, haven’t you seen enough? Click on the stone’s home page and take a look at it casually. Maybe there will be a surprise? Welcome to support the likes/attention/comments, your support is my biggest motivation, thank you!