github.com/pulumi/pulumi-aws/sdk/v6@v6.32.0/go/aws/ec2/getSecurityGroup.go (about)

     1  // Code generated by the Pulumi Terraform Bridge (tfgen) Tool DO NOT EDIT.
     2  // *** WARNING: Do not edit by hand unless you're certain you know what you are doing! ***
     3  
     4  package ec2
     5  
     6  import (
     7  	"context"
     8  	"reflect"
     9  
    10  	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/internal"
    11  	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    12  )
    13  
    14  // `ec2.SecurityGroup` provides details about a specific Security Group.
    15  //
    16  // This resource can prove useful when a module accepts a Security Group id as
    17  // an input variable and needs to, for example, determine the id of the
    18  // VPC that the security group belongs to.
    19  //
    20  // ## Example Usage
    21  //
    22  // The following example shows how one might accept a Security Group id as a variable
    23  // and use this data source to obtain the data necessary to create a subnet.
    24  //
    25  // <!--Start PulumiCodeChooser -->
    26  // ```go
    27  // package main
    28  //
    29  // import (
    30  //
    31  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ec2"
    32  //	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    33  //	"github.com/pulumi/pulumi/sdk/v3/go/pulumi/config"
    34  //
    35  // )
    36  //
    37  //	func main() {
    38  //		pulumi.Run(func(ctx *pulumi.Context) error {
    39  //			cfg := config.New(ctx, "")
    40  //			securityGroupId := cfg.RequireObject("securityGroupId")
    41  //			selected, err := ec2.LookupSecurityGroup(ctx, &ec2.LookupSecurityGroupArgs{
    42  //				Id: pulumi.StringRef(securityGroupId),
    43  //			}, nil)
    44  //			if err != nil {
    45  //				return err
    46  //			}
    47  //			_, err = ec2.NewSubnet(ctx, "subnet", &ec2.SubnetArgs{
    48  //				VpcId:     pulumi.String(selected.VpcId),
    49  //				CidrBlock: pulumi.String("10.0.1.0/24"),
    50  //			})
    51  //			if err != nil {
    52  //				return err
    53  //			}
    54  //			return nil
    55  //		})
    56  //	}
    57  //
    58  // ```
    59  // <!--End PulumiCodeChooser -->
    60  func LookupSecurityGroup(ctx *pulumi.Context, args *LookupSecurityGroupArgs, opts ...pulumi.InvokeOption) (*LookupSecurityGroupResult, error) {
    61  	opts = internal.PkgInvokeDefaultOpts(opts)
    62  	var rv LookupSecurityGroupResult
    63  	err := ctx.Invoke("aws:ec2/getSecurityGroup:getSecurityGroup", args, &rv, opts...)
    64  	if err != nil {
    65  		return nil, err
    66  	}
    67  	return &rv, nil
    68  }
    69  
    70  // A collection of arguments for invoking getSecurityGroup.
    71  type LookupSecurityGroupArgs struct {
    72  	// Custom filter block as described below.
    73  	Filters []GetSecurityGroupFilter `pulumi:"filters"`
    74  	// Id of the specific security group to retrieve.
    75  	Id *string `pulumi:"id"`
    76  	// Name of the field to filter by, as defined by
    77  	// [the underlying AWS API](http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeSecurityGroups.html).
    78  	Name *string `pulumi:"name"`
    79  	// Map of tags, each pair of which must exactly match
    80  	// a pair on the desired security group.
    81  	Tags map[string]string `pulumi:"tags"`
    82  	// Id of the VPC that the desired security group belongs to.
    83  	//
    84  	// More complex filters can be expressed using one or more `filter` sub-blocks,
    85  	// which take the following arguments:
    86  	VpcId *string `pulumi:"vpcId"`
    87  }
    88  
    89  // A collection of values returned by getSecurityGroup.
    90  type LookupSecurityGroupResult struct {
    91  	// Computed ARN of the security group.
    92  	Arn string `pulumi:"arn"`
    93  	// Description of the security group.
    94  	Description string                   `pulumi:"description"`
    95  	Filters     []GetSecurityGroupFilter `pulumi:"filters"`
    96  	Id          string                   `pulumi:"id"`
    97  	Name        string                   `pulumi:"name"`
    98  	Tags        map[string]string        `pulumi:"tags"`
    99  	VpcId       string                   `pulumi:"vpcId"`
   100  }
   101  
   102  func LookupSecurityGroupOutput(ctx *pulumi.Context, args LookupSecurityGroupOutputArgs, opts ...pulumi.InvokeOption) LookupSecurityGroupResultOutput {
   103  	return pulumi.ToOutputWithContext(context.Background(), args).
   104  		ApplyT(func(v interface{}) (LookupSecurityGroupResult, error) {
   105  			args := v.(LookupSecurityGroupArgs)
   106  			r, err := LookupSecurityGroup(ctx, &args, opts...)
   107  			var s LookupSecurityGroupResult
   108  			if r != nil {
   109  				s = *r
   110  			}
   111  			return s, err
   112  		}).(LookupSecurityGroupResultOutput)
   113  }
   114  
   115  // A collection of arguments for invoking getSecurityGroup.
   116  type LookupSecurityGroupOutputArgs struct {
   117  	// Custom filter block as described below.
   118  	Filters GetSecurityGroupFilterArrayInput `pulumi:"filters"`
   119  	// Id of the specific security group to retrieve.
   120  	Id pulumi.StringPtrInput `pulumi:"id"`
   121  	// Name of the field to filter by, as defined by
   122  	// [the underlying AWS API](http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeSecurityGroups.html).
   123  	Name pulumi.StringPtrInput `pulumi:"name"`
   124  	// Map of tags, each pair of which must exactly match
   125  	// a pair on the desired security group.
   126  	Tags pulumi.StringMapInput `pulumi:"tags"`
   127  	// Id of the VPC that the desired security group belongs to.
   128  	//
   129  	// More complex filters can be expressed using one or more `filter` sub-blocks,
   130  	// which take the following arguments:
   131  	VpcId pulumi.StringPtrInput `pulumi:"vpcId"`
   132  }
   133  
   134  func (LookupSecurityGroupOutputArgs) ElementType() reflect.Type {
   135  	return reflect.TypeOf((*LookupSecurityGroupArgs)(nil)).Elem()
   136  }
   137  
   138  // A collection of values returned by getSecurityGroup.
   139  type LookupSecurityGroupResultOutput struct{ *pulumi.OutputState }
   140  
   141  func (LookupSecurityGroupResultOutput) ElementType() reflect.Type {
   142  	return reflect.TypeOf((*LookupSecurityGroupResult)(nil)).Elem()
   143  }
   144  
   145  func (o LookupSecurityGroupResultOutput) ToLookupSecurityGroupResultOutput() LookupSecurityGroupResultOutput {
   146  	return o
   147  }
   148  
   149  func (o LookupSecurityGroupResultOutput) ToLookupSecurityGroupResultOutputWithContext(ctx context.Context) LookupSecurityGroupResultOutput {
   150  	return o
   151  }
   152  
   153  // Computed ARN of the security group.
   154  func (o LookupSecurityGroupResultOutput) Arn() pulumi.StringOutput {
   155  	return o.ApplyT(func(v LookupSecurityGroupResult) string { return v.Arn }).(pulumi.StringOutput)
   156  }
   157  
   158  // Description of the security group.
   159  func (o LookupSecurityGroupResultOutput) Description() pulumi.StringOutput {
   160  	return o.ApplyT(func(v LookupSecurityGroupResult) string { return v.Description }).(pulumi.StringOutput)
   161  }
   162  
   163  func (o LookupSecurityGroupResultOutput) Filters() GetSecurityGroupFilterArrayOutput {
   164  	return o.ApplyT(func(v LookupSecurityGroupResult) []GetSecurityGroupFilter { return v.Filters }).(GetSecurityGroupFilterArrayOutput)
   165  }
   166  
   167  func (o LookupSecurityGroupResultOutput) Id() pulumi.StringOutput {
   168  	return o.ApplyT(func(v LookupSecurityGroupResult) string { return v.Id }).(pulumi.StringOutput)
   169  }
   170  
   171  func (o LookupSecurityGroupResultOutput) Name() pulumi.StringOutput {
   172  	return o.ApplyT(func(v LookupSecurityGroupResult) string { return v.Name }).(pulumi.StringOutput)
   173  }
   174  
   175  func (o LookupSecurityGroupResultOutput) Tags() pulumi.StringMapOutput {
   176  	return o.ApplyT(func(v LookupSecurityGroupResult) map[string]string { return v.Tags }).(pulumi.StringMapOutput)
   177  }
   178  
   179  func (o LookupSecurityGroupResultOutput) VpcId() pulumi.StringOutput {
   180  	return o.ApplyT(func(v LookupSecurityGroupResult) string { return v.VpcId }).(pulumi.StringOutput)
   181  }
   182  
   183  func init() {
   184  	pulumi.RegisterOutputType(LookupSecurityGroupResultOutput{})
   185  }