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

Use Git management module

If we plan to share this module across multiple environments, it is best to put the module in a source control repository, so we can get all the benefits of source control, such as change tracking.

In addition, we get the version tag. Tagging modules is a best practice because it allows us to “pin” a stable working version of a module into a Terraform configuration. This prevents any disruptive changes from affecting configurations already in production.

To use the Terraform module from your Git repository, change the source parameter to a Git URL. In our example, I have uploaded our storage account module to Azure DevOps Buyback. This is a public Git repo that does not require any authentication configuration. We can use HTTPS urls and prefix them with git: : :.

#Create Storage Account
module "storage_account" {
  source    = "git::https://[email protected]/allanore/TerraformModulesExample/_git/TerraformModulesExample?ref=v0.1"

  saname    = "tfdemosa23432"
  rgname    = azurerm_resource_group.rg.name
  location  = azurerm_resource_group.rg.location
}
Copy the code

If we run terraForm Init, we can see in the console output that the module was downloaded from git repo and saved to. Terraform/modules local directory:

. Please install a compatible extension version or remove it. Initializing modules... Downloading git::https://[email protected]/allanore/TerraformModulesExample/_git/TerraformModulesExample?ref=v0.1 for storage_account... - storage_account in .terraform/modules/storage_account Downloading git::https://[email protected]/allanore/TerraformModulesExample/_git/TerraformModulesExample?ref=v0.1 for storage_account2... - storage_account2 in .terraform/modules/storage_account2 Initializing the backend... .Copy the code

Alternatively, if we want to use a private Azure Repo with SSH, we can reference our module in the source parameter via the SSH URL shown below. We also need to generate and install SSH certificates for authentication.

git::[email protected]: v3 / allanore/TerraformModulesExample/TerraformModulesExample? Ref = v0.1Copy the code

To use the Terraform module source code from the GitHub repo, use the GitHub project URL. In the following example, I uploaded our module to the Github repo:

#Create Storage Account
module "storage_account" {
  source    = "github.com/**/TerraformModulesExample"

  saname    = "tfdemosa23432"
  rgname    = azurerm_resource_group.rg.name
  location  = azurerm_resource_group.rg.location
}
Copy the code

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!