mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
provider/aws: Added a S3 Bucket domain name attribute (#10088)
This commit is contained in:
parent
4f7f048f76
commit
92d723609e
@ -18,11 +18,11 @@ func TestAccAWSS3Bucket_importBasic(t *testing.T) {
|
|||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckAWSS3BucketDestroy,
|
CheckDestroy: testAccCheckAWSS3BucketDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
{
|
||||||
Config: testAccAWSS3BucketConfig(rInt),
|
Config: testAccAWSS3BucketConfig(rInt),
|
||||||
},
|
},
|
||||||
|
|
||||||
resource.TestStep{
|
{
|
||||||
ResourceName: resourceName,
|
ResourceName: resourceName,
|
||||||
ImportState: true,
|
ImportState: true,
|
||||||
ImportStateVerify: true,
|
ImportStateVerify: true,
|
||||||
@ -63,11 +63,11 @@ func TestAccAWSS3Bucket_importWithPolicy(t *testing.T) {
|
|||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckAWSS3BucketDestroy,
|
CheckDestroy: testAccCheckAWSS3BucketDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
{
|
||||||
Config: testAccAWSS3BucketConfigWithPolicy(rInt),
|
Config: testAccAWSS3BucketConfigWithPolicy(rInt),
|
||||||
},
|
},
|
||||||
|
|
||||||
resource.TestStep{
|
{
|
||||||
ResourceName: "aws_s3_bucket.bucket",
|
ResourceName: "aws_s3_bucket.bucket",
|
||||||
ImportState: true,
|
ImportState: true,
|
||||||
ImportStateCheck: checkFn,
|
ImportStateCheck: checkFn,
|
||||||
|
@ -36,6 +36,11 @@ func resourceAwsS3Bucket() *schema.Resource {
|
|||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"bucket_domain_name": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
|
||||||
"arn": {
|
"arn": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
@ -534,6 +539,8 @@ func resourceAwsS3BucketRead(d *schema.ResourceData, meta interface{}) error {
|
|||||||
d.Set("bucket", d.Id())
|
d.Set("bucket", d.Id())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
d.Set("bucket_domain_name", bucketDomainName(d.Get("bucket").(string)))
|
||||||
|
|
||||||
// Read the policy
|
// Read the policy
|
||||||
if _, ok := d.GetOk("policy"); ok {
|
if _, ok := d.GetOk("policy"); ok {
|
||||||
pol, err := s3conn.GetBucketPolicy(&s3.GetBucketPolicyInput{
|
pol, err := s3conn.GetBucketPolicy(&s3.GetBucketPolicyInput{
|
||||||
@ -1207,6 +1214,10 @@ func websiteEndpoint(s3conn *s3.S3, d *schema.ResourceData) (*S3Website, error)
|
|||||||
return WebsiteEndpoint(bucket, region), nil
|
return WebsiteEndpoint(bucket, region), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func bucketDomainName(bucket string) string {
|
||||||
|
return fmt.Sprintf("%s.s3.amazonaws.com", bucket)
|
||||||
|
}
|
||||||
|
|
||||||
func WebsiteEndpoint(bucket string, region string) *S3Website {
|
func WebsiteEndpoint(bucket string, region string) *S3Website {
|
||||||
domain := WebsiteDomainUrl(region)
|
domain := WebsiteDomainUrl(region)
|
||||||
return &S3Website{Endpoint: fmt.Sprintf("%s.%s", bucket, domain), Domain: domain}
|
return &S3Website{Endpoint: fmt.Sprintf("%s.%s", bucket, domain), Domain: domain}
|
||||||
|
@ -46,6 +46,10 @@ func TestAccAWSS3Bucket_basic(t *testing.T) {
|
|||||||
"aws_s3_bucket.bucket", "website_endpoint"),
|
"aws_s3_bucket.bucket", "website_endpoint"),
|
||||||
resource.TestMatchResourceAttr(
|
resource.TestMatchResourceAttr(
|
||||||
"aws_s3_bucket.bucket", "arn", arnRegexp),
|
"aws_s3_bucket.bucket", "arn", arnRegexp),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"aws_s3_bucket.bucket", "bucket", testAccBucketName(rInt)),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"aws_s3_bucket.bucket", "bucket_domain_name", testAccBucketDomainName(rInt)),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -1089,6 +1093,14 @@ func testAccCheckAWSS3BucketLogging(n, b, p string) resource.TestCheckFunc {
|
|||||||
|
|
||||||
// These need a bit of randomness as the name can only be used once globally
|
// These need a bit of randomness as the name can only be used once globally
|
||||||
// within AWS
|
// within AWS
|
||||||
|
func testAccBucketName(randInt int) string {
|
||||||
|
return fmt.Sprintf("tf-test-bucket-%d", randInt)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testAccBucketDomainName(randInt int) string {
|
||||||
|
return fmt.Sprintf("tf-test-bucket-%d.s3.amazonaws.com", randInt)
|
||||||
|
}
|
||||||
|
|
||||||
func testAccWebsiteEndpoint(randInt int) string {
|
func testAccWebsiteEndpoint(randInt int) string {
|
||||||
return fmt.Sprintf("tf-test-bucket-%d.s3-website-us-west-2.amazonaws.com", randInt)
|
return fmt.Sprintf("tf-test-bucket-%d.s3-website-us-west-2.amazonaws.com", randInt)
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ resource "aws_s3_bucket" "b" {
|
|||||||
|
|
||||||
resource "aws_cloudfront_distribution" "s3_distribution" {
|
resource "aws_cloudfront_distribution" "s3_distribution" {
|
||||||
origin {
|
origin {
|
||||||
domain_name = "${aws_s3_bucket.b.bucket}.s3.amazonaws.com"
|
domain_name = "${aws_s3_bucket.b.bucket_domain_name}"
|
||||||
origin_id = "myS3Origin"
|
origin_id = "myS3Origin"
|
||||||
|
|
||||||
s3_origin_config {
|
s3_origin_config {
|
||||||
|
@ -380,6 +380,7 @@ The following attributes are exported:
|
|||||||
|
|
||||||
* `id` - The name of the bucket.
|
* `id` - The name of the bucket.
|
||||||
* `arn` - The ARN of the bucket. Will be of format `arn:aws:s3:::bucketname`.
|
* `arn` - The ARN of the bucket. Will be of format `arn:aws:s3:::bucketname`.
|
||||||
|
* `bucket_domain_name` - The bucket domain name. Will be of format `bucketname.s3.amazonaws.com`.
|
||||||
* `hosted_zone_id` - 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.
|
* `hosted_zone_id` - 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.
|
||||||
* `region` - The AWS region this bucket resides in.
|
* `region` - The AWS region this bucket resides in.
|
||||||
* `website_endpoint` - The website endpoint, if the bucket is configured with a website. If not, this will be an empty string.
|
* `website_endpoint` - The website endpoint, if the bucket is configured with a website. If not, this will be an empty string.
|
||||||
|
Loading…
Reference in New Issue
Block a user