github.com/pulumi/pulumi-aws/sdk/v6@v6.32.0/go/aws/ec2/getSubnet.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.Subnet` provides details about a specific VPC subnet.
    15  //
    16  // This resource can prove useful when a module accepts a subnet ID as an input variable and needs to, for example, determine the ID of the VPC that the subnet belongs to.
    17  //
    18  // ## Example Usage
    19  //
    20  // The following example shows how one might accept a subnet ID as a variable and use this data source to obtain the data necessary to create a security group that allows connections from hosts in that subnet.
    21  //
    22  // <!--Start PulumiCodeChooser -->
    23  // ```go
    24  // package main
    25  //
    26  // import (
    27  //
    28  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ec2"
    29  //	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    30  //	"github.com/pulumi/pulumi/sdk/v3/go/pulumi/config"
    31  //
    32  // )
    33  //
    34  //	func main() {
    35  //		pulumi.Run(func(ctx *pulumi.Context) error {
    36  //			cfg := config.New(ctx, "")
    37  //			subnetId := cfg.RequireObject("subnetId")
    38  //			selected, err := ec2.LookupSubnet(ctx, &ec2.LookupSubnetArgs{
    39  //				Id: pulumi.StringRef(subnetId),
    40  //			}, nil)
    41  //			if err != nil {
    42  //				return err
    43  //			}
    44  //			_, err = ec2.NewSecurityGroup(ctx, "subnet", &ec2.SecurityGroupArgs{
    45  //				VpcId: pulumi.String(selected.VpcId),
    46  //				Ingress: ec2.SecurityGroupIngressArray{
    47  //					&ec2.SecurityGroupIngressArgs{
    48  //						CidrBlocks: pulumi.StringArray{
    49  //							pulumi.String(selected.CidrBlock),
    50  //						},
    51  //						FromPort: pulumi.Int(80),
    52  //						ToPort:   pulumi.Int(80),
    53  //						Protocol: pulumi.String("tcp"),
    54  //					},
    55  //				},
    56  //			})
    57  //			if err != nil {
    58  //				return err
    59  //			}
    60  //			return nil
    61  //		})
    62  //	}
    63  //
    64  // ```
    65  // <!--End PulumiCodeChooser -->
    66  //
    67  // ### Filter Example
    68  //
    69  // If you want to match against tag `Name`, use:
    70  //
    71  // <!--Start PulumiCodeChooser -->
    72  // ```go
    73  // package main
    74  //
    75  // import (
    76  //
    77  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ec2"
    78  //	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    79  //
    80  // )
    81  //
    82  //	func main() {
    83  //		pulumi.Run(func(ctx *pulumi.Context) error {
    84  //			_, err := ec2.LookupSubnet(ctx, &ec2.LookupSubnetArgs{
    85  //				Filters: []ec2.GetSubnetFilter{
    86  //					{
    87  //						Name: "tag:Name",
    88  //						Values: []string{
    89  //							"yakdriver",
    90  //						},
    91  //					},
    92  //				},
    93  //			}, nil)
    94  //			if err != nil {
    95  //				return err
    96  //			}
    97  //			return nil
    98  //		})
    99  //	}
   100  //
   101  // ```
   102  // <!--End PulumiCodeChooser -->
   103  func LookupSubnet(ctx *pulumi.Context, args *LookupSubnetArgs, opts ...pulumi.InvokeOption) (*LookupSubnetResult, error) {
   104  	opts = internal.PkgInvokeDefaultOpts(opts)
   105  	var rv LookupSubnetResult
   106  	err := ctx.Invoke("aws:ec2/getSubnet:getSubnet", args, &rv, opts...)
   107  	if err != nil {
   108  		return nil, err
   109  	}
   110  	return &rv, nil
   111  }
   112  
   113  // A collection of arguments for invoking getSubnet.
   114  type LookupSubnetArgs struct {
   115  	// Availability zone where the subnet must reside.
   116  	AvailabilityZone *string `pulumi:"availabilityZone"`
   117  	// ID of the Availability Zone for the subnet. This argument is not supported in all regions or partitions. If necessary, use `availabilityZone` instead.
   118  	AvailabilityZoneId *string `pulumi:"availabilityZoneId"`
   119  	// CIDR block of the desired subnet.
   120  	CidrBlock *string `pulumi:"cidrBlock"`
   121  	// Whether the desired subnet must be the default subnet for its associated availability zone.
   122  	DefaultForAz *bool `pulumi:"defaultForAz"`
   123  	// Configuration block. Detailed below.
   124  	Filters []GetSubnetFilter `pulumi:"filters"`
   125  	// ID of the specific subnet to retrieve.
   126  	Id *string `pulumi:"id"`
   127  	// IPv6 CIDR block of the desired subnet.
   128  	Ipv6CidrBlock *string `pulumi:"ipv6CidrBlock"`
   129  	// State that the desired subnet must have.
   130  	State *string `pulumi:"state"`
   131  	// Map of tags, each pair of which must exactly match a pair on the desired subnet.
   132  	Tags map[string]string `pulumi:"tags"`
   133  	// ID of the VPC that the desired subnet belongs to.
   134  	VpcId *string `pulumi:"vpcId"`
   135  }
   136  
   137  // A collection of values returned by getSubnet.
   138  type LookupSubnetResult struct {
   139  	// ARN of the subnet.
   140  	Arn string `pulumi:"arn"`
   141  	// Whether an IPv6 address is assigned on creation.
   142  	AssignIpv6AddressOnCreation bool   `pulumi:"assignIpv6AddressOnCreation"`
   143  	AvailabilityZone            string `pulumi:"availabilityZone"`
   144  	AvailabilityZoneId          string `pulumi:"availabilityZoneId"`
   145  	// Available IP addresses of the subnet.
   146  	AvailableIpAddressCount int    `pulumi:"availableIpAddressCount"`
   147  	CidrBlock               string `pulumi:"cidrBlock"`
   148  	// Identifier of customer owned IPv4 address pool.
   149  	CustomerOwnedIpv4Pool string `pulumi:"customerOwnedIpv4Pool"`
   150  	DefaultForAz          bool   `pulumi:"defaultForAz"`
   151  	// Whether DNS queries made to the Amazon-provided DNS Resolver in this subnet return synthetic IPv6 addresses for IPv4-only destinations.
   152  	EnableDns64 bool `pulumi:"enableDns64"`
   153  	// Indicates the device position for local network interfaces in this subnet. For example, 1 indicates local network interfaces in this subnet are the secondary network interface (eth1). A local network interface cannot be the primary network interface (eth0).
   154  	EnableLniAtDeviceIndex int `pulumi:"enableLniAtDeviceIndex"`
   155  	// Indicates whether to respond to DNS queries for instance hostnames with DNS A records.
   156  	EnableResourceNameDnsARecordOnLaunch bool `pulumi:"enableResourceNameDnsARecordOnLaunch"`
   157  	// Indicates whether to respond to DNS queries for instance hostnames with DNS AAAA records.
   158  	EnableResourceNameDnsAaaaRecordOnLaunch bool              `pulumi:"enableResourceNameDnsAaaaRecordOnLaunch"`
   159  	Filters                                 []GetSubnetFilter `pulumi:"filters"`
   160  	Id                                      string            `pulumi:"id"`
   161  	Ipv6CidrBlock                           string            `pulumi:"ipv6CidrBlock"`
   162  	// Association ID of the IPv6 CIDR block.
   163  	Ipv6CidrBlockAssociationId string `pulumi:"ipv6CidrBlockAssociationId"`
   164  	// Whether this is an IPv6-only subnet.
   165  	Ipv6Native bool `pulumi:"ipv6Native"`
   166  	// Whether customer owned IP addresses are assigned on network interface creation.
   167  	MapCustomerOwnedIpOnLaunch bool `pulumi:"mapCustomerOwnedIpOnLaunch"`
   168  	// Whether public IP addresses are assigned on instance launch.
   169  	MapPublicIpOnLaunch bool `pulumi:"mapPublicIpOnLaunch"`
   170  	// ARN of the Outpost.
   171  	OutpostArn string `pulumi:"outpostArn"`
   172  	// ID of the AWS account that owns the subnet.
   173  	OwnerId string `pulumi:"ownerId"`
   174  	// The type of hostnames assigned to instances in the subnet at launch.
   175  	PrivateDnsHostnameTypeOnLaunch string            `pulumi:"privateDnsHostnameTypeOnLaunch"`
   176  	State                          string            `pulumi:"state"`
   177  	Tags                           map[string]string `pulumi:"tags"`
   178  	VpcId                          string            `pulumi:"vpcId"`
   179  }
   180  
   181  func LookupSubnetOutput(ctx *pulumi.Context, args LookupSubnetOutputArgs, opts ...pulumi.InvokeOption) LookupSubnetResultOutput {
   182  	return pulumi.ToOutputWithContext(context.Background(), args).
   183  		ApplyT(func(v interface{}) (LookupSubnetResult, error) {
   184  			args := v.(LookupSubnetArgs)
   185  			r, err := LookupSubnet(ctx, &args, opts...)
   186  			var s LookupSubnetResult
   187  			if r != nil {
   188  				s = *r
   189  			}
   190  			return s, err
   191  		}).(LookupSubnetResultOutput)
   192  }
   193  
   194  // A collection of arguments for invoking getSubnet.
   195  type LookupSubnetOutputArgs struct {
   196  	// Availability zone where the subnet must reside.
   197  	AvailabilityZone pulumi.StringPtrInput `pulumi:"availabilityZone"`
   198  	// ID of the Availability Zone for the subnet. This argument is not supported in all regions or partitions. If necessary, use `availabilityZone` instead.
   199  	AvailabilityZoneId pulumi.StringPtrInput `pulumi:"availabilityZoneId"`
   200  	// CIDR block of the desired subnet.
   201  	CidrBlock pulumi.StringPtrInput `pulumi:"cidrBlock"`
   202  	// Whether the desired subnet must be the default subnet for its associated availability zone.
   203  	DefaultForAz pulumi.BoolPtrInput `pulumi:"defaultForAz"`
   204  	// Configuration block. Detailed below.
   205  	Filters GetSubnetFilterArrayInput `pulumi:"filters"`
   206  	// ID of the specific subnet to retrieve.
   207  	Id pulumi.StringPtrInput `pulumi:"id"`
   208  	// IPv6 CIDR block of the desired subnet.
   209  	Ipv6CidrBlock pulumi.StringPtrInput `pulumi:"ipv6CidrBlock"`
   210  	// State that the desired subnet must have.
   211  	State pulumi.StringPtrInput `pulumi:"state"`
   212  	// Map of tags, each pair of which must exactly match a pair on the desired subnet.
   213  	Tags pulumi.StringMapInput `pulumi:"tags"`
   214  	// ID of the VPC that the desired subnet belongs to.
   215  	VpcId pulumi.StringPtrInput `pulumi:"vpcId"`
   216  }
   217  
   218  func (LookupSubnetOutputArgs) ElementType() reflect.Type {
   219  	return reflect.TypeOf((*LookupSubnetArgs)(nil)).Elem()
   220  }
   221  
   222  // A collection of values returned by getSubnet.
   223  type LookupSubnetResultOutput struct{ *pulumi.OutputState }
   224  
   225  func (LookupSubnetResultOutput) ElementType() reflect.Type {
   226  	return reflect.TypeOf((*LookupSubnetResult)(nil)).Elem()
   227  }
   228  
   229  func (o LookupSubnetResultOutput) ToLookupSubnetResultOutput() LookupSubnetResultOutput {
   230  	return o
   231  }
   232  
   233  func (o LookupSubnetResultOutput) ToLookupSubnetResultOutputWithContext(ctx context.Context) LookupSubnetResultOutput {
   234  	return o
   235  }
   236  
   237  // ARN of the subnet.
   238  func (o LookupSubnetResultOutput) Arn() pulumi.StringOutput {
   239  	return o.ApplyT(func(v LookupSubnetResult) string { return v.Arn }).(pulumi.StringOutput)
   240  }
   241  
   242  // Whether an IPv6 address is assigned on creation.
   243  func (o LookupSubnetResultOutput) AssignIpv6AddressOnCreation() pulumi.BoolOutput {
   244  	return o.ApplyT(func(v LookupSubnetResult) bool { return v.AssignIpv6AddressOnCreation }).(pulumi.BoolOutput)
   245  }
   246  
   247  func (o LookupSubnetResultOutput) AvailabilityZone() pulumi.StringOutput {
   248  	return o.ApplyT(func(v LookupSubnetResult) string { return v.AvailabilityZone }).(pulumi.StringOutput)
   249  }
   250  
   251  func (o LookupSubnetResultOutput) AvailabilityZoneId() pulumi.StringOutput {
   252  	return o.ApplyT(func(v LookupSubnetResult) string { return v.AvailabilityZoneId }).(pulumi.StringOutput)
   253  }
   254  
   255  // Available IP addresses of the subnet.
   256  func (o LookupSubnetResultOutput) AvailableIpAddressCount() pulumi.IntOutput {
   257  	return o.ApplyT(func(v LookupSubnetResult) int { return v.AvailableIpAddressCount }).(pulumi.IntOutput)
   258  }
   259  
   260  func (o LookupSubnetResultOutput) CidrBlock() pulumi.StringOutput {
   261  	return o.ApplyT(func(v LookupSubnetResult) string { return v.CidrBlock }).(pulumi.StringOutput)
   262  }
   263  
   264  // Identifier of customer owned IPv4 address pool.
   265  func (o LookupSubnetResultOutput) CustomerOwnedIpv4Pool() pulumi.StringOutput {
   266  	return o.ApplyT(func(v LookupSubnetResult) string { return v.CustomerOwnedIpv4Pool }).(pulumi.StringOutput)
   267  }
   268  
   269  func (o LookupSubnetResultOutput) DefaultForAz() pulumi.BoolOutput {
   270  	return o.ApplyT(func(v LookupSubnetResult) bool { return v.DefaultForAz }).(pulumi.BoolOutput)
   271  }
   272  
   273  // Whether DNS queries made to the Amazon-provided DNS Resolver in this subnet return synthetic IPv6 addresses for IPv4-only destinations.
   274  func (o LookupSubnetResultOutput) EnableDns64() pulumi.BoolOutput {
   275  	return o.ApplyT(func(v LookupSubnetResult) bool { return v.EnableDns64 }).(pulumi.BoolOutput)
   276  }
   277  
   278  // Indicates the device position for local network interfaces in this subnet. For example, 1 indicates local network interfaces in this subnet are the secondary network interface (eth1). A local network interface cannot be the primary network interface (eth0).
   279  func (o LookupSubnetResultOutput) EnableLniAtDeviceIndex() pulumi.IntOutput {
   280  	return o.ApplyT(func(v LookupSubnetResult) int { return v.EnableLniAtDeviceIndex }).(pulumi.IntOutput)
   281  }
   282  
   283  // Indicates whether to respond to DNS queries for instance hostnames with DNS A records.
   284  func (o LookupSubnetResultOutput) EnableResourceNameDnsARecordOnLaunch() pulumi.BoolOutput {
   285  	return o.ApplyT(func(v LookupSubnetResult) bool { return v.EnableResourceNameDnsARecordOnLaunch }).(pulumi.BoolOutput)
   286  }
   287  
   288  // Indicates whether to respond to DNS queries for instance hostnames with DNS AAAA records.
   289  func (o LookupSubnetResultOutput) EnableResourceNameDnsAaaaRecordOnLaunch() pulumi.BoolOutput {
   290  	return o.ApplyT(func(v LookupSubnetResult) bool { return v.EnableResourceNameDnsAaaaRecordOnLaunch }).(pulumi.BoolOutput)
   291  }
   292  
   293  func (o LookupSubnetResultOutput) Filters() GetSubnetFilterArrayOutput {
   294  	return o.ApplyT(func(v LookupSubnetResult) []GetSubnetFilter { return v.Filters }).(GetSubnetFilterArrayOutput)
   295  }
   296  
   297  func (o LookupSubnetResultOutput) Id() pulumi.StringOutput {
   298  	return o.ApplyT(func(v LookupSubnetResult) string { return v.Id }).(pulumi.StringOutput)
   299  }
   300  
   301  func (o LookupSubnetResultOutput) Ipv6CidrBlock() pulumi.StringOutput {
   302  	return o.ApplyT(func(v LookupSubnetResult) string { return v.Ipv6CidrBlock }).(pulumi.StringOutput)
   303  }
   304  
   305  // Association ID of the IPv6 CIDR block.
   306  func (o LookupSubnetResultOutput) Ipv6CidrBlockAssociationId() pulumi.StringOutput {
   307  	return o.ApplyT(func(v LookupSubnetResult) string { return v.Ipv6CidrBlockAssociationId }).(pulumi.StringOutput)
   308  }
   309  
   310  // Whether this is an IPv6-only subnet.
   311  func (o LookupSubnetResultOutput) Ipv6Native() pulumi.BoolOutput {
   312  	return o.ApplyT(func(v LookupSubnetResult) bool { return v.Ipv6Native }).(pulumi.BoolOutput)
   313  }
   314  
   315  // Whether customer owned IP addresses are assigned on network interface creation.
   316  func (o LookupSubnetResultOutput) MapCustomerOwnedIpOnLaunch() pulumi.BoolOutput {
   317  	return o.ApplyT(func(v LookupSubnetResult) bool { return v.MapCustomerOwnedIpOnLaunch }).(pulumi.BoolOutput)
   318  }
   319  
   320  // Whether public IP addresses are assigned on instance launch.
   321  func (o LookupSubnetResultOutput) MapPublicIpOnLaunch() pulumi.BoolOutput {
   322  	return o.ApplyT(func(v LookupSubnetResult) bool { return v.MapPublicIpOnLaunch }).(pulumi.BoolOutput)
   323  }
   324  
   325  // ARN of the Outpost.
   326  func (o LookupSubnetResultOutput) OutpostArn() pulumi.StringOutput {
   327  	return o.ApplyT(func(v LookupSubnetResult) string { return v.OutpostArn }).(pulumi.StringOutput)
   328  }
   329  
   330  // ID of the AWS account that owns the subnet.
   331  func (o LookupSubnetResultOutput) OwnerId() pulumi.StringOutput {
   332  	return o.ApplyT(func(v LookupSubnetResult) string { return v.OwnerId }).(pulumi.StringOutput)
   333  }
   334  
   335  // The type of hostnames assigned to instances in the subnet at launch.
   336  func (o LookupSubnetResultOutput) PrivateDnsHostnameTypeOnLaunch() pulumi.StringOutput {
   337  	return o.ApplyT(func(v LookupSubnetResult) string { return v.PrivateDnsHostnameTypeOnLaunch }).(pulumi.StringOutput)
   338  }
   339  
   340  func (o LookupSubnetResultOutput) State() pulumi.StringOutput {
   341  	return o.ApplyT(func(v LookupSubnetResult) string { return v.State }).(pulumi.StringOutput)
   342  }
   343  
   344  func (o LookupSubnetResultOutput) Tags() pulumi.StringMapOutput {
   345  	return o.ApplyT(func(v LookupSubnetResult) map[string]string { return v.Tags }).(pulumi.StringMapOutput)
   346  }
   347  
   348  func (o LookupSubnetResultOutput) VpcId() pulumi.StringOutput {
   349  	return o.ApplyT(func(v LookupSubnetResult) string { return v.VpcId }).(pulumi.StringOutput)
   350  }
   351  
   352  func init() {
   353  	pulumi.RegisterOutputType(LookupSubnetResultOutput{})
   354  }