1. Packages
  2. Azure Classic
  3. API Docs
  4. network
  5. getSubnet

We recommend using Azure Native.

Azure Classic v5.81.0 published on Monday, Jun 24, 2024 by Pulumi

azure.network.getSubnet

Explore with Pulumi AI

azure logo

We recommend using Azure Native.

Azure Classic v5.81.0 published on Monday, Jun 24, 2024 by Pulumi

    Use this data source to access information about an existing Subnet within a Virtual Network.

    Example Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as azure from "@pulumi/azure";
    
    const example = azure.network.getSubnet({
        name: "backend",
        virtualNetworkName: "production",
        resourceGroupName: "networking",
    });
    export const subnetId = example.then(example => example.id);
    
    import pulumi
    import pulumi_azure as azure
    
    example = azure.network.get_subnet(name="backend",
        virtual_network_name="production",
        resource_group_name="networking")
    pulumi.export("subnetId", example.id)
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-azure/sdk/v5/go/azure/network"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		example, err := network.LookupSubnet(ctx, &network.LookupSubnetArgs{
    			Name:               "backend",
    			VirtualNetworkName: "production",
    			ResourceGroupName:  "networking",
    		}, nil)
    		if err != nil {
    			return err
    		}
    		ctx.Export("subnetId", example.Id)
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Azure = Pulumi.Azure;
    
    return await Deployment.RunAsync(() => 
    {
        var example = Azure.Network.GetSubnet.Invoke(new()
        {
            Name = "backend",
            VirtualNetworkName = "production",
            ResourceGroupName = "networking",
        });
    
        return new Dictionary<string, object?>
        {
            ["subnetId"] = example.Apply(getSubnetResult => getSubnetResult.Id),
        };
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.azure.network.NetworkFunctions;
    import com.pulumi.azure.network.inputs.GetSubnetArgs;
    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) {
            final var example = NetworkFunctions.getSubnet(GetSubnetArgs.builder()
                .name("backend")
                .virtualNetworkName("production")
                .resourceGroupName("networking")
                .build());
    
            ctx.export("subnetId", example.applyValue(getSubnetResult -> getSubnetResult.id()));
        }
    }
    
    variables:
      example:
        fn::invoke:
          Function: azure:network:getSubnet
          Arguments:
            name: backend
            virtualNetworkName: production
            resourceGroupName: networking
    outputs:
      subnetId: ${example.id}
    

    Using getSubnet

    Two invocation forms are available. The direct form accepts plain arguments and either blocks until the result value is available, or returns a Promise-wrapped result. The output form accepts Input-wrapped arguments and returns an Output-wrapped result.

    function getSubnet(args: GetSubnetArgs, opts?: InvokeOptions): Promise<GetSubnetResult>
    function getSubnetOutput(args: GetSubnetOutputArgs, opts?: InvokeOptions): Output<GetSubnetResult>
    def get_subnet(name: Optional[str] = None,
                   resource_group_name: Optional[str] = None,
                   virtual_network_name: Optional[str] = None,
                   opts: Optional[InvokeOptions] = None) -> GetSubnetResult
    def get_subnet_output(name: Optional[pulumi.Input[str]] = None,
                   resource_group_name: Optional[pulumi.Input[str]] = None,
                   virtual_network_name: Optional[pulumi.Input[str]] = None,
                   opts: Optional[InvokeOptions] = None) -> Output[GetSubnetResult]
    func LookupSubnet(ctx *Context, args *LookupSubnetArgs, opts ...InvokeOption) (*LookupSubnetResult, error)
    func LookupSubnetOutput(ctx *Context, args *LookupSubnetOutputArgs, opts ...InvokeOption) LookupSubnetResultOutput

    > Note: This function is named LookupSubnet in the Go SDK.

    public static class GetSubnet 
    {
        public static Task<GetSubnetResult> InvokeAsync(GetSubnetArgs args, InvokeOptions? opts = null)
        public static Output<GetSubnetResult> Invoke(GetSubnetInvokeArgs args, InvokeOptions? opts = null)
    }
    public static CompletableFuture<GetSubnetResult> getSubnet(GetSubnetArgs args, InvokeOptions options)
    // Output-based functions aren't available in Java yet
    
    fn::invoke:
      function: azure:network/getSubnet:getSubnet
      arguments:
        # arguments dictionary

    The following arguments are supported:

    Name string
    Specifies the name of the Subnet.
    ResourceGroupName string
    Specifies the name of the resource group the Virtual Network is located in.
    VirtualNetworkName string
    Specifies the name of the Virtual Network this Subnet is located within.
    Name string
    Specifies the name of the Subnet.
    ResourceGroupName string
    Specifies the name of the resource group the Virtual Network is located in.
    VirtualNetworkName string
    Specifies the name of the Virtual Network this Subnet is located within.
    name String
    Specifies the name of the Subnet.
    resourceGroupName String
    Specifies the name of the resource group the Virtual Network is located in.
    virtualNetworkName String
    Specifies the name of the Virtual Network this Subnet is located within.
    name string
    Specifies the name of the Subnet.
    resourceGroupName string
    Specifies the name of the resource group the Virtual Network is located in.
    virtualNetworkName string
    Specifies the name of the Virtual Network this Subnet is located within.
    name str
    Specifies the name of the Subnet.
    resource_group_name str
    Specifies the name of the resource group the Virtual Network is located in.
    virtual_network_name str
    Specifies the name of the Virtual Network this Subnet is located within.
    name String
    Specifies the name of the Subnet.
    resourceGroupName String
    Specifies the name of the resource group the Virtual Network is located in.
    virtualNetworkName String
    Specifies the name of the Virtual Network this Subnet is located within.

    getSubnet Result

    The following output properties are available:

    AddressPrefix string
    AddressPrefixes List<string>
    The address prefixes for the subnet.
    DefaultOutboundAccessEnabled bool
    Is the default outbound access enabled for the subnet.
    EnforcePrivateLinkEndpointNetworkPolicies bool
    EnforcePrivateLinkServiceNetworkPolicies bool
    Id string
    The provider-assigned unique ID for this managed resource.
    Name string
    NetworkSecurityGroupId string
    The ID of the Network Security Group associated with the subnet.
    PrivateEndpointNetworkPolicies string
    Enable or Disable network policies for the private endpoint on the subnet.
    PrivateEndpointNetworkPoliciesEnabled bool

    Deprecated: This property has been superseded by private_endpoint_network_policies and will be removed in v4.0 of the AzureRM Provider.

    PrivateLinkServiceNetworkPoliciesEnabled bool
    Enable or Disable network policies for the private link service on the subnet.
    ResourceGroupName string
    RouteTableId string
    The ID of the Route Table associated with this subnet.
    ServiceEndpoints List<string>
    A list of Service Endpoints within this subnet.
    VirtualNetworkName string
    AddressPrefix string
    AddressPrefixes []string
    The address prefixes for the subnet.
    DefaultOutboundAccessEnabled bool
    Is the default outbound access enabled for the subnet.
    EnforcePrivateLinkEndpointNetworkPolicies bool
    EnforcePrivateLinkServiceNetworkPolicies bool
    Id string
    The provider-assigned unique ID for this managed resource.
    Name string
    NetworkSecurityGroupId string
    The ID of the Network Security Group associated with the subnet.
    PrivateEndpointNetworkPolicies string
    Enable or Disable network policies for the private endpoint on the subnet.
    PrivateEndpointNetworkPoliciesEnabled bool

    Deprecated: This property has been superseded by private_endpoint_network_policies and will be removed in v4.0 of the AzureRM Provider.

    PrivateLinkServiceNetworkPoliciesEnabled bool
    Enable or Disable network policies for the private link service on the subnet.
    ResourceGroupName string
    RouteTableId string
    The ID of the Route Table associated with this subnet.
    ServiceEndpoints []string
    A list of Service Endpoints within this subnet.
    VirtualNetworkName string
    addressPrefix String
    addressPrefixes List<String>
    The address prefixes for the subnet.
    defaultOutboundAccessEnabled Boolean
    Is the default outbound access enabled for the subnet.
    enforcePrivateLinkEndpointNetworkPolicies Boolean
    enforcePrivateLinkServiceNetworkPolicies Boolean
    id String
    The provider-assigned unique ID for this managed resource.
    name String
    networkSecurityGroupId String
    The ID of the Network Security Group associated with the subnet.
    privateEndpointNetworkPolicies String
    Enable or Disable network policies for the private endpoint on the subnet.
    privateEndpointNetworkPoliciesEnabled Boolean

    Deprecated: This property has been superseded by private_endpoint_network_policies and will be removed in v4.0 of the AzureRM Provider.

    privateLinkServiceNetworkPoliciesEnabled Boolean
    Enable or Disable network policies for the private link service on the subnet.
    resourceGroupName String
    routeTableId String
    The ID of the Route Table associated with this subnet.
    serviceEndpoints List<String>
    A list of Service Endpoints within this subnet.
    virtualNetworkName String
    addressPrefix string
    addressPrefixes string[]
    The address prefixes for the subnet.
    defaultOutboundAccessEnabled boolean
    Is the default outbound access enabled for the subnet.
    enforcePrivateLinkEndpointNetworkPolicies boolean
    enforcePrivateLinkServiceNetworkPolicies boolean
    id string
    The provider-assigned unique ID for this managed resource.
    name string
    networkSecurityGroupId string
    The ID of the Network Security Group associated with the subnet.
    privateEndpointNetworkPolicies string
    Enable or Disable network policies for the private endpoint on the subnet.
    privateEndpointNetworkPoliciesEnabled boolean

    Deprecated: This property has been superseded by private_endpoint_network_policies and will be removed in v4.0 of the AzureRM Provider.

    privateLinkServiceNetworkPoliciesEnabled boolean
    Enable or Disable network policies for the private link service on the subnet.
    resourceGroupName string
    routeTableId string
    The ID of the Route Table associated with this subnet.
    serviceEndpoints string[]
    A list of Service Endpoints within this subnet.
    virtualNetworkName string
    address_prefix str
    address_prefixes Sequence[str]
    The address prefixes for the subnet.
    default_outbound_access_enabled bool
    Is the default outbound access enabled for the subnet.
    enforce_private_link_endpoint_network_policies bool
    enforce_private_link_service_network_policies bool
    id str
    The provider-assigned unique ID for this managed resource.
    name str
    network_security_group_id str
    The ID of the Network Security Group associated with the subnet.
    private_endpoint_network_policies str
    Enable or Disable network policies for the private endpoint on the subnet.
    private_endpoint_network_policies_enabled bool

    Deprecated: This property has been superseded by private_endpoint_network_policies and will be removed in v4.0 of the AzureRM Provider.

    private_link_service_network_policies_enabled bool
    Enable or Disable network policies for the private link service on the subnet.
    resource_group_name str
    route_table_id str
    The ID of the Route Table associated with this subnet.
    service_endpoints Sequence[str]
    A list of Service Endpoints within this subnet.
    virtual_network_name str
    addressPrefix String
    addressPrefixes List<String>
    The address prefixes for the subnet.
    defaultOutboundAccessEnabled Boolean
    Is the default outbound access enabled for the subnet.
    enforcePrivateLinkEndpointNetworkPolicies Boolean
    enforcePrivateLinkServiceNetworkPolicies Boolean
    id String
    The provider-assigned unique ID for this managed resource.
    name String
    networkSecurityGroupId String
    The ID of the Network Security Group associated with the subnet.
    privateEndpointNetworkPolicies String
    Enable or Disable network policies for the private endpoint on the subnet.
    privateEndpointNetworkPoliciesEnabled Boolean

    Deprecated: This property has been superseded by private_endpoint_network_policies and will be removed in v4.0 of the AzureRM Provider.

    privateLinkServiceNetworkPoliciesEnabled Boolean
    Enable or Disable network policies for the private link service on the subnet.
    resourceGroupName String
    routeTableId String
    The ID of the Route Table associated with this subnet.
    serviceEndpoints List<String>
    A list of Service Endpoints within this subnet.
    virtualNetworkName String

    Package Details

    Repository
    Azure Classic pulumi/pulumi-azure
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the azurerm Terraform Provider.
    azure logo

    We recommend using Azure Native.

    Azure Classic v5.81.0 published on Monday, Jun 24, 2024 by Pulumi