getSecurityGroup

aws.ec2.SecurityGroup provides details about a specific Security Group.

This resource can prove useful when a module accepts a Security Group id as an input variable and needs to, for example, determine the id of the VPC that the security group belongs to.

Example Usage

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
    public MyStack()
    {
        var config = new Config();
        var securityGroupId = config.RequireObject<dynamic>("securityGroupId");
        var selected = Output.Create(Aws.Ec2.GetSecurityGroup.InvokeAsync(new Aws.Ec2.GetSecurityGroupArgs
        {
            Id = securityGroupId,
        }));
        var subnet = new Aws.Ec2.Subnet("subnet", new Aws.Ec2.SubnetArgs
        {
            VpcId = selected.Apply(selected => selected.VpcId),
            CidrBlock = "10.0.1.0/24",
        });
    }

}
package main

import (
	"github.com/pulumi/pulumi-aws/sdk/v4/go/aws/ec2"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi/config"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		cfg := config.New(ctx, "")
		securityGroupId := cfg.RequireObject("securityGroupId")
		opt0 := securityGroupId
		selected, err := ec2.LookupSecurityGroup(ctx, &ec2.LookupSecurityGroupArgs{
			Id: &opt0,
		}, nil)
		if err != nil {
			return err
		}
		_, err = ec2.NewSubnet(ctx, "subnet", &ec2.SubnetArgs{
			VpcId:     pulumi.String(selected.VpcId),
			CidrBlock: pulumi.String("10.0.1.0/24"),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
import pulumi
import pulumi_aws as aws

config = pulumi.Config()
security_group_id = config.require_object("securityGroupId")
selected = aws.ec2.get_security_group(id=security_group_id)
subnet = aws.ec2.Subnet("subnet",
    vpc_id=selected.vpc_id,
    cidr_block="10.0.1.0/24")
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const config = new pulumi.Config();
const securityGroupId = config.requireObject("securityGroupId");
const selected = aws.ec2.getSecurityGroup({
    id: securityGroupId,
});
const subnet = new aws.ec2.Subnet("subnet", {
    vpcId: selected.then(selected => selected.vpcId),
    cidrBlock: "10.0.1.0/24",
});

Using getSecurityGroup

function getSecurityGroup(args: GetSecurityGroupArgs, opts?: InvokeOptions): Promise<GetSecurityGroupResult>
def get_security_group(filters: Optional[Sequence[GetSecurityGroupFilter]] = None,
                       id: Optional[str] = None,
                       name: Optional[str] = None,
                       tags: Optional[Mapping[str, str]] = None,
                       vpc_id: Optional[str] = None,
                       opts: Optional[InvokeOptions] = None) -> GetSecurityGroupResult
func LookupSecurityGroup(ctx *Context, args *LookupSecurityGroupArgs, opts ...InvokeOption) (*LookupSecurityGroupResult, error)

Note: This function is named LookupSecurityGroup in the Go SDK.

public static class GetSecurityGroup {
    public static Task<GetSecurityGroupResult> InvokeAsync(GetSecurityGroupArgs args, InvokeOptions? opts = null)
}

The following arguments are supported:

Filters List<GetSecurityGroupFilter>
Custom filter block as described below.
Id string
The id of the specific security group to retrieve.
Name string
The name of the field to filter by, as defined by the underlying AWS API.
Tags Dictionary<string, string>
A map of tags, each pair of which must exactly match a pair on the desired security group.
VpcId string
The id of the VPC that the desired security group belongs to.
Filters []GetSecurityGroupFilter
Custom filter block as described below.
Id string
The id of the specific security group to retrieve.
Name string
The name of the field to filter by, as defined by the underlying AWS API.
Tags map[string]string
A map of tags, each pair of which must exactly match a pair on the desired security group.
VpcId string
The id of the VPC that the desired security group belongs to.
filters GetSecurityGroupFilter[]
Custom filter block as described below.
id string
The id of the specific security group to retrieve.
name string
The name of the field to filter by, as defined by the underlying AWS API.
tags {[key: string]: string}
A map of tags, each pair of which must exactly match a pair on the desired security group.
vpcId string
The id of the VPC that the desired security group belongs to.
filters Sequence[GetSecurityGroupFilter]
Custom filter block as described below.
id str
The id of the specific security group to retrieve.
name str
The name of the field to filter by, as defined by the underlying AWS API.
tags Mapping[str, str]
A map of tags, each pair of which must exactly match a pair on the desired security group.
vpc_id str
The id of the VPC that the desired security group belongs to.

getSecurityGroup Result

The following output properties are available:

Arn string
The computed ARN of the security group.
Description string
The description of the security group.
Id string
Name string
Tags Dictionary<string, string>
VpcId string
Filters List<GetSecurityGroupFilter>
Arn string
The computed ARN of the security group.
Description string
The description of the security group.
Id string
Name string
Tags map[string]string
VpcId string
Filters []GetSecurityGroupFilter
arn string
The computed ARN of the security group.
description string
The description of the security group.
id string
name string
tags {[key: string]: string}
vpcId string
filters GetSecurityGroupFilter[]
arn str
The computed ARN of the security group.
description str
The description of the security group.
id str
name str
tags Mapping[str, str]
vpc_id str
filters Sequence[GetSecurityGroupFilter]

Supporting Types

GetSecurityGroupFilter

Name string
The name of the field to filter by, as defined by the underlying AWS API.
Values List<string>
Set of values that are accepted for the given field. A Security Group will be selected if any one of the given values matches.
Name string
The name of the field to filter by, as defined by the underlying AWS API.
Values []string
Set of values that are accepted for the given field. A Security Group will be selected if any one of the given values matches.
name string
The name of the field to filter by, as defined by the underlying AWS API.
values string[]
Set of values that are accepted for the given field. A Security Group will be selected if any one of the given values matches.
name str
The name of the field to filter by, as defined by the underlying AWS API.
values Sequence[str]
Set of values that are accepted for the given field. A Security Group will be selected if any one of the given values matches.

Package Details

Repository
https://github.com/pulumi/pulumi-aws
License
Apache-2.0
Notes
This Pulumi package is based on the aws Terraform Provider.