Manages a subnet. Subnets represent network segments within the IP space defined by the virtual network.
resource "azurerm_resource_group" "example" {
name = "example-resources"
location = "West Europe"
}
resource "azurerm_virtual_network" "example" {
name = "example-vnet"
address_space = ["10.0.0.0/16"]
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
}
resource "azurerm_subnet" "example" {
name = "example-subnet"
resource_group_name = azurerm_resource_group.example.name
virtual_network_name = azurerm_virtual_network.example.name
address_prefixes = ["10.0.1.0/24"]
delegation {
name = "delegation"
service_delegation {
name = "Microsoft.ContainerInstance/containerGroups"
actions = ["Microsoft.Network/virtualNetworks/subnets/join/action", "Microsoft.Network/virtualNetworks/subnets/prepareNetworkPolicies/action"]
}
}
}
The following arguments are supported:
name
- (Required) The name of the subnet. Changing this forces a new resource to be created.
resource_group_name
- (Required) The name of the resource group in which to create the subnet. This must be the resource group that the virtual network resides in. Changing this forces a new resource to be created.
virtual_network_name
- (Required) The name of the virtual network to which to attach the subnet. Changing this forces a new resource to be created.
address_prefixes
- (Required) The address prefixes to use for the subnet.
delegation
- (Optional) One or more delegation
blocks as defined below.
private_endpoint_network_policies
- (Optional) Enable or Disable network policies for the private endpoint on the subnet. Possible values are Disabled
, Enabled
, NetworkSecurityGroupEnabled
and RouteTableEnabled
. Defaults to Disabled
.
private_link_service_network_policies_enabled
- (Optional) Enable or Disable network policies for the private link service on the subnet. Setting this to true
will Enable the policy and setting this to false
will Disable the policy. Defaults to true
.service_endpoints
- (Optional) The list of Service endpoints to associate with the subnet. Possible values include: Microsoft.AzureActiveDirectory
, Microsoft.AzureCosmosDB
, Microsoft.ContainerRegistry
, Microsoft.EventHub
, Microsoft.KeyVault
, Microsoft.ServiceBus
, Microsoft.Sql
, Microsoft.Storage
, Microsoft.Storage.Global
and Microsoft.Web
.service_endpoint_policy_ids
- (Optional) The list of IDs of Service Endpoint Policies to associate with the subnet.A delegation
block supports the following:
name
- (Required) A name for this delegation.
service_delegation
- (Required) A service_delegation
block as defined below.
A service_delegation
block supports the following:
name
- (Required) The name of service to delegate to. Possible values are GitHub.Network/networkSettings
, Microsoft.ApiManagement/service
, Microsoft.Apollo/npu
, Microsoft.App/environments
, Microsoft.App/testClients
, Microsoft.AVS/PrivateClouds
, Microsoft.AzureCosmosDB/clusters
, Microsoft.BareMetal/AzureHostedService
, Microsoft.BareMetal/AzureHPC
, Microsoft.BareMetal/AzurePaymentHSM
, Microsoft.BareMetal/AzureVMware
, Microsoft.BareMetal/CrayServers
, Microsoft.BareMetal/MonitoringServers
, Microsoft.Batch/batchAccounts
, Microsoft.CloudTest/hostedpools
, Microsoft.CloudTest/images
, Microsoft.CloudTest/pools
, Microsoft.Codespaces/plans
, Microsoft.ContainerInstance/containerGroups
, Microsoft.ContainerService/managedClusters
, Microsoft.ContainerService/TestClients
, Microsoft.Databricks/workspaces
, Microsoft.DBforMySQL/flexibleServers
, Microsoft.DBforMySQL/servers
, Microsoft.DBforMySQL/serversv2
, Microsoft.DBforPostgreSQL/flexibleServers
, Microsoft.DBforPostgreSQL/serversv2
, Microsoft.DBforPostgreSQL/singleServers
, Microsoft.DelegatedNetwork/controller
, Microsoft.DevCenter/networkConnection
, Microsoft.DocumentDB/cassandraClusters
, Microsoft.Fidalgo/networkSettings
, Microsoft.HardwareSecurityModules/dedicatedHSMs
, Microsoft.Kusto/clusters
, Microsoft.LabServices/labplans
, Microsoft.Logic/integrationServiceEnvironments
, Microsoft.MachineLearningServices/workspaces
, Microsoft.Netapp/volumes
, Microsoft.Network/dnsResolvers
, Microsoft.Network/managedResolvers
, Microsoft.Network/fpgaNetworkInterfaces
, Microsoft.Network/networkWatchers.
, Microsoft.Network/virtualNetworkGateways
, Microsoft.Orbital/orbitalGateways
, Microsoft.PowerPlatform/enterprisePolicies
, Microsoft.PowerPlatform/vnetaccesslinks
, Microsoft.ServiceFabricMesh/networks
, Microsoft.ServiceNetworking/trafficControllers
, Microsoft.Singularity/accounts/networks
, Microsoft.Singularity/accounts/npu
, Microsoft.Sql/managedInstances
, Microsoft.Sql/managedInstancesOnebox
, Microsoft.Sql/managedInstancesStage
, Microsoft.Sql/managedInstancesTest
, Microsoft.Sql/servers
, Microsoft.StoragePool/diskPools
, Microsoft.StreamAnalytics/streamingJobs
, Microsoft.Synapse/workspaces
, Microsoft.Web/hostingEnvironments
, Microsoft.Web/serverFarms
, NGINX.NGINXPLUS/nginxDeployments
, PaloAltoNetworks.Cloudngfw/firewalls
, Qumulo.Storage/fileSystems
, and Oracle.Database/networkAttachments
.
actions
- (Optional) A list of Actions which should be delegated. This list is specific to the service to delegate to. Possible values are Microsoft.Network/networkinterfaces/*
, Microsoft.Network/publicIPAddresses/join/action
, Microsoft.Network/publicIPAddresses/read
, Microsoft.Network/virtualNetworks/read
, Microsoft.Network/virtualNetworks/subnets/action
, Microsoft.Network/virtualNetworks/subnets/join/action
, Microsoft.Network/virtualNetworks/subnets/prepareNetworkPolicies/action
, and Microsoft.Network/virtualNetworks/subnets/unprepareNetworkPolicies/action
.
In addition to the Arguments listed above - the following Attributes are exported:
id
- The subnet ID.name
- (Required) The name of the subnet. Changing this forces a new resource to be created.resource_group_name
- (Required) The name of the resource group in which the subnet is created in.virtual_network_name
- (Required) The name of the virtual network in which the subnet is created in. Changing this forces a new resource to be created.address_prefixes
- (Required) The address prefixes for the subnetThe timeouts
block allows you to specify timeouts for certain actions:
create
- (Defaults to 30 minutes) Used when creating the Subnet.update
- (Defaults to 30 minutes) Used when updating the Subnet.read
- (Defaults to 5 minutes) Used when retrieving the Subnet.delete
- (Defaults to 30 minutes) Used when deleting the Subnet.Subnets can be imported using the resource id
, e.g.
terraform import azurerm_subnet.exampleSubnet /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.Network/virtualNetworks/myvnet1/subnets/mysubnet1