Skip to content

Commit 10d0ca1

Browse files
Merge pull request #1813 from linode/dev
Release v2.35.1
2 parents 1853cad + 6a00fc6 commit 10d0ca1

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

linode/objbucket/helpers.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55

66
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
7+
"github.com/linode/linodego"
78
"github.com/linode/terraform-provider-linode/v2/linode/helper"
89
)
910

@@ -13,3 +14,12 @@ func populateLogAttributes(ctx context.Context, d *schema.ResourceData) context.
1314
"cluster": d.Get("cluster"),
1415
})
1516
}
17+
18+
func getS3Endpoint(ctx context.Context, bucket linodego.ObjectStorageBucket) (endpoint string) {
19+
if bucket.S3Endpoint != "" {
20+
endpoint = bucket.S3Endpoint
21+
} else {
22+
endpoint = helper.ComputeS3EndpointFromBucket(ctx, bucket)
23+
}
24+
return
25+
}

linode/objbucket/resource.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ func readResource(
102102
defer teardownKeysCleanUp()
103103
}
104104

105-
s3Client, err := helper.S3Connection(ctx, bucket.S3Endpoint, objKeys.AccessKey, objKeys.SecretKey)
105+
endpoint := getS3Endpoint(ctx, *bucket)
106+
s3Client, err := helper.S3Connection(ctx, endpoint, objKeys.AccessKey, objKeys.SecretKey)
106107
if err != nil {
107108
return diag.FromErr(err)
108109
}
@@ -123,14 +124,16 @@ func readResource(
123124
d.SetId(fmt.Sprintf("%s:%s", bucket.Cluster, bucket.Label))
124125
}
125126

127+
endpoint := getS3Endpoint(ctx, *bucket)
128+
126129
d.Set("cluster", bucket.Cluster)
127130
d.Set("region", bucket.Region)
128131
d.Set("label", bucket.Label)
129132
d.Set("hostname", bucket.Hostname)
130133
d.Set("acl", access.ACL)
131134
d.Set("cors_enabled", access.CorsEnabled)
132-
d.Set("endpoint", bucket.S3Endpoint)
133-
d.Set("s3_endpoint", bucket.S3Endpoint)
135+
d.Set("endpoint", endpoint)
136+
d.Set("s3_endpoint", endpoint)
134137
d.Set("endpoint_type", bucket.EndpointType)
135138

136139
return nil
@@ -178,8 +181,10 @@ func createResource(
178181
return diag.Errorf("failed to create a Linode ObjectStorageBucket: %s", err)
179182
}
180183

181-
d.Set("endpoint", bucket.S3Endpoint)
182-
d.Set("s3_endpoint", bucket.S3Endpoint)
184+
endpoint := getS3Endpoint(ctx, *bucket)
185+
186+
d.Set("endpoint", endpoint)
187+
d.Set("s3_endpoint", endpoint)
183188

184189
if bucket.Region != "" {
185190
d.SetId(fmt.Sprintf("%s:%s", bucket.Region, bucket.Label))

0 commit comments

Comments
 (0)