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

We recommend using Azure Native.

Azure v6.22.0 published on Tuesday, Apr 1, 2025 by Pulumi

azure.network.getNetworkSecurityGroup

Explore with Pulumi AI

We recommend using Azure Native.

Azure v6.22.0 published on Tuesday, Apr 1, 2025 by Pulumi

Use this data source to access information about an existing Network Security Group.

Example Usage

import * as pulumi from "@pulumi/pulumi";
import * as azure from "@pulumi/azure";

const example = azure.network.getNetworkSecurityGroup({
    name: "example",
    resourceGroupName: exampleAzurermResourceGroup.name,
});
export const location = example.then(example => example.location);
Copy
import pulumi
import pulumi_azure as azure

example = azure.network.get_network_security_group(name="example",
    resource_group_name=example_azurerm_resource_group["name"])
pulumi.export("location", example.location)
Copy
package main

import (
	"github.com/pulumi/pulumi-azure/sdk/v6/go/azure/network"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		example, err := network.LookupNetworkSecurityGroup(ctx, &network.LookupNetworkSecurityGroupArgs{
			Name:              "example",
			ResourceGroupName: exampleAzurermResourceGroup.Name,
		}, nil)
		if err != nil {
			return err
		}
		ctx.Export("location", example.Location)
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Azure = Pulumi.Azure;

return await Deployment.RunAsync(() => 
{
    var example = Azure.Network.GetNetworkSecurityGroup.Invoke(new()
    {
        Name = "example",
        ResourceGroupName = exampleAzurermResourceGroup.Name,
    });

    return new Dictionary<string, object?>
    {
        ["location"] = example.Apply(getNetworkSecurityGroupResult => getNetworkSecurityGroupResult.Location),
    };
});
Copy
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.GetNetworkSecurityGroupArgs;
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.getNetworkSecurityGroup(GetNetworkSecurityGroupArgs.builder()
            .name("example")
            .resourceGroupName(exampleAzurermResourceGroup.name())
            .build());

        ctx.export("location", example.applyValue(getNetworkSecurityGroupResult -> getNetworkSecurityGroupResult.location()));
    }
}
Copy
variables:
  example:
    fn::invoke:
      function: azure:network:getNetworkSecurityGroup
      arguments:
        name: example
        resourceGroupName: ${exampleAzurermResourceGroup.name}
outputs:
  location: ${example.location}
Copy

Using getNetworkSecurityGroup

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 getNetworkSecurityGroup(args: GetNetworkSecurityGroupArgs, opts?: InvokeOptions): Promise<GetNetworkSecurityGroupResult>
function getNetworkSecurityGroupOutput(args: GetNetworkSecurityGroupOutputArgs, opts?: InvokeOptions): Output<GetNetworkSecurityGroupResult>
Copy
def get_network_security_group(name: Optional[str] = None,
                               resource_group_name: Optional[str] = None,
                               opts: Optional[InvokeOptions] = None) -> GetNetworkSecurityGroupResult
def get_network_security_group_output(name: Optional[pulumi.Input[str]] = None,
                               resource_group_name: Optional[pulumi.Input[str]] = None,
                               opts: Optional[InvokeOptions] = None) -> Output[GetNetworkSecurityGroupResult]
Copy
func LookupNetworkSecurityGroup(ctx *Context, args *LookupNetworkSecurityGroupArgs, opts ...InvokeOption) (*LookupNetworkSecurityGroupResult, error)
func LookupNetworkSecurityGroupOutput(ctx *Context, args *LookupNetworkSecurityGroupOutputArgs, opts ...InvokeOption) LookupNetworkSecurityGroupResultOutput
Copy

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

public static class GetNetworkSecurityGroup 
{
    public static Task<GetNetworkSecurityGroupResult> InvokeAsync(GetNetworkSecurityGroupArgs args, InvokeOptions? opts = null)
    public static Output<GetNetworkSecurityGroupResult> Invoke(GetNetworkSecurityGroupInvokeArgs args, InvokeOptions? opts = null)
}
Copy
public static CompletableFuture<GetNetworkSecurityGroupResult> getNetworkSecurityGroup(GetNetworkSecurityGroupArgs args, InvokeOptions options)
public static Output<GetNetworkSecurityGroupResult> getNetworkSecurityGroup(GetNetworkSecurityGroupArgs args, InvokeOptions options)
Copy
fn::invoke:
  function: azure:network/getNetworkSecurityGroup:getNetworkSecurityGroup
  arguments:
    # arguments dictionary
Copy

The following arguments are supported:

Name This property is required. string
Specifies the Name of the Network Security Group.
ResourceGroupName This property is required. string
Specifies the Name of the Resource Group within which the Network Security Group exists
Name This property is required. string
Specifies the Name of the Network Security Group.
ResourceGroupName This property is required. string
Specifies the Name of the Resource Group within which the Network Security Group exists
name This property is required. String
Specifies the Name of the Network Security Group.
resourceGroupName This property is required. String
Specifies the Name of the Resource Group within which the Network Security Group exists
name This property is required. string
Specifies the Name of the Network Security Group.
resourceGroupName This property is required. string
Specifies the Name of the Resource Group within which the Network Security Group exists
name This property is required. str
Specifies the Name of the Network Security Group.
resource_group_name This property is required. str
Specifies the Name of the Resource Group within which the Network Security Group exists
name This property is required. String
Specifies the Name of the Network Security Group.
resourceGroupName This property is required. String
Specifies the Name of the Resource Group within which the Network Security Group exists

getNetworkSecurityGroup Result

The following output properties are available:

Id string
The provider-assigned unique ID for this managed resource.
Location string
The supported Azure location where the resource exists.
Name string
The name of the security rule.
ResourceGroupName string
SecurityRules List<GetNetworkSecurityGroupSecurityRule>
One or more security_rule blocks as defined below.
Tags Dictionary<string, string>
A mapping of tags assigned to the resource.
Id string
The provider-assigned unique ID for this managed resource.
Location string
The supported Azure location where the resource exists.
Name string
The name of the security rule.
ResourceGroupName string
SecurityRules []GetNetworkSecurityGroupSecurityRule
One or more security_rule blocks as defined below.
Tags map[string]string
A mapping of tags assigned to the resource.
id String
The provider-assigned unique ID for this managed resource.
location String
The supported Azure location where the resource exists.
name String
The name of the security rule.
resourceGroupName String
securityRules List<GetNetworkSecurityGroupSecurityRule>
One or more security_rule blocks as defined below.
tags Map<String,String>
A mapping of tags assigned to the resource.
id string
The provider-assigned unique ID for this managed resource.
location string
The supported Azure location where the resource exists.
name string
The name of the security rule.
resourceGroupName string
securityRules GetNetworkSecurityGroupSecurityRule[]
One or more security_rule blocks as defined below.
tags {[key: string]: string}
A mapping of tags assigned to the resource.
id str
The provider-assigned unique ID for this managed resource.
location str
The supported Azure location where the resource exists.
name str
The name of the security rule.
resource_group_name str
security_rules Sequence[GetNetworkSecurityGroupSecurityRule]
One or more security_rule blocks as defined below.
tags Mapping[str, str]
A mapping of tags assigned to the resource.
id String
The provider-assigned unique ID for this managed resource.
location String
The supported Azure location where the resource exists.
name String
The name of the security rule.
resourceGroupName String
securityRules List<Property Map>
One or more security_rule blocks as defined below.
tags Map<String>
A mapping of tags assigned to the resource.

Supporting Types

GetNetworkSecurityGroupSecurityRule

Access This property is required. string
Is network traffic is allowed or denied?
Description This property is required. string
The description for this rule.
DestinationAddressPrefix This property is required. string
CIDR or destination IP range or * to match any IP.
DestinationAddressPrefixes This property is required. List<string>
A list of CIDRs or destination IP ranges.
DestinationPortRange This property is required. string
The Destination Port or Range.
DestinationPortRanges This property is required. List<string>
Direction This property is required. string
The direction specifies if rule will be evaluated on incoming or outgoing traffic.
Name This property is required. string
Specifies the Name of the Network Security Group.
Priority This property is required. int
The priority of the rule
Protocol This property is required. string
The network protocol this rule applies to.
SourceAddressPrefix This property is required. string
CIDR or source IP range or * to match any IP.
SourceAddressPrefixes This property is required. List<string>
A list of CIDRs or source IP ranges.
SourcePortRange This property is required. string
The Source Port or Range.
SourcePortRanges This property is required. List<string>
DestinationApplicationSecurityGroupIds List<string>
A List of destination Application Security Group IDs
SourceApplicationSecurityGroupIds List<string>
A List of source Application Security Group IDs
Access This property is required. string
Is network traffic is allowed or denied?
Description This property is required. string
The description for this rule.
DestinationAddressPrefix This property is required. string
CIDR or destination IP range or * to match any IP.
DestinationAddressPrefixes This property is required. []string
A list of CIDRs or destination IP ranges.
DestinationPortRange This property is required. string
The Destination Port or Range.
DestinationPortRanges This property is required. []string
Direction This property is required. string
The direction specifies if rule will be evaluated on incoming or outgoing traffic.
Name This property is required. string
Specifies the Name of the Network Security Group.
Priority This property is required. int
The priority of the rule
Protocol This property is required. string
The network protocol this rule applies to.
SourceAddressPrefix This property is required. string
CIDR or source IP range or * to match any IP.
SourceAddressPrefixes This property is required. []string
A list of CIDRs or source IP ranges.
SourcePortRange This property is required. string
The Source Port or Range.
SourcePortRanges This property is required. []string
DestinationApplicationSecurityGroupIds []string
A List of destination Application Security Group IDs
SourceApplicationSecurityGroupIds []string
A List of source Application Security Group IDs
access This property is required. String
Is network traffic is allowed or denied?
description This property is required. String
The description for this rule.
destinationAddressPrefix This property is required. String
CIDR or destination IP range or * to match any IP.
destinationAddressPrefixes This property is required. List<String>
A list of CIDRs or destination IP ranges.
destinationPortRange This property is required. String
The Destination Port or Range.
destinationPortRanges This property is required. List<String>
direction This property is required. String
The direction specifies if rule will be evaluated on incoming or outgoing traffic.
name This property is required. String
Specifies the Name of the Network Security Group.
priority This property is required. Integer
The priority of the rule
protocol This property is required. String
The network protocol this rule applies to.
sourceAddressPrefix This property is required. String
CIDR or source IP range or * to match any IP.
sourceAddressPrefixes This property is required. List<String>
A list of CIDRs or source IP ranges.
sourcePortRange This property is required. String
The Source Port or Range.
sourcePortRanges This property is required. List<String>
destinationApplicationSecurityGroupIds List<String>
A List of destination Application Security Group IDs
sourceApplicationSecurityGroupIds List<String>
A List of source Application Security Group IDs
access This property is required. string
Is network traffic is allowed or denied?
description This property is required. string
The description for this rule.
destinationAddressPrefix This property is required. string
CIDR or destination IP range or * to match any IP.
destinationAddressPrefixes This property is required. string[]
A list of CIDRs or destination IP ranges.
destinationPortRange This property is required. string
The Destination Port or Range.
destinationPortRanges This property is required. string[]
direction This property is required. string
The direction specifies if rule will be evaluated on incoming or outgoing traffic.
name This property is required. string
Specifies the Name of the Network Security Group.
priority This property is required. number
The priority of the rule
protocol This property is required. string
The network protocol this rule applies to.
sourceAddressPrefix This property is required. string
CIDR or source IP range or * to match any IP.
sourceAddressPrefixes This property is required. string[]
A list of CIDRs or source IP ranges.
sourcePortRange This property is required. string
The Source Port or Range.
sourcePortRanges This property is required. string[]
destinationApplicationSecurityGroupIds string[]
A List of destination Application Security Group IDs
sourceApplicationSecurityGroupIds string[]
A List of source Application Security Group IDs
access This property is required. str
Is network traffic is allowed or denied?
description This property is required. str
The description for this rule.
destination_address_prefix This property is required. str
CIDR or destination IP range or * to match any IP.
destination_address_prefixes This property is required. Sequence[str]
A list of CIDRs or destination IP ranges.
destination_port_range This property is required. str
The Destination Port or Range.
destination_port_ranges This property is required. Sequence[str]
direction This property is required. str
The direction specifies if rule will be evaluated on incoming or outgoing traffic.
name This property is required. str
Specifies the Name of the Network Security Group.
priority This property is required. int
The priority of the rule
protocol This property is required. str
The network protocol this rule applies to.
source_address_prefix This property is required. str
CIDR or source IP range or * to match any IP.
source_address_prefixes This property is required. Sequence[str]
A list of CIDRs or source IP ranges.
source_port_range This property is required. str
The Source Port or Range.
source_port_ranges This property is required. Sequence[str]
destination_application_security_group_ids Sequence[str]
A List of destination Application Security Group IDs
source_application_security_group_ids Sequence[str]
A List of source Application Security Group IDs
access This property is required. String
Is network traffic is allowed or denied?
description This property is required. String
The description for this rule.
destinationAddressPrefix This property is required. String
CIDR or destination IP range or * to match any IP.
destinationAddressPrefixes This property is required. List<String>
A list of CIDRs or destination IP ranges.
destinationPortRange This property is required. String
The Destination Port or Range.
destinationPortRanges This property is required. List<String>
direction This property is required. String
The direction specifies if rule will be evaluated on incoming or outgoing traffic.
name This property is required. String
Specifies the Name of the Network Security Group.
priority This property is required. Number
The priority of the rule
protocol This property is required. String
The network protocol this rule applies to.
sourceAddressPrefix This property is required. String
CIDR or source IP range or * to match any IP.
sourceAddressPrefixes This property is required. List<String>
A list of CIDRs or source IP ranges.
sourcePortRange This property is required. String
The Source Port or Range.
sourcePortRanges This property is required. List<String>
destinationApplicationSecurityGroupIds List<String>
A List of destination Application Security Group IDs
sourceApplicationSecurityGroupIds List<String>
A List of source Application Security Group IDs

Package Details

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

We recommend using Azure Native.

Azure v6.22.0 published on Tuesday, Apr 1, 2025 by Pulumi