We recommend using Azure Native.
Azure v6.21.0 published on Friday, Mar 7, 2025 by Pulumi
azure.network.getNetworkSecurityGroup
Explore with Pulumi AI
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);
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)
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
	})
}
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),
    };
});
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()));
    }
}
variables:
  example:
    fn::invoke:
      function: azure:network:getNetworkSecurityGroup
      arguments:
        name: example
        resourceGroupName: ${exampleAzurermResourceGroup.name}
outputs:
  location: ${example.location}
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>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]func LookupNetworkSecurityGroup(ctx *Context, args *LookupNetworkSecurityGroupArgs, opts ...InvokeOption) (*LookupNetworkSecurityGroupResult, error)
func LookupNetworkSecurityGroupOutput(ctx *Context, args *LookupNetworkSecurityGroupOutputArgs, opts ...InvokeOption) LookupNetworkSecurityGroupResultOutput> 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)
}public static CompletableFuture<GetNetworkSecurityGroupResult> getNetworkSecurityGroup(GetNetworkSecurityGroupArgs args, InvokeOptions options)
public static Output<GetNetworkSecurityGroupResult> getNetworkSecurityGroup(GetNetworkSecurityGroupArgs args, InvokeOptions options)
fn::invoke:
  function: azure:network/getNetworkSecurityGroup:getNetworkSecurityGroup
  arguments:
    # arguments dictionaryThe following arguments are supported:
- Name string
- Specifies the Name of the Network Security Group.
- ResourceGroup stringName 
- Specifies the Name of the Resource Group within which the Network Security Group exists
- Name string
- Specifies the Name of the Network Security Group.
- ResourceGroup stringName 
- Specifies the Name of the Resource Group within which the Network Security Group exists
- name String
- Specifies the Name of the Network Security Group.
- resourceGroup StringName 
- Specifies the Name of the Resource Group within which the Network Security Group exists
- name string
- Specifies the Name of the Network Security Group.
- resourceGroup stringName 
- Specifies the Name of the Resource Group within which the Network Security Group exists
- name str
- Specifies the Name of the Network Security Group.
- resource_group_ strname 
- Specifies the Name of the Resource Group within which the Network Security Group exists
- name String
- Specifies the Name of the Network Security Group.
- resourceGroup StringName 
- 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.
- ResourceGroup stringName 
- SecurityRules List<GetNetwork Security Group Security Rule> 
- One or more security_ruleblocks as defined below.
- 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.
- ResourceGroup stringName 
- SecurityRules []GetNetwork Security Group Security Rule 
- One or more security_ruleblocks as defined below.
- 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.
- resourceGroup StringName 
- securityRules List<GetNetwork Security Group Security Rule> 
- One or more security_ruleblocks as defined below.
- 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.
- resourceGroup stringName 
- securityRules GetNetwork Security Group Security Rule[] 
- One or more security_ruleblocks as defined below.
- {[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_ strname 
- security_rules Sequence[GetNetwork Security Group Security Rule] 
- One or more security_ruleblocks as defined below.
- 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.
- resourceGroup StringName 
- securityRules List<Property Map>
- One or more security_ruleblocks as defined below.
- Map<String>
- A mapping of tags assigned to the resource.
Supporting Types
GetNetworkSecurityGroupSecurityRule     
- Access string
- Is network traffic is allowed or denied?
- Description string
- The description for this rule.
- DestinationAddress stringPrefix 
- CIDR or destination IP range or * to match any IP.
- DestinationAddress List<string>Prefixes 
- A list of CIDRs or destination IP ranges.
- DestinationPort stringRange 
- The Destination Port or Range.
- DestinationPort List<string>Ranges 
- Direction string
- The direction specifies if rule will be evaluated on incoming or outgoing traffic.
- Name string
- Specifies the Name of the Network Security Group.
- Priority int
- The priority of the rule
- Protocol string
- The network protocol this rule applies to.
- SourceAddress stringPrefix 
- CIDR or source IP range or * to match any IP.
- SourceAddress List<string>Prefixes 
- A list of CIDRs or source IP ranges.
- SourcePort stringRange 
- The Source Port or Range.
- SourcePort List<string>Ranges 
- DestinationApplication List<string>Security Group Ids 
- A List of destination Application Security Group IDs
- SourceApplication List<string>Security Group Ids 
- A List of source Application Security Group IDs
- Access string
- Is network traffic is allowed or denied?
- Description string
- The description for this rule.
- DestinationAddress stringPrefix 
- CIDR or destination IP range or * to match any IP.
- DestinationAddress []stringPrefixes 
- A list of CIDRs or destination IP ranges.
- DestinationPort stringRange 
- The Destination Port or Range.
- DestinationPort []stringRanges 
- Direction string
- The direction specifies if rule will be evaluated on incoming or outgoing traffic.
- Name string
- Specifies the Name of the Network Security Group.
- Priority int
- The priority of the rule
- Protocol string
- The network protocol this rule applies to.
- SourceAddress stringPrefix 
- CIDR or source IP range or * to match any IP.
- SourceAddress []stringPrefixes 
- A list of CIDRs or source IP ranges.
- SourcePort stringRange 
- The Source Port or Range.
- SourcePort []stringRanges 
- DestinationApplication []stringSecurity Group Ids 
- A List of destination Application Security Group IDs
- SourceApplication []stringSecurity Group Ids 
- A List of source Application Security Group IDs
- access String
- Is network traffic is allowed or denied?
- description String
- The description for this rule.
- destinationAddress StringPrefix 
- CIDR or destination IP range or * to match any IP.
- destinationAddress List<String>Prefixes 
- A list of CIDRs or destination IP ranges.
- destinationPort StringRange 
- The Destination Port or Range.
- destinationPort List<String>Ranges 
- direction String
- The direction specifies if rule will be evaluated on incoming or outgoing traffic.
- name String
- Specifies the Name of the Network Security Group.
- priority Integer
- The priority of the rule
- protocol String
- The network protocol this rule applies to.
- sourceAddress StringPrefix 
- CIDR or source IP range or * to match any IP.
- sourceAddress List<String>Prefixes 
- A list of CIDRs or source IP ranges.
- sourcePort StringRange 
- The Source Port or Range.
- sourcePort List<String>Ranges 
- destinationApplication List<String>Security Group Ids 
- A List of destination Application Security Group IDs
- sourceApplication List<String>Security Group Ids 
- A List of source Application Security Group IDs
- access string
- Is network traffic is allowed or denied?
- description string
- The description for this rule.
- destinationAddress stringPrefix 
- CIDR or destination IP range or * to match any IP.
- destinationAddress string[]Prefixes 
- A list of CIDRs or destination IP ranges.
- destinationPort stringRange 
- The Destination Port or Range.
- destinationPort string[]Ranges 
- direction string
- The direction specifies if rule will be evaluated on incoming or outgoing traffic.
- name string
- Specifies the Name of the Network Security Group.
- priority number
- The priority of the rule
- protocol string
- The network protocol this rule applies to.
- sourceAddress stringPrefix 
- CIDR or source IP range or * to match any IP.
- sourceAddress string[]Prefixes 
- A list of CIDRs or source IP ranges.
- sourcePort stringRange 
- The Source Port or Range.
- sourcePort string[]Ranges 
- destinationApplication string[]Security Group Ids 
- A List of destination Application Security Group IDs
- sourceApplication string[]Security Group Ids 
- A List of source Application Security Group IDs
- access str
- Is network traffic is allowed or denied?
- description str
- The description for this rule.
- destination_address_ strprefix 
- CIDR or destination IP range or * to match any IP.
- destination_address_ Sequence[str]prefixes 
- A list of CIDRs or destination IP ranges.
- destination_port_ strrange 
- The Destination Port or Range.
- destination_port_ Sequence[str]ranges 
- direction str
- The direction specifies if rule will be evaluated on incoming or outgoing traffic.
- name str
- Specifies the Name of the Network Security Group.
- priority int
- The priority of the rule
- protocol str
- The network protocol this rule applies to.
- source_address_ strprefix 
- CIDR or source IP range or * to match any IP.
- source_address_ Sequence[str]prefixes 
- A list of CIDRs or source IP ranges.
- source_port_ strrange 
- The Source Port or Range.
- source_port_ Sequence[str]ranges 
- destination_application_ Sequence[str]security_ group_ ids 
- A List of destination Application Security Group IDs
- source_application_ Sequence[str]security_ group_ ids 
- A List of source Application Security Group IDs
- access String
- Is network traffic is allowed or denied?
- description String
- The description for this rule.
- destinationAddress StringPrefix 
- CIDR or destination IP range or * to match any IP.
- destinationAddress List<String>Prefixes 
- A list of CIDRs or destination IP ranges.
- destinationPort StringRange 
- The Destination Port or Range.
- destinationPort List<String>Ranges 
- direction String
- The direction specifies if rule will be evaluated on incoming or outgoing traffic.
- name String
- Specifies the Name of the Network Security Group.
- priority Number
- The priority of the rule
- protocol String
- The network protocol this rule applies to.
- sourceAddress StringPrefix 
- CIDR or source IP range or * to match any IP.
- sourceAddress List<String>Prefixes 
- A list of CIDRs or source IP ranges.
- sourcePort StringRange 
- The Source Port or Range.
- sourcePort List<String>Ranges 
- destinationApplication List<String>Security Group Ids 
- A List of destination Application Security Group IDs
- sourceApplication List<String>Security Group Ids 
- 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 azurermTerraform Provider.