github.com/pulumi/pulumi-aws/sdk/v6@v6.32.0/go/aws/s3/getBucket.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 s3
     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  // Provides details about a specific S3 bucket.
    15  //
    16  // This resource may prove useful when setting up a Route53 record, or an origin for a CloudFront
    17  // Distribution.
    18  //
    19  // ## Example Usage
    20  //
    21  // ### Route53 Record
    22  //
    23  // <!--Start PulumiCodeChooser -->
    24  // ```go
    25  // package main
    26  //
    27  // import (
    28  //
    29  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/route53"
    30  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/s3"
    31  //	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    32  //
    33  // )
    34  //
    35  //	func main() {
    36  //		pulumi.Run(func(ctx *pulumi.Context) error {
    37  //			selected, err := s3.LookupBucket(ctx, &s3.LookupBucketArgs{
    38  //				Bucket: "bucket.test.com",
    39  //			}, nil)
    40  //			if err != nil {
    41  //				return err
    42  //			}
    43  //			testZone, err := route53.LookupZone(ctx, &route53.LookupZoneArgs{
    44  //				Name: pulumi.StringRef("test.com."),
    45  //			}, nil)
    46  //			if err != nil {
    47  //				return err
    48  //			}
    49  //			_, err = route53.NewRecord(ctx, "example", &route53.RecordArgs{
    50  //				ZoneId: pulumi.String(testZone.Id),
    51  //				Name:   pulumi.String("bucket"),
    52  //				Type:   pulumi.String(route53.RecordTypeA),
    53  //				Aliases: route53.RecordAliasArray{
    54  //					&route53.RecordAliasArgs{
    55  //						Name:   pulumi.String(selected.WebsiteDomain),
    56  //						ZoneId: pulumi.String(selected.HostedZoneId),
    57  //					},
    58  //				},
    59  //			})
    60  //			if err != nil {
    61  //				return err
    62  //			}
    63  //			return nil
    64  //		})
    65  //	}
    66  //
    67  // ```
    68  // <!--End PulumiCodeChooser -->
    69  //
    70  // ### CloudFront Origin
    71  //
    72  // <!--Start PulumiCodeChooser -->
    73  // ```go
    74  // package main
    75  //
    76  // import (
    77  //
    78  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/cloudfront"
    79  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/s3"
    80  //	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    81  //
    82  // )
    83  //
    84  //	func main() {
    85  //		pulumi.Run(func(ctx *pulumi.Context) error {
    86  //			selected, err := s3.LookupBucket(ctx, &s3.LookupBucketArgs{
    87  //				Bucket: "a-test-bucket",
    88  //			}, nil)
    89  //			if err != nil {
    90  //				return err
    91  //			}
    92  //			_, err = cloudfront.NewDistribution(ctx, "test", &cloudfront.DistributionArgs{
    93  //				Origins: cloudfront.DistributionOriginArray{
    94  //					&cloudfront.DistributionOriginArgs{
    95  //						DomainName: pulumi.String(selected.BucketDomainName),
    96  //						OriginId:   pulumi.String("s3-selected-bucket"),
    97  //					},
    98  //				},
    99  //			})
   100  //			if err != nil {
   101  //				return err
   102  //			}
   103  //			return nil
   104  //		})
   105  //	}
   106  //
   107  // ```
   108  // <!--End PulumiCodeChooser -->
   109  func LookupBucket(ctx *pulumi.Context, args *LookupBucketArgs, opts ...pulumi.InvokeOption) (*LookupBucketResult, error) {
   110  	opts = internal.PkgInvokeDefaultOpts(opts)
   111  	var rv LookupBucketResult
   112  	err := ctx.Invoke("aws:s3/getBucket:getBucket", args, &rv, opts...)
   113  	if err != nil {
   114  		return nil, err
   115  	}
   116  	return &rv, nil
   117  }
   118  
   119  // A collection of arguments for invoking getBucket.
   120  type LookupBucketArgs struct {
   121  	// Name of the bucket
   122  	Bucket string `pulumi:"bucket"`
   123  }
   124  
   125  // A collection of values returned by getBucket.
   126  type LookupBucketResult struct {
   127  	// ARN of the bucket. Will be of format `arn:aws:s3:::bucketname`.
   128  	Arn    string `pulumi:"arn"`
   129  	Bucket string `pulumi:"bucket"`
   130  	// Bucket domain name. Will be of format `bucketname.s3.amazonaws.com`.
   131  	BucketDomainName string `pulumi:"bucketDomainName"`
   132  	// The bucket region-specific domain name. The bucket domain name including the region name. Please refer to the [S3 endpoints reference](https://docs.aws.amazon.com/general/latest/gr/s3.html#s3_region) for format. Note: AWS CloudFront allows specifying an S3 region-specific endpoint when creating an S3 origin. This will prevent redirect issues from CloudFront to the S3 Origin URL. For more information, see the [Virtual Hosted-Style Requests for Other Regions](https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html#deprecated-global-endpoint) section in the AWS S3 User Guide.
   133  	BucketRegionalDomainName string `pulumi:"bucketRegionalDomainName"`
   134  	// The [Route 53 Hosted Zone ID](https://docs.aws.amazon.com/general/latest/gr/rande.html#s3_website_region_endpoints) for this bucket's region.
   135  	HostedZoneId string `pulumi:"hostedZoneId"`
   136  	// The provider-assigned unique ID for this managed resource.
   137  	Id string `pulumi:"id"`
   138  	// AWS region this bucket resides in.
   139  	Region string `pulumi:"region"`
   140  	// Domain of the website endpoint, if the bucket is configured with a website. If not, this will be an empty string. This is used to create Route 53 alias records.
   141  	WebsiteDomain string `pulumi:"websiteDomain"`
   142  	// Website endpoint, if the bucket is configured with a website. If not, this will be an empty string.
   143  	WebsiteEndpoint string `pulumi:"websiteEndpoint"`
   144  }
   145  
   146  func LookupBucketOutput(ctx *pulumi.Context, args LookupBucketOutputArgs, opts ...pulumi.InvokeOption) LookupBucketResultOutput {
   147  	return pulumi.ToOutputWithContext(context.Background(), args).
   148  		ApplyT(func(v interface{}) (LookupBucketResult, error) {
   149  			args := v.(LookupBucketArgs)
   150  			r, err := LookupBucket(ctx, &args, opts...)
   151  			var s LookupBucketResult
   152  			if r != nil {
   153  				s = *r
   154  			}
   155  			return s, err
   156  		}).(LookupBucketResultOutput)
   157  }
   158  
   159  // A collection of arguments for invoking getBucket.
   160  type LookupBucketOutputArgs struct {
   161  	// Name of the bucket
   162  	Bucket pulumi.StringInput `pulumi:"bucket"`
   163  }
   164  
   165  func (LookupBucketOutputArgs) ElementType() reflect.Type {
   166  	return reflect.TypeOf((*LookupBucketArgs)(nil)).Elem()
   167  }
   168  
   169  // A collection of values returned by getBucket.
   170  type LookupBucketResultOutput struct{ *pulumi.OutputState }
   171  
   172  func (LookupBucketResultOutput) ElementType() reflect.Type {
   173  	return reflect.TypeOf((*LookupBucketResult)(nil)).Elem()
   174  }
   175  
   176  func (o LookupBucketResultOutput) ToLookupBucketResultOutput() LookupBucketResultOutput {
   177  	return o
   178  }
   179  
   180  func (o LookupBucketResultOutput) ToLookupBucketResultOutputWithContext(ctx context.Context) LookupBucketResultOutput {
   181  	return o
   182  }
   183  
   184  // ARN of the bucket. Will be of format `arn:aws:s3:::bucketname`.
   185  func (o LookupBucketResultOutput) Arn() pulumi.StringOutput {
   186  	return o.ApplyT(func(v LookupBucketResult) string { return v.Arn }).(pulumi.StringOutput)
   187  }
   188  
   189  func (o LookupBucketResultOutput) Bucket() pulumi.StringOutput {
   190  	return o.ApplyT(func(v LookupBucketResult) string { return v.Bucket }).(pulumi.StringOutput)
   191  }
   192  
   193  // Bucket domain name. Will be of format `bucketname.s3.amazonaws.com`.
   194  func (o LookupBucketResultOutput) BucketDomainName() pulumi.StringOutput {
   195  	return o.ApplyT(func(v LookupBucketResult) string { return v.BucketDomainName }).(pulumi.StringOutput)
   196  }
   197  
   198  // The bucket region-specific domain name. The bucket domain name including the region name. Please refer to the [S3 endpoints reference](https://docs.aws.amazon.com/general/latest/gr/s3.html#s3_region) for format. Note: AWS CloudFront allows specifying an S3 region-specific endpoint when creating an S3 origin. This will prevent redirect issues from CloudFront to the S3 Origin URL. For more information, see the [Virtual Hosted-Style Requests for Other Regions](https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html#deprecated-global-endpoint) section in the AWS S3 User Guide.
   199  func (o LookupBucketResultOutput) BucketRegionalDomainName() pulumi.StringOutput {
   200  	return o.ApplyT(func(v LookupBucketResult) string { return v.BucketRegionalDomainName }).(pulumi.StringOutput)
   201  }
   202  
   203  // The [Route 53 Hosted Zone ID](https://docs.aws.amazon.com/general/latest/gr/rande.html#s3_website_region_endpoints) for this bucket's region.
   204  func (o LookupBucketResultOutput) HostedZoneId() pulumi.StringOutput {
   205  	return o.ApplyT(func(v LookupBucketResult) string { return v.HostedZoneId }).(pulumi.StringOutput)
   206  }
   207  
   208  // The provider-assigned unique ID for this managed resource.
   209  func (o LookupBucketResultOutput) Id() pulumi.StringOutput {
   210  	return o.ApplyT(func(v LookupBucketResult) string { return v.Id }).(pulumi.StringOutput)
   211  }
   212  
   213  // AWS region this bucket resides in.
   214  func (o LookupBucketResultOutput) Region() pulumi.StringOutput {
   215  	return o.ApplyT(func(v LookupBucketResult) string { return v.Region }).(pulumi.StringOutput)
   216  }
   217  
   218  // Domain of the website endpoint, if the bucket is configured with a website. If not, this will be an empty string. This is used to create Route 53 alias records.
   219  func (o LookupBucketResultOutput) WebsiteDomain() pulumi.StringOutput {
   220  	return o.ApplyT(func(v LookupBucketResult) string { return v.WebsiteDomain }).(pulumi.StringOutput)
   221  }
   222  
   223  // Website endpoint, if the bucket is configured with a website. If not, this will be an empty string.
   224  func (o LookupBucketResultOutput) WebsiteEndpoint() pulumi.StringOutput {
   225  	return o.ApplyT(func(v LookupBucketResult) string { return v.WebsiteEndpoint }).(pulumi.StringOutput)
   226  }
   227  
   228  func init() {
   229  	pulumi.RegisterOutputType(LookupBucketResultOutput{})
   230  }