# How does terraform use modules?

**URL:** <https://discuss.hashicorp.com/t/how-does-terraform-use-modules/3050>\
**Category:** Terraform\
**Created:** [September 27, 2019, 1:30am UTC](https://discuss.hashicorp.com/t/how-does-terraform-use-modules/3050 "2019-09-27T01:30:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kimdav111](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/kimdav111/32/2417_2.png) [@kimdav111](https://discuss.hashicorp.com/u/kimdav111)\
**Post date:** [September 27, 2019, 1:30am UTC](https://discuss.hashicorp.com/t/how-does-terraform-use-modules/3050/1 "2019-09-27T01:30:48Z")

</div>

How does terraform use modules?

For example in the below link there is reference to a module?  
source = “innovationnorway/virtual-network/azurerm” what is this path for?

Please explain.

[https://registry.terraform.io/modules/innovationnorway/virtual-network/azurerm/1.0.0](https://registry.terraform.io/modules/innovationnorway/virtual-network/azurerm/1.0.0)

There is also module in the upper right of the html page. All it says is to run terraform init. What is the comment to “# insert the 4 required variables here”? What are these 4 variables?

module “virtual-network” {  
source = “innovationnorway/virtual-network/azurerm”  
version = “1.0.0”

# insert the 4 required variables here

}

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

```auto
resource "azurerm_resource_group" "example" {
  name = "example-resources"
  location = "westeurope"
}

module "virtual_network" {
  source = "innovationnorway/virtual-network/azurerm"

  name = "example-network"

  resource_group_name = azurerm_resource_group.example.name

  address_space = ["10.0.0.0/16"]

  subnets = [
    {
      name = "subnet-1"
      address_prefix = "10.0.1.0/24"
    },
    {
      name = "subnet-2"
      address_prefix = "10.0.2.0/24"
      delegations = ["Microsoft.ContainerInstance/containerGroups"]
    },
  ]
}

```

---

<div class="post-metadata">

**Author:** ![sl1pm4t](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/sl1pm4t/32/2112_2.png) [@sl1pm4t](https://discuss.hashicorp.com/u/sl1pm4t)\
**Post date:** [September 27, 2019, 9:46am UTC](https://discuss.hashicorp.com/t/how-does-terraform-use-modules/3050/2 "2019-09-27T09:46:59Z")

</div>

The module source is flexible and can be used to mean one of:

- Terraform Registry reference
- relative / fully qualified path on local file system
- git repository
- http/https

The example you provded would be interpreted by Terraform as a registry module.  
The module sources are described [here](https://www.terraform.io/docs/modules/sources.html).

In regards to the 4 required variables, the module you reference takes 6 total possible input variables, but 4 of them do not have a default value, so must be provided (are required) when you invoke the module. The input variables are documented on the Terraform Registry under the **Inputs** tab:  
[https://registry.terraform.io/modules/innovationnorway/virtual-network/azurerm/1.0.0?tab=inputs](https://registry.terraform.io/modules/innovationnorway/virtual-network/azurerm/1.0.0?tab=inputs)

---

<div class="post-metadata">

**Author:** ![apparentlymart](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/apparentlymart/32/702_2.png) [@apparentlymart](https://discuss.hashicorp.com/u/apparentlymart)\
**Post date:** [September 27, 2019, 9:06pm UTC](https://discuss.hashicorp.com/t/how-does-terraform-use-modules/3050/3 "2019-09-27T21:06:40Z")

</div>

In addition to what @sl1pm4t shared, there’s some general background information on Terraform modules in the documentation section [Modules](https://www.terraform.io/docs/configuration/modules.html). I think the content on that page should hopefully connect the dots a little; if you have any follow-on questions please do ask!
