1. Registry
  2. Packages
  3. Alibaba Cloud Provider
  4. API Docs
  5. ens
  6. getSecurityGroups
Viewing docs for Alibaba Cloud v3.106.0
published on Monday, Aug 24, 2026 by Pulumi
alicloud logo alicloud logo
Viewing docs for Alibaba Cloud v3.106.0
published on Monday, Aug 24, 2026 by Pulumi

    This data source provides the ENS Security Groups of the current Alibaba Cloud user.

    NOTE: Available since v1.287.0.

    Example Usage

    Basic Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as alicloud from "@pulumi/alicloud";
    
    const _default = alicloud.ens.getSecurityGroups({
        securityGroupName: "tf-example",
        ids: ["sg-xxx"],
    });
    export const firstGroupId = _default.then(_default => _default.groups?.[0]?.id);
    
    import pulumi
    import pulumi_alicloud as alicloud
    
    default = alicloud.ens.get_security_groups(security_group_name="tf-example",
        ids=["sg-xxx"])
    pulumi.export("firstGroupId", default.groups[0].id)
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-alicloud/sdk/v3/go/alicloud/ens"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		_default, err := ens.GetSecurityGroups(ctx, &ens.GetSecurityGroupsArgs{
    			SecurityGroupName: pulumi.StringRef("tf-example"),
    			Ids: []string{
    				"sg-xxx",
    			},
    		}, nil)
    		if err != nil {
    			return err
    		}
    		ctx.Export("firstGroupId", _default.Groups[0].Id)
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using AliCloud = Pulumi.AliCloud;
    
    return await Deployment.RunAsync(() => 
    {
        var @default = AliCloud.Ens.GetSecurityGroups.Invoke(new()
        {
            SecurityGroupName = "tf-example",
            Ids = new[]
            {
                "sg-xxx",
            },
        });
    
        return new Dictionary<string, object?>
        {
            ["firstGroupId"] = @default.Apply(@default => @default.Apply(getSecurityGroupsResult => getSecurityGroupsResult.Groups[0]?.Id)),
        };
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.alicloud.ens.EnsFunctions;
    import com.pulumi.alicloud.ens.inputs.GetSecurityGroupsArgs;
    import java.util.ArrayList;
    import java.util.Arrays;
    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 default = EnsFunctions.getSecurityGroups(GetSecurityGroupsArgs.builder()
                .securityGroupName("tf-example")
                .ids("sg-xxx")
                .build());
    
            ctx.export("firstGroupId", default_.groups()[0].id());
        }
    }
    
    variables:
      default:
        fn::invoke:
          function: alicloud:ens:getSecurityGroups
          arguments:
            securityGroupName: tf-example
            ids:
              - sg-xxx
    outputs:
      firstGroupId: ${default.groups[0].id}
    
    pulumi {
      required_providers {
        alicloud = {
          source = "pulumi/alicloud"
        }
      }
    }
    
    data "alicloud_ens_getsecuritygroups" "default" {
      security_group_name = "tf-example"
      ids                 = ["sg-xxx"]
    }
    
    output "firstGroupId" {
      value = data.alicloud_ens_getsecuritygroups.default.groups[0].id
    }
    

    Using getSecurityGroups

    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 getSecurityGroups(args: GetSecurityGroupsArgs, opts?: InvokeOptions): Promise<GetSecurityGroupsResult>
    function getSecurityGroupsOutput(args: GetSecurityGroupsOutputArgs, opts?: InvokeOutputOptions): Output<GetSecurityGroupsResult>
    def get_security_groups(enable_details: Optional[bool] = None,
                            ids: Optional[Sequence[str]] = None,
                            name_regex: Optional[str] = None,
                            output_file: Optional[str] = None,
                            security_group_id: Optional[str] = None,
                            security_group_name: Optional[str] = None,
                            opts: Optional[InvokeOptions] = None) -> GetSecurityGroupsResult
    def get_security_groups_output(enable_details: pulumi.Input[Optional[bool]] = None,
                            ids: pulumi.Input[Optional[Sequence[pulumi.Input[str]]]] = None,
                            name_regex: pulumi.Input[Optional[str]] = None,
                            output_file: pulumi.Input[Optional[str]] = None,
                            security_group_id: pulumi.Input[Optional[str]] = None,
                            security_group_name: pulumi.Input[Optional[str]] = None,
                            opts: Optional[InvokeOutputOptions] = None) -> Output[GetSecurityGroupsResult]
    func GetSecurityGroups(ctx *Context, args *GetSecurityGroupsArgs, opts ...InvokeOption) (*GetSecurityGroupsResult, error)
    func GetSecurityGroupsOutput(ctx *Context, args *GetSecurityGroupsOutputArgs, opts ...InvokeOption) GetSecurityGroupsResultOutput

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

    public static class GetSecurityGroups 
    {
        public static Task<GetSecurityGroupsResult> InvokeAsync(GetSecurityGroupsArgs args, InvokeOptions? opts = null)
        public static Output<GetSecurityGroupsResult> Invoke(GetSecurityGroupsInvokeArgs args, InvokeOptions? opts = null)
        public static Output<GetSecurityGroupsResult> Invoke(GetSecurityGroupsInvokeArgs args, InvokeOutputOptions opts)
    }
    public static CompletableFuture<GetSecurityGroupsResult> getSecurityGroups(GetSecurityGroupsArgs args, InvokeOptions options)
    public static Output<GetSecurityGroupsResult> getSecurityGroups(GetSecurityGroupsArgs args, InvokeOptions options)
    public static Output<GetSecurityGroupsResult> getSecurityGroups(GetSecurityGroupsArgs args, InvokeOutputOptions options)
    
    fn::invoke:
      function: alicloud:ens/getSecurityGroups:getSecurityGroups
      arguments:
        # arguments dictionary
    data "alicloud_ens_get_security_groups" "name" {
        # arguments
    }

    The following arguments are supported:

    EnableDetails bool
    Default to false. Set it to true to get more details of the security groups.
    Ids List<string>
    A list of Security Group IDs.
    NameRegex string
    A regex string to filter results by Security Group name.
    OutputFile string
    File name where to save data source results (after running pulumi preview).
    SecurityGroupId string
    The ID of the Security Group.
    SecurityGroupName string
    The name of the Security Group.
    EnableDetails bool
    Default to false. Set it to true to get more details of the security groups.
    Ids []string
    A list of Security Group IDs.
    NameRegex string
    A regex string to filter results by Security Group name.
    OutputFile string
    File name where to save data source results (after running pulumi preview).
    SecurityGroupId string
    The ID of the Security Group.
    SecurityGroupName string
    The name of the Security Group.
    enable_details bool
    Default to false. Set it to true to get more details of the security groups.
    ids list(string)
    A list of Security Group IDs.
    name_regex string
    A regex string to filter results by Security Group name.
    output_file string
    File name where to save data source results (after running pulumi preview).
    security_group_id string
    The ID of the Security Group.
    security_group_name string
    The name of the Security Group.
    enableDetails Boolean
    Default to false. Set it to true to get more details of the security groups.
    ids List<String>
    A list of Security Group IDs.
    nameRegex String
    A regex string to filter results by Security Group name.
    outputFile String
    File name where to save data source results (after running pulumi preview).
    securityGroupId String
    The ID of the Security Group.
    securityGroupName String
    The name of the Security Group.
    enableDetails boolean
    Default to false. Set it to true to get more details of the security groups.
    ids string[]
    A list of Security Group IDs.
    nameRegex string
    A regex string to filter results by Security Group name.
    outputFile string
    File name where to save data source results (after running pulumi preview).
    securityGroupId string
    The ID of the Security Group.
    securityGroupName string
    The name of the Security Group.
    enable_details bool
    Default to false. Set it to true to get more details of the security groups.
    ids Sequence[str]
    A list of Security Group IDs.
    name_regex str
    A regex string to filter results by Security Group name.
    output_file str
    File name where to save data source results (after running pulumi preview).
    security_group_id str
    The ID of the Security Group.
    security_group_name str
    The name of the Security Group.
    enableDetails Boolean
    Default to false. Set it to true to get more details of the security groups.
    ids List<String>
    A list of Security Group IDs.
    nameRegex String
    A regex string to filter results by Security Group name.
    outputFile String
    File name where to save data source results (after running pulumi preview).
    securityGroupId String
    The ID of the Security Group.
    securityGroupName String
    The name of the Security Group.

    getSecurityGroups Result

    The following output properties are available:

    Groups List<Pulumi.AliCloud.Ens.Outputs.GetSecurityGroupsGroup>
    A list of Security Groups.
    Id string
    The provider-assigned unique ID for this managed resource.
    Ids List<string>
    A list of Security Group IDs.
    Names List<string>
    A list of Security Group names.
    EnableDetails bool
    NameRegex string
    OutputFile string
    SecurityGroupId string
    The ID of the Security Group.
    SecurityGroupName string
    Security group name.
    Groups []GetSecurityGroupsGroup
    A list of Security Groups.
    Id string
    The provider-assigned unique ID for this managed resource.
    Ids []string
    A list of Security Group IDs.
    Names []string
    A list of Security Group names.
    EnableDetails bool
    NameRegex string
    OutputFile string
    SecurityGroupId string
    The ID of the Security Group.
    SecurityGroupName string
    Security group name.
    groups list(object)
    A list of Security Groups.
    id string
    The provider-assigned unique ID for this managed resource.
    ids list(string)
    A list of Security Group IDs.
    names list(string)
    A list of Security Group names.
    enable_details bool
    name_regex string
    output_file string
    security_group_id string
    The ID of the Security Group.
    security_group_name string
    Security group name.
    groups List<GetSecurityGroupsGroup>
    A list of Security Groups.
    id String
    The provider-assigned unique ID for this managed resource.
    ids List<String>
    A list of Security Group IDs.
    names List<String>
    A list of Security Group names.
    enableDetails Boolean
    nameRegex String
    outputFile String
    securityGroupId String
    The ID of the Security Group.
    securityGroupName String
    Security group name.
    groups GetSecurityGroupsGroup[]
    A list of Security Groups.
    id string
    The provider-assigned unique ID for this managed resource.
    ids string[]
    A list of Security Group IDs.
    names string[]
    A list of Security Group names.
    enableDetails boolean
    nameRegex string
    outputFile string
    securityGroupId string
    The ID of the Security Group.
    securityGroupName string
    Security group name.
    groups Sequence[GetSecurityGroupsGroup]
    A list of Security Groups.
    id str
    The provider-assigned unique ID for this managed resource.
    ids Sequence[str]
    A list of Security Group IDs.
    names Sequence[str]
    A list of Security Group names.
    enable_details bool
    name_regex str
    output_file str
    security_group_id str
    The ID of the Security Group.
    security_group_name str
    Security group name.
    groups List<Property Map>
    A list of Security Groups.
    id String
    The provider-assigned unique ID for this managed resource.
    ids List<String>
    A list of Security Group IDs.
    names List<String>
    A list of Security Group names.
    enableDetails Boolean
    nameRegex String
    outputFile String
    securityGroupId String
    The ID of the Security Group.
    securityGroupName String
    Security group name.

    Supporting Types

    GetSecurityGroupsGroup

    CreateTime string
    Creation time of the security group, UTC time.
    Description string
    Rule description information.
    Id string
    The ID of the Security Group.
    InstanceCount int
    Number of instances associated with a security group.
    Permissions List<Pulumi.AliCloud.Ens.Inputs.GetSecurityGroupsGroupPermission>
    A collection of rules for a security group instance.
    SecurityGroupId string
    The ID of the Security Group.
    SecurityGroupName string
    The name of the Security Group.
    CreateTime string
    Creation time of the security group, UTC time.
    Description string
    Rule description information.
    Id string
    The ID of the Security Group.
    InstanceCount int
    Number of instances associated with a security group.
    Permissions []GetSecurityGroupsGroupPermission
    A collection of rules for a security group instance.
    SecurityGroupId string
    The ID of the Security Group.
    SecurityGroupName string
    The name of the Security Group.
    create_time string
    Creation time of the security group, UTC time.
    description string
    Rule description information.
    id string
    The ID of the Security Group.
    instance_count number
    Number of instances associated with a security group.
    permissions list(object)
    A collection of rules for a security group instance.
    security_group_id string
    The ID of the Security Group.
    security_group_name string
    The name of the Security Group.
    createTime String
    Creation time of the security group, UTC time.
    description String
    Rule description information.
    id String
    The ID of the Security Group.
    instanceCount Integer
    Number of instances associated with a security group.
    permissions List<GetSecurityGroupsGroupPermission>
    A collection of rules for a security group instance.
    securityGroupId String
    The ID of the Security Group.
    securityGroupName String
    The name of the Security Group.
    createTime string
    Creation time of the security group, UTC time.
    description string
    Rule description information.
    id string
    The ID of the Security Group.
    instanceCount number
    Number of instances associated with a security group.
    permissions GetSecurityGroupsGroupPermission[]
    A collection of rules for a security group instance.
    securityGroupId string
    The ID of the Security Group.
    securityGroupName string
    The name of the Security Group.
    create_time str
    Creation time of the security group, UTC time.
    description str
    Rule description information.
    id str
    The ID of the Security Group.
    instance_count int
    Number of instances associated with a security group.
    permissions Sequence[GetSecurityGroupsGroupPermission]
    A collection of rules for a security group instance.
    security_group_id str
    The ID of the Security Group.
    security_group_name str
    The name of the Security Group.
    createTime String
    Creation time of the security group, UTC time.
    description String
    Rule description information.
    id String
    The ID of the Security Group.
    instanceCount Number
    Number of instances associated with a security group.
    permissions List<Property Map>
    A collection of rules for a security group instance.
    securityGroupId String
    The ID of the Security Group.
    securityGroupName String
    The name of the Security Group.

    GetSecurityGroupsGroupPermission

    CreationTime string
    Creation time, UTC time.
    Description string
    Rule description information.
    DestCidrIp string
    Destination IP address segment for outbound authorization.
    Direction string
    Authorized direction.
    IpProtocol string
    IP protocol.
    Ipv6DestCidrIp string
    The target IPv6 address segment.
    Ipv6SourceCidrIp string
    The source IPv6 address segment.
    Policy string
    Authorization Policy.
    PortRange string
    Source end port range.
    Priority int
    Rule Priority.
    SourceCidrIp string
    Source IP address segment, used for inbound authorization.
    SourcePortRange string
    The port range of the source security group.
    CreationTime string
    Creation time, UTC time.
    Description string
    Rule description information.
    DestCidrIp string
    Destination IP address segment for outbound authorization.
    Direction string
    Authorized direction.
    IpProtocol string
    IP protocol.
    Ipv6DestCidrIp string
    The target IPv6 address segment.
    Ipv6SourceCidrIp string
    The source IPv6 address segment.
    Policy string
    Authorization Policy.
    PortRange string
    Source end port range.
    Priority int
    Rule Priority.
    SourceCidrIp string
    Source IP address segment, used for inbound authorization.
    SourcePortRange string
    The port range of the source security group.
    creation_time string
    Creation time, UTC time.
    description string
    Rule description information.
    dest_cidr_ip string
    Destination IP address segment for outbound authorization.
    direction string
    Authorized direction.
    ip_protocol string
    IP protocol.
    ipv6_dest_cidr_ip string
    The target IPv6 address segment.
    ipv6_source_cidr_ip string
    The source IPv6 address segment.
    policy string
    Authorization Policy.
    port_range string
    Source end port range.
    priority number
    Rule Priority.
    source_cidr_ip string
    Source IP address segment, used for inbound authorization.
    source_port_range string
    The port range of the source security group.
    creationTime String
    Creation time, UTC time.
    description String
    Rule description information.
    destCidrIp String
    Destination IP address segment for outbound authorization.
    direction String
    Authorized direction.
    ipProtocol String
    IP protocol.
    ipv6DestCidrIp String
    The target IPv6 address segment.
    ipv6SourceCidrIp String
    The source IPv6 address segment.
    policy String
    Authorization Policy.
    portRange String
    Source end port range.
    priority Integer
    Rule Priority.
    sourceCidrIp String
    Source IP address segment, used for inbound authorization.
    sourcePortRange String
    The port range of the source security group.
    creationTime string
    Creation time, UTC time.
    description string
    Rule description information.
    destCidrIp string
    Destination IP address segment for outbound authorization.
    direction string
    Authorized direction.
    ipProtocol string
    IP protocol.
    ipv6DestCidrIp string
    The target IPv6 address segment.
    ipv6SourceCidrIp string
    The source IPv6 address segment.
    policy string
    Authorization Policy.
    portRange string
    Source end port range.
    priority number
    Rule Priority.
    sourceCidrIp string
    Source IP address segment, used for inbound authorization.
    sourcePortRange string
    The port range of the source security group.
    creation_time str
    Creation time, UTC time.
    description str
    Rule description information.
    dest_cidr_ip str
    Destination IP address segment for outbound authorization.
    direction str
    Authorized direction.
    ip_protocol str
    IP protocol.
    ipv6_dest_cidr_ip str
    The target IPv6 address segment.
    ipv6_source_cidr_ip str
    The source IPv6 address segment.
    policy str
    Authorization Policy.
    port_range str
    Source end port range.
    priority int
    Rule Priority.
    source_cidr_ip str
    Source IP address segment, used for inbound authorization.
    source_port_range str
    The port range of the source security group.
    creationTime String
    Creation time, UTC time.
    description String
    Rule description information.
    destCidrIp String
    Destination IP address segment for outbound authorization.
    direction String
    Authorized direction.
    ipProtocol String
    IP protocol.
    ipv6DestCidrIp String
    The target IPv6 address segment.
    ipv6SourceCidrIp String
    The source IPv6 address segment.
    policy String
    Authorization Policy.
    portRange String
    Source end port range.
    priority Number
    Rule Priority.
    sourceCidrIp String
    Source IP address segment, used for inbound authorization.
    sourcePortRange String
    The port range of the source security group.

    Package Details

    Repository
    Alibaba Cloud pulumi/pulumi-alicloud
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the alicloud Terraform Provider.
    alicloud logo alicloud logo
    Viewing docs for Alibaba Cloud v3.106.0
    published on Monday, Aug 24, 2026 by Pulumi

      Try Pulumi Cloud free.
      Your team will thank you.

      Start free trial