This module creates the basic and advance network resources for virtual network in azure .
Name | Version |
---|---|
terraform | >= 1.3.0 |
Before you begin, ensure you have the following installed:
- Terraform (version X.XX.X)
- Azure CLI (version X.XX.X)
- Azure Subscription
Name | Version |
---|---|
azurerm | >= 3.0 |
- This module contain the example child module which also contains the 2 sub modules i.e vnet-advance , vnet-simple
- vnet-advance module specifies the user defined subnet configuration in which the users create the advance configuration in vnet i.e subnet delegation service , nsg association , route table association , nat gateway etc.
- vnet-simple module specifies the simple configuration of virtual network i.e it will create only user define subnets and one virtual network.
This repository contains a Terraform module to create an Azure Virtual network.
To configure the Azure provider, you need to set up the necessary Azure credentials. If you already have the Azure CLI installed and authenticated with Azure, Terraform will use the same credentials.
If you haven't authenticated with Azure, you can do so by running:
az login
First, clone this repository to your local machine using the following command:
git clone <repository_url>
cd <repository_name>
Once you have cloned the repository, navigate to the module directory and initialize Terraform:
cd path/to/module_directory
terraform init
This will download the necessary plugins required for Terraform to work with Azure.
After configuring the input variables, you can apply the Terraform configuration to create the Azure Container Registry:
terraform apply
Terraform will show you the changes that will be applied to the infrastructure. Type yes
to confirm and apply the changes.
The project uses the following variables:
location
: The Azure region where resources will be created.resource_group_name
: The name of the resource group where resources will be provisioned.vnet_name
: The name of the Virtual Network.address_spae
: CIDR range for vnet.subnet_type
: The type of subnets to create.subnets
: It defines the user defined subnet configurationsubnet_bits
: The number of simple subnets to create (used whensubnet_type = "subnet-simple"
).associate_with_route_table
: It create route table & associate the required subnet to route table.is_natgateway
: If true then it create a nat gateway for the subnets.is_nsg
: If true then it create a NSG for the subnets.service_delegation
: If true then it will create the service delegation for subnet.Virtual_network_peering
: If true then it will create the VNet Peering.
To provision the resources, modify the variables in variables.tf
to match your desired configuration.
module "vnet_main" {
source = "git::https://github.com/tothenew/terraform-azure-vnet.git?ref=vnet-v1"
resource_group_name = azurerm_resource_group.main.name
location = azurerm_resource_group.main.location
address_space = "10.0.0.0/16"
virtual_network_peering = true
subnets = {
"vm1" = {
address_prefixes = ["10.0.1.0/24"]
associate_with_route_table = false
is_natgateway = true
is_nsg = true
service_delegation = true
delegation_name = "Microsoft.ContainerInstance/containerGroups"
delegation_actions = ["Microsoft.Network/virtualNetworks/subnets/action"]
}
"vm2" = {
address_prefixes = ["10.0.2.0/24"]
associate_with_route_table = false
service_endpoints = ["Microsoft.AzureCosmosDB"]
}
}
}
Name | Type |
---|---|
azurerm_virtual_network.main | resource |
azurerm_network_security_group.main | resource |
azurerm_route_table.main | resource |
azurerm_subnet.subnets | resource |
azurerm_resource_group.rg | resource |
azurerm_subnet_route_table_association.main | resource |
azurerm_subnet_network_security_group_association | resource |
Name | Description | Type |
---|---|---|
subnet_type | define the type of the subnet for subnet_simple | string |
address_space | specify the CIDR Block for vnet | string |
address_prefixes | specify the CIDR Block for subnets in vnet | string |
subnet_bits | define the number of subnet_simple creates | number |
resource_group_name | specify the name of the resource group | string |
location | specify the location of the vnet | string |
subnets | specify the subnets name having cidr_ranges and is_public variable etc.. | map(object({ |
virtual_network_peering | specify the creation of vnet peering. | bool |
is_natgateway | specify the creation of NAT Gateway for subnets. | bool |
is_nsg | specify the creation of NSG for subnets. | bool |
service_delegation | specify the service_delegation for subnets. | bool |
associate_with_route_table | specify the creation of Route Table and associate the subnets. | bool |
service_endpoint | specify the service endpoint for subnets. | bool |
Below are some useful Terraform commands for managing the project:
terraform init
: Initializes the Terraform configuration.terraform validate
: To validate the syntax of the configuration.terraform plan
: Shows the execution plan for the resources.terraform apply
: Applies the changes and creates the Azure resources.terraform destroy
: Destroys all resources created by Terraform.
Module managed by TO THE NEW Pvt. Ltd.
Apache 2 Licensed. See LICENSE for full details.