Skip to content

Retoxx-dev/terraform-azurerm-virtual-network

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

terraform-azurerm-virtual-network

Create a virtual network in Azure

With this module you can create a virtual network with subnets and security groups in Azure.

Usage

Virtual Network with subnets

module "virtual_network" {
  source = "<module-source>"

  resource_group_name = "<resource-group-name>"
  location            = "<location>"

  name = "<virtual-network-name>"

  subnets = [
    {
      name             = "<subnet-name>"
      address_prefixes = ["<subnet-address-prefixes>"]
    },
    {
      name             = "<subnet-name>"
      address_prefixes = ["<subnet-address-prefixes>"]
    }
  ]
}

Virtual Network with subnets and security groups

This module can also create security groups and assign them to subnets.By default they're not being attached so to do that, specify assign_to variable with the name of the subnet to which the security group should be assigned.

module "virtual_network" {
  source = "<module-source>"

  resource_group_name = "<resource-group-name>"
  location            = "<location>"

  name = "<virtual-network-name>"

  subnets = [
    {
      name             = "<subnet-name>"
      address_prefixes = ["<subnet-address-prefixes>"]
    },
    {
      name             = "<subnet-name>"
      address_prefixes = ["<subnet-address-prefixes>"]
    }
  ]

  security_groups = [
    {
      name = "<security-group-name>"
      assign_to = "<subnet-name>"
      rules = [
        {
          name                       = "<rule-name>"
          protocol                   = "<rule-protocol>"
          access                     = "<rule-access>"
          priority                   = "<rule-priority>"
          direction                  = "<rule-direction>"
          source_port_range          = "*"
          destination_port_range     = "*"
          source_address_prefix      = "*"
          destination_address_prefix = "*"
        }
      ]
    }
  ]
}

Outputs info

If you want to get specific ID of either the subnet or security group, you can use the following syntax:

module.virtual_network.subnet_ids["<subnet-name>"]
module.virtual_network.security_group_ids["<security-group-name>"]

Requirements

Name Version
terraform >= 1.3.1
azurerm >=3.33

Providers

Name Version
azurerm >=3.33

Modules

No modules.

Resources

Name Type
azurerm_network_security_group.this resource
azurerm_subnet.this resource
azurerm_subnet_network_security_group_association.this resource
azurerm_virtual_network.this resource

Inputs

Name Description Type Default Required
address_space (Required) The address space that is used the Virtual Network. list(string) n/a yes
bgp_community (Optional) The BGP community attribute in format :. string null no
ddos_protection_plan (Optional) A configuration block for DDoS protection plan.
object({
id = string
enable = bool
})
null no
dns_servers (Optional) List of IP addresses of DNS servers. list(string) null no
edge_zone (Optional) Specifies the Edge Zone within the Azure Region where this Virtual Network should exist. Changing this forces a new Virtual Network to be created. string null no
flow_timeout_in_minutes (Optional) The flow timeout in minutes for the Virtual Network, which is used to enable connection tracking for intra-VM flows. Possible values are between 4 and 30 minutes. number null no
location (Required) The location in which to create the Kubernetes Cluster. string n/a yes
name (Required) The name of the Virtual Network. string n/a yes
resource_group_name (Required) The name of the resource group in which to create the Kubernetes Cluster. string n/a yes
security_groups (Optional) A list of security groups to create.
list(object({
name = string
assign_to = optional(string, null)
rules = list(object({
name = string
description = optional(string, null)
protocol = string
source_port_range = optional(string, null)
source_port_ranges = optional(set(string), null)
destination_port_range = optional(string, null)
destination_port_ranges = optional(list(string), null)
source_address_prefix = optional(string, null)
source_address_prefixes = optional(list(string), null)
source_application_security_group_ids = optional(list(string), null)
destination_address_prefix = optional(string, null)
destination_address_prefixes = optional(list(string), null)
destination_application_security_group_ids = optional(list(string), null)
access = string
priority = number
direction = string
}))
tags = optional(map(string), null)
}))
[] no
subnets (Required) A list of subnets to create within the Virtual Network.
list(object({
name = string
address_prefixes = list(string)
subnet_delegations = optional(list(object({
name = string
service_name = string
service_actions = optional(list(string), null)
})), null)
private_endpoint_network_policies = optional(string, "Disabled")
private_link_service_network_policies_enabled = optional(bool, true)
service_endpoints = optional(list(string), null)
service_endpoint_policy_ids = optional(list(string), null)
}))
n/a yes
tags (Optional) A mapping of tags to assign to the resource. map(string) null no

Outputs

Name Description
id The ID of the virtual network.
name The name of the virtual network.
security_group_ids The IDs of the security groups.
subnet_ids The IDs of the subnets within the virtual network.