Subnet
Subnet in a virtual network resource. Uses Azure REST API version 2024-05-01. In version 2.x of the Azure Native provider, it used API version 2023-02-01. Other available API versions: 2018-06-01, 2018-07-01, 2018-08-01, 2018-10-01, 2018-11-01, 2018-12-01, 2019-02-01, 2019-04-01, 2019-06-01, 2019-07-01, 2019-08-01, 2019-09-01, 2019-11-01, 2019-12-01, 2020-03-01, 2020-04-01, 2020-05-01, 2020-06-01, 2020-07-01, 2020-08-01, 2020-11-01, 2021-02-01, 2021-03-01, 2021-05-01, 2021-08-01, 2022-01-01, 2022-05-01, 2022-07-01, 2022-09-01, 2022-11-01, 2023-02-01, 2023-04-01, 2023-05-01, 2023-06-01, 2023-09-01, 2023-11-01, 2024-01-01, 2024-03-01, 2024-07-01. These can be accessed by generating a local SDK package using the CLI command pulumi package add azure-native network [ApiVersion]
. See the ../../../version-guide/#accessing-any-api-version-via-local-packages for details.
Example Usage
Create subnet
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using AzureNative = Pulumi.AzureNative;
return await Deployment.RunAsync(() =>
{
var subnet = new AzureNative.Network.Subnet("subnet", new()
{
AddressPrefix = "10.0.0.0/16",
ResourceGroupName = "subnet-test",
SubnetName = "subnet1",
VirtualNetworkName = "vnetname",
});
});
package main
import (
network "github.com/pulumi/pulumi-azure-native-sdk/network/v3"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := network.NewSubnet(ctx, "subnet", &network.SubnetArgs{
AddressPrefix: pulumi.String("10.0.0.0/16"),
ResourceGroupName: pulumi.String("subnet-test"),
SubnetName: pulumi.String("subnet1"),
VirtualNetworkName: pulumi.String("vnetname"),
})
if err != nil {
return err
}
return nil
})
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.azurenative.network.Subnet;
import com.pulumi.azurenative.network.SubnetArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var subnet = new Subnet("subnet", SubnetArgs.builder()
.addressPrefix("10.0.0.0/16")
.resourceGroupName("subnet-test")
.subnetName("subnet1")
.virtualNetworkName("vnetname")
.build());
}
}
Create subnet with a delegation
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using AzureNative = Pulumi.AzureNative;
return await Deployment.RunAsync(() =>
{
var subnet = new AzureNative.Network.Subnet("subnet", new()
{
AddressPrefix = "10.0.0.0/16",
ResourceGroupName = "subnet-test",
SubnetName = "subnet1",
VirtualNetworkName = "vnetname",
});
});
package main
import (
network "github.com/pulumi/pulumi-azure-native-sdk/network/v3"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := network.NewSubnet(ctx, "subnet", &network.SubnetArgs{
AddressPrefix: pulumi.String("10.0.0.0/16"),
ResourceGroupName: pulumi.String("subnet-test"),
SubnetName: pulumi.String("subnet1"),
VirtualNetworkName: pulumi.String("vnetname"),
})
if err != nil {
return err
}
return nil
})
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.azurenative.network.Subnet;
import com.pulumi.azurenative.network.SubnetArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var subnet = new Subnet("subnet", SubnetArgs.builder()
.addressPrefix("10.0.0.0/16")
.resourceGroupName("subnet-test")
.subnetName("subnet1")
.virtualNetworkName("vnetname")
.build());
}
}
Create subnet with service endpoints
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using AzureNative = Pulumi.AzureNative;
return await Deployment.RunAsync(() =>
{
var subnet = new AzureNative.Network.Subnet("subnet", new()
{
AddressPrefix = "10.0.0.0/16",
ResourceGroupName = "subnet-test",
ServiceEndpoints = new[]
{
new AzureNative.Network.Inputs.ServiceEndpointPropertiesFormatArgs
{
Service = "Microsoft.Storage",
},
},
SubnetName = "subnet1",
VirtualNetworkName = "vnetname",
});
});
package main
import (
network "github.com/pulumi/pulumi-azure-native-sdk/network/v3"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := network.NewSubnet(ctx, "subnet", &network.SubnetArgs{
AddressPrefix: pulumi.String("10.0.0.0/16"),
ResourceGroupName: pulumi.String("subnet-test"),
ServiceEndpoints: network.ServiceEndpointPropertiesFormatArray{
&network.ServiceEndpointPropertiesFormatArgs{
Service: pulumi.String("Microsoft.Storage"),
},
},
SubnetName: pulumi.String("subnet1"),
VirtualNetworkName: pulumi.String("vnetname"),
})
if err != nil {
return err
}
return nil
})
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.azurenative.network.Subnet;
import com.pulumi.azurenative.network.SubnetArgs;
import com.pulumi.azurenative.network.inputs.ServiceEndpointPropertiesFormatArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var subnet = new Subnet("subnet", SubnetArgs.builder()
.addressPrefix("10.0.0.0/16")
.resourceGroupName("subnet-test")
.serviceEndpoints(ServiceEndpointPropertiesFormatArgs.builder()
.service("Microsoft.Storage")
.build())
.subnetName("subnet1")
.virtualNetworkName("vnetname")
.build());
}
}
Create subnet with service endpoints with network identifier
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using AzureNative = Pulumi.AzureNative;
return await Deployment.RunAsync(() =>
{
var subnet = new AzureNative.Network.Subnet("subnet", new()
{
AddressPrefix = "10.0.0.0/16",
ResourceGroupName = "subnet-test",
ServiceEndpoints = new[]
{
new AzureNative.Network.Inputs.ServiceEndpointPropertiesFormatArgs
{
NetworkIdentifier = new AzureNative.Network.Inputs.SubResourceArgs
{
Id = "/subscriptions/subid/resourceGroups/subnet-test/providers/Microsoft.Network/publicIPAddresses/test-ip",
},
Service = "Microsoft.Storage",
},
},
SubnetName = "subnet1",
VirtualNetworkName = "vnetname",
});
});
package main
import (
network "github.com/pulumi/pulumi-azure-native-sdk/network/v3"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := network.NewSubnet(ctx, "subnet", &network.SubnetArgs{
AddressPrefix: pulumi.String("10.0.0.0/16"),
ResourceGroupName: pulumi.String("subnet-test"),
ServiceEndpoints: network.ServiceEndpointPropertiesFormatArray{
&network.ServiceEndpointPropertiesFormatArgs{
NetworkIdentifier: &network.SubResourceArgs{
Id: pulumi.String("/subscriptions/subid/resourceGroups/subnet-test/providers/Microsoft.Network/publicIPAddresses/test-ip"),
},
Service: pulumi.String("Microsoft.Storage"),
},
},
SubnetName: pulumi.String("subnet1"),
VirtualNetworkName: pulumi.String("vnetname"),
})
if err != nil {
return err
}
return nil
})
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.azurenative.network.Subnet;
import com.pulumi.azurenative.network.SubnetArgs;
import com.pulumi.azurenative.network.inputs.ServiceEndpointPropertiesFormatArgs;
import com.pulumi.azurenative.network.inputs.SubResourceArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var subnet = new Subnet("subnet", SubnetArgs.builder()
.addressPrefix("10.0.0.0/16")
.resourceGroupName("subnet-test")
.serviceEndpoints(ServiceEndpointPropertiesFormatArgs.builder()
.networkIdentifier(SubResourceArgs.builder()
.id("/subscriptions/subid/resourceGroups/subnet-test/providers/Microsoft.Network/publicIPAddresses/test-ip")
.build())
.service("Microsoft.Storage")
.build())
.subnetName("subnet1")
.virtualNetworkName("vnetname")
.build());
}
}
Create subnet with sharing scope
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using AzureNative = Pulumi.AzureNative;
return await Deployment.RunAsync(() =>
{
var subnet = new AzureNative.Network.Subnet("subnet", new()
{
AddressPrefix = "10.0.0.0/16",
ResourceGroupName = "subnet-test",
SubnetName = "subnet1",
VirtualNetworkName = "vnetname",
});
});
package main
import (
network "github.com/pulumi/pulumi-azure-native-sdk/network/v3"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := network.NewSubnet(ctx, "subnet", &network.SubnetArgs{
AddressPrefix: pulumi.String("10.0.0.0/16"),
ResourceGroupName: pulumi.String("subnet-test"),
SubnetName: pulumi.String("subnet1"),
VirtualNetworkName: pulumi.String("vnetname"),
})
if err != nil {
return err
}
return nil
})
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.azurenative.network.Subnet;
import com.pulumi.azurenative.network.SubnetArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var subnet = new Subnet("subnet", SubnetArgs.builder()
.addressPrefix("10.0.0.0/16")
.resourceGroupName("subnet-test")
.subnetName("subnet1")
.virtualNetworkName("vnetname")
.build());
}
}
Import
An existing resource can be imported using its type token, name, and identifier, e.g.
$ pulumi import azure-native:network:Subnet subnet1 /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworks/{virtualNetworkName}/subnets/{subnetName}
Properties
The address prefix for the subnet.
List of address prefixes for the subnet.
Application gateway IP configurations of virtual network resource.
The Azure API version of the resource.
Set this property to false to disable default outbound connectivity for all VMs in the subnet. This property can only be set at the time of subnet creation and cannot be updated for an existing subnet.
An array of references to the delegations on the subnet.
Array of IpAllocation which reference this subnet.
A list of IPAM Pools for allocating IP address prefixes.
Array of IP configuration profiles which reference this subnet.
An array of references to the network interface IP configurations using subnet.
Nat gateway associated with this subnet.
The reference to the NetworkSecurityGroup resource.
Enable or Disable apply network policies on private end point in the subnet.
An array of references to private endpoints.
Enable or Disable apply network policies on private link service in the subnet.
The provisioning state of the subnet resource.
An array of references to the external resources using subnet.
The reference to the RouteTable resource.
An array of references to services injecting into this subnet.
An array of service endpoint policies.
An array of service endpoints.
Set this property to Tenant to allow sharing subnet with other subscriptions in your AAD tenant. This property can only be set if defaultOutboundAccess is set to false, both properties can only be set if subnet is empty.