Making the code more reusable
As well as using variables, we are also able to reuse chunks of code – when we discussed Ansible in Chapter 5, Deploying to Amazon Web Services, we discussed roles. In Ansible, roles are designed to be called repeatedly, so while we used them to logically split our project into more manageable sections, we can go one step further and have them only perform a single function.
We can also do the same thing in Terraform. For most of our Azure deployments so far, we have been using a module downloaded from the Terraform registry to manage the region settings.
Claranet, the publisher of that module, also has others – let us look at how we can create a virtual network in Azure using only modules (the complete executable code can be found in this book’s GitHub repository):
- To start, we need to initialize the region module as we have been doing in our other Terraform code:
module "azure_region" { source&...