Create dynamic subnets based on a subnet input config/variable input, on an existing or new Azure Virtual Network using Terraform.
This module can be used to do the following subnet tasks based on input:
- Create a new resource group and Vnet and populate with subnets based on input variable subnet config.
- Create a new Vnet in an existing resource group and populate with subnets based on input variable subnet config.
- Populate subnets dynamically onto an existing Vnet in an existing resource group based on input variable subnet config.
Simple example where a new Resource Group and Vnet will be created (Default).
This example requires no input and will create a new resource group and vnet populated with demo subnets based on the default input variables.
provider "azurerm" {
features {}
}
module "dynamic-subnets" {
source = "github.com/Pwd9000-ML/terraform-azurerm-dynamic-subnets"
}
Simple example where a new Vnet with custom DNS will be created in an existing resource group.
This example requires an existing resource group and will create a new vnet populated with demo subnets based on the default input variables.
provider "azurerm" {
features {}
}
module "dynamic-subnets" {
source = "github.com/Pwd9000-ML/terraform-azurerm-dynamic-subnets"
create_rg = false #Existing VNET Resource group name must be provided.
virtual_network_rg_name = "Core-Networking-Rg"
dns_entries = ["10.1.0.10", "10.1.0.138"]
}
Simple example where subnets are populated dynamically onto an existing Vnet.
This example requires an existing resource group and VNET that will be populated with demo subnets based on the default input variables.
This example assumes a network address space of "10.1.0.0/22" with no subnets exists.
For more advanced examples see: examples
provider "azurerm" {
features {}
}
module "dynamic-subnets" {
source = "github.com/Pwd9000-ML/terraform-azurerm-dynamic-subnets"
create_rg = false #Existing VNET Resource group name must be provided.
create_vnet = false #Existing VNET name must be provided.
virtual_network_rg_name = "My-ResourceGroup-Name"
virtual_network_name = "My-VNET-Name"
}
Name | Version |
---|---|
terraform | >= 1.5.0 |
azurerm | ~> 4.0.1 |
Name | Version |
---|---|
azurerm | ~> 4.0.1 |
No modules.
Name | Type |
---|---|
azurerm_resource_group.core_network_rg | resource |
azurerm_subnet.dynamic | resource |
azurerm_virtual_network.core_vnet | resource |
azurerm_resource_group.core_network_rg | data source |
azurerm_virtual_network.core_vnet | data source |
Name | Description | Type | Default | Required |
---|---|---|---|---|
common_tags | A map of key value pairs that is used to tag resources created. (Default: demo map) | map(string) |
{ |
no |
create_rg | Create a new resource group for this deployment. (Set to false to use existing resource group) | bool |
true |
no |
create_vnet | Create a new Azure Virtual Network for this deployment. (Set to false to use existing Azure Virtual Network) | bool |
true |
no |
dns_entries | Set custom dns config. If no values specified, this defaults to Azure DNS (Only in effect on newly created Vnet when variable:create_vnet=true) | list(string) |
[] |
no |
environment | Value to describe the environment. Used for tagging. (Default: Development) | string |
"Development" |
no |
location | Location in azure where resources will be created. (Only in effect on newly created Resource Group when variable:create_rg=true) | string |
"uksouth" |
no |
network_address_ip | Network IP to construct network address space. (Only in effect on newly created Vnet when variable:create_vnet=true) | string |
"10.1.0.0" |
no |
network_address_mask | Network address mask to construct network address space. (Only in effect on newly created Vnet when variable:create_vnet=true) | number |
22 |
no |
subnet_config | Subnet config map for each subnet to be created in either existing or newly created VNET based on. (create_vnet=true/false) | map(object({ |
{ |
no |
virtual_network_name | Name of the existing Vnet subnets will be created in. (create_vnet=false) / Name of the new Vnet that will be created. (create_vnet=true) | string |
"Terraform-CORE-VNET" |
no |
virtual_network_rg_name | Name of the resource group the existing Vnet is in. (create_rg=false) / Name of the resource group the Vnet will be created in. (create_rg=true). | string |
"Terraform-CORE-Networking" |
no |
Name | Description |
---|---|
core_network_rg_id | Output Resource Group ID. (Only if new resource group was created as part of this deployment) |
core_vnet_id | Output Azure Virtual Network ID. (Only if new Vnet was created as part of this deployment) |