Skip to content

Commit 2986c05

Browse files
author
Christopher Robert Sherman
committed
Fix S3 Express Directory Bucket tagging API routing
1 parent e0e2e15 commit 2986c05

File tree

3 files changed

+91
-3
lines changed

3 files changed

+91
-3
lines changed

internal/conns/awsclient.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/aws/aws-sdk-go-v2/aws/arn"
1818
apigatewayv2_types "github.com/aws/aws-sdk-go-v2/service/apigatewayv2/types"
1919
"github.com/aws/aws-sdk-go-v2/service/s3"
20+
"github.com/aws/aws-sdk-go-v2/service/s3control"
2021
"github.com/hashicorp/aws-sdk-go-base/v2/endpoints"
2122
baselogging "github.com/hashicorp/aws-sdk-go-base/v2/logging"
2223
"github.com/hashicorp/terraform-plugin-log/tflog"
@@ -191,6 +192,14 @@ func (c *AWSClient) S3ExpressClient(ctx context.Context) *s3.Client {
191192
return c.s3ExpressClient
192193
}
193194

195+
// S3ExpressControlClient returns an AWS SDK for Go v2 S3 Control API client suitable for use with S3 Express (directory buckets).
196+
// For Directory Buckets, control plane operations like ListTagsForResource must use the s3express-control.region.amazonaws.com endpoint.
197+
func (c *AWSClient) S3ExpressControlClient(ctx context.Context) *s3control.Client {
198+
return errs.Must(client[*s3control.Client](ctx, c, names.S3Control, map[string]any{
199+
"endpoint": fmt.Sprintf("https://s3express-control.%s.%s", c.Region(ctx), c.DNSSuffix(ctx)),
200+
}))
201+
}
202+
194203
// S3UsePathStyle returns the s3_force_path_style provider configuration value.
195204
func (c *AWSClient) S3UsePathStyle(context.Context) bool {
196205
return c.s3UsePathStyle
@@ -258,7 +267,7 @@ func (c *AWSClient) DefaultKMSKeyPolicy(ctx context.Context) string {
258267
"Resource": "*"
259268
}
260269
]
261-
}
270+
}
262271
`, c.Partition(ctx), c.AccountID(ctx))
263272
}
264273

internal/service/s3control/tags_gen.go

Lines changed: 27 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package s3control
5+
6+
import "testing"
7+
8+
func TestIsDirectoryBucketARN(t *testing.T) {
9+
testCases := []struct {
10+
name string
11+
arn string
12+
expected bool
13+
}{
14+
{
15+
name: "Standard S3 bucket ARN",
16+
arn: "arn:aws:s3:::my-bucket",
17+
expected: false,
18+
},
19+
{
20+
name: "S3 Control Access Point ARN",
21+
arn: "arn:aws:s3:us-east-1:123456789012:accesspoint/my-access-point",
22+
expected: false,
23+
},
24+
{
25+
name: "Directory Bucket ARN (S3 Express)",
26+
arn: "arn:aws:s3express:us-east-1:123456789012:bucket/my-directory-bucket--usw2-az1--x-s3",
27+
expected: true,
28+
},
29+
{
30+
name: "Directory Bucket Access Point ARN",
31+
arn: "arn:aws:s3express:us-east-1:123456789012:accesspoint/my-access-point",
32+
expected: true,
33+
},
34+
{
35+
name: "Empty ARN",
36+
arn: "",
37+
expected: false,
38+
},
39+
{
40+
name: "Invalid ARN format",
41+
arn: "not-an-arn",
42+
expected: false,
43+
},
44+
}
45+
46+
for _, tc := range testCases {
47+
t.Run(tc.name, func(t *testing.T) {
48+
result := isDirectoryBucketARN(tc.arn)
49+
if result != tc.expected {
50+
t.Errorf("isDirectoryBucketARN(%q) = %v, expected %v", tc.arn, result, tc.expected)
51+
}
52+
})
53+
}
54+
}

0 commit comments

Comments
 (0)