Skip to content

Commit 454633f

Browse files
authored
Merge pull request #33024 from hashicorp/f-s3-us-east-1-regional
provider: Adds support for enabling regional endpoint for S3
2 parents fd4e4a5 + 0e995c3 commit 454633f

File tree

9 files changed

+60
-15
lines changed

9 files changed

+60
-15
lines changed

.changelog/33024.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
provider: Adds the `s3_us_east_1_regional_endpoint` attribute to support using the regional S3 API endpoint in `us-east-1`.
3+
```

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ require (
6666
github.com/beevik/etree v1.2.0
6767
github.com/google/go-cmp v0.5.9
6868
github.com/hashicorp/aws-cloudformation-resource-schema-sdk-go v0.21.0
69-
github.com/hashicorp/aws-sdk-go-base/v2 v2.0.0-beta.33
70-
github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2 v2.0.0-beta.34
69+
github.com/hashicorp/aws-sdk-go-base/v2 v2.0.0-beta.34
70+
github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2 v2.0.0-beta.35
7171
github.com/hashicorp/awspolicyequivalence v1.6.0
7272
github.com/hashicorp/go-cleanhttp v0.5.2
7373
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,10 @@ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
214214
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
215215
github.com/hashicorp/aws-cloudformation-resource-schema-sdk-go v0.21.0 h1:IUypt/TbXiJBkBbE3926CgnjD8IltAitdn7Yive61DY=
216216
github.com/hashicorp/aws-cloudformation-resource-schema-sdk-go v0.21.0/go.mod h1:cdTE6F2pCKQobug+RqRaQp7Kz9hIEqiSvpPmb6E5G1w=
217-
github.com/hashicorp/aws-sdk-go-base/v2 v2.0.0-beta.33 h1:8ogYFA7VJSKIOvyODL2mJphWLYc87ZdoKR9Zg3UEAVM=
218-
github.com/hashicorp/aws-sdk-go-base/v2 v2.0.0-beta.33/go.mod h1:D8McAXJE4Ki5B4MYCicebCGfH8f5s3hNJc8ubR8x//4=
219-
github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2 v2.0.0-beta.34 h1:t2/JBep3k7Maetnw6N5e9PKWVKPHpWEJHYz5avmeKl0=
220-
github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2 v2.0.0-beta.34/go.mod h1:yfSdY7j8d/ifBnvktBI58gZH+tg6fQLqKAtZtGYMVBo=
217+
github.com/hashicorp/aws-sdk-go-base/v2 v2.0.0-beta.34 h1:WH0OOrhZe6wzOnA+ra0ZV0+5BWSElVriWmudH2S2cFw=
218+
github.com/hashicorp/aws-sdk-go-base/v2 v2.0.0-beta.34/go.mod h1:cR5oVK+h10mSG4T9eHaBAYfacxUlYI5vNfJuIRMGfMA=
219+
github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2 v2.0.0-beta.35 h1:FLgIkz1RPYkYG62Q+u7M/JtU2tEKPUDMeDH+WtZ04ic=
220+
github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2 v2.0.0-beta.35/go.mod h1:AQknW73NE5hbAZn/ruNomae0OJUNf5xzsAi6yDndWgs=
221221
github.com/hashicorp/awspolicyequivalence v1.6.0 h1:7aadmkalbc5ewStC6g3rljx1iNvP4QyAhg2KsHx8bU8=
222222
github.com/hashicorp/awspolicyequivalence v1.6.0/go.mod h1:9IOaIHx+a7C0NfUNk1A93M7kHd5rJ19aoUx37LZGC14=
223223
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=

internal/conns/awsclient.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@ type AWSClient struct {
3333
Session *session_sdkv1.Session
3434
TerraformVersion string
3535

36-
awsConfig *aws_sdkv2.Config
37-
clients map[string]any
38-
conns map[string]any
39-
endpoints map[string]string // From provider configuration.
40-
httpClient *http.Client
41-
lock sync.Mutex
42-
s3UsePathStyle bool // From provider configuration.
43-
stsRegion string // From provider configuration.
36+
awsConfig *aws_sdkv2.Config
37+
clients map[string]any
38+
conns map[string]any
39+
endpoints map[string]string // From provider configuration.
40+
httpClient *http.Client
41+
lock sync.Mutex
42+
s3UsePathStyle bool // From provider configuration.
43+
s3UsEast1RegionalEndpoint endpoints_sdkv1.S3UsEast1RegionalEndpoint // From provider configuration.
44+
stsRegion string // From provider configuration.
4445
}
4546

4647
// PartitionHostname returns a hostname with the provider domain suffix for the partition
@@ -145,6 +146,7 @@ func (client *AWSClient) apiClientConfig(servicePackageName string) map[string]a
145146
switch servicePackageName {
146147
case names.S3:
147148
m["s3_use_path_style"] = client.s3UsePathStyle
149+
m["s3_us_east_1_regional_endpoint"] = client.s3UsEast1RegionalEndpoint
148150
case names.STS:
149151
m["sts_region"] = client.stsRegion
150152
}

internal/conns/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
awsbase "github.com/hashicorp/aws-sdk-go-base/v2"
1414
awsbasev1 "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2"
1515
basediag "github.com/hashicorp/aws-sdk-go-base/v2/diag"
16+
"github.com/hashicorp/aws-sdk-go-base/v2/logging"
1617
"github.com/hashicorp/terraform-plugin-log/tflog"
1718
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1819
"github.com/hashicorp/terraform-provider-aws/internal/errs"
@@ -41,6 +42,7 @@ type Config struct {
4142
Region string
4243
RetryMode aws_sdkv2.RetryMode
4344
S3UsePathStyle bool
45+
S3UsEast1RegionalEndpoint endpoints_sdkv1.S3UsEast1RegionalEndpoint
4446
SecretKey string
4547
SharedConfigFiles []string
4648
SharedCredentialsFiles []string
@@ -59,6 +61,8 @@ type Config struct {
5961
func (c *Config) ConfigureProvider(ctx context.Context, client *AWSClient) (*AWSClient, diag.Diagnostics) {
6062
var diags diag.Diagnostics
6163

64+
ctx, logger := logging.NewTfLogger(ctx)
65+
6266
awsbaseConfig := awsbase.Config{
6367
AccessKey: c.AccessKey,
6468
APNInfo: StdUserAgentProducts(c.TerraformVersion),
@@ -70,6 +74,7 @@ func (c *Config) ConfigureProvider(ctx context.Context, client *AWSClient) (*AWS
7074
Insecure: c.Insecure,
7175
HTTPClient: client.HTTPClient(),
7276
HTTPProxy: c.HTTPProxy,
77+
Logger: logger,
7378
MaxRetries: c.MaxRetries,
7479
Profile: c.Profile,
7580
Region: c.Region,
@@ -204,6 +209,7 @@ func (c *Config) ConfigureProvider(ctx context.Context, client *AWSClient) (*AWS
204209
client.conns = make(map[string]any, 0)
205210
client.endpoints = c.Endpoints
206211
client.s3UsePathStyle = c.S3UsePathStyle
212+
client.s3UsEast1RegionalEndpoint = c.S3UsEast1RegionalEndpoint
207213
client.stsRegion = c.STSRegion
208214

209215
return client, diags

internal/provider/fwprovider/provider.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ func (p *fwprovider) Schema(ctx context.Context, req provider.SchemaRequest, res
9595
Optional: true,
9696
Description: "Set this to true to enable the request to use path-style addressing,\ni.e., https://s3.amazonaws.com/BUCKET/KEY. By default, the S3 client will\nuse virtual hosted bucket addressing when possible\n(https://BUCKET.s3.amazonaws.com/KEY). Specific to the Amazon S3 service.",
9797
},
98+
"s3_us_east_1_regional_endpoint": schema.StringAttribute{
99+
Optional: true,
100+
Description: "Specifies whether S3 API calls in the `us-east-1` region use the legacy global endpoint or a regional endpoint. " + //lintignore:AWSAT003
101+
"Valid values are `legacy` or `regional`. " +
102+
"Can also be configured using the `AWS_S3_US_EAST_1_REGIONAL_ENDPOINT` environment variable or the `s3_us_east_1_regional_endpoint` shared config file parameter",
103+
},
98104
"secret_key": schema.StringAttribute{
99105
Optional: true,
100106
Description: "The secret key for API operations. You can retrieve this\nfrom the 'Security & Credentials' section of the AWS console.",

internal/provider/provider.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
"github.com/aws/aws-sdk-go-v2/aws"
1515
"github.com/aws/aws-sdk-go-v2/feature/ec2/imds"
16+
"github.com/aws/aws-sdk-go/aws/endpoints"
1617
awsbase "github.com/hashicorp/aws-sdk-go-base/v2"
1718
multierror "github.com/hashicorp/go-multierror"
1819
"github.com/hashicorp/terraform-plugin-log/tflog"
@@ -158,6 +159,13 @@ func New(ctx context.Context) (*schema.Provider, error) {
158159
"use virtual hosted bucket addressing when possible\n" +
159160
"(https://BUCKET.s3.amazonaws.com/KEY). Specific to the Amazon S3 service.",
160161
},
162+
"s3_us_east_1_regional_endpoint": {
163+
Type: schema.TypeString,
164+
Optional: true,
165+
Description: "Specifies whether S3 API calls in the `us-east-1` region use the legacy global endpoint or a regional endpoint. " + //lintignore:AWSAT003
166+
"Valid values are `legacy` or `regional`. " +
167+
"Can also be configured using the `AWS_S3_US_EAST_1_REGIONAL_ENDPOINT` environment variable or the `s3_us_east_1_regional_endpoint` shared config file parameter",
168+
},
161169
"secret_key": {
162170
Type: schema.TypeString,
163171
Optional: true,
@@ -478,6 +486,14 @@ func configure(ctx context.Context, provider *schema.Provider, d *schema.Resourc
478486
config.RetryMode = mode
479487
}
480488

489+
if v, ok := d.Get("s3_us_east_1_regional_endpoint").(string); ok && v != "" {
490+
endpoint, err := endpoints.GetS3UsEast1RegionalEndpoint(v)
491+
if err != nil {
492+
return nil, sdkdiag.AppendFromErr(diags, err)
493+
}
494+
config.S3UsEast1RegionalEndpoint = endpoint
495+
}
496+
481497
if v, ok := d.GetOk("allowed_account_ids"); ok && v.(*schema.Set).Len() > 0 {
482498
config.AllowedAccountIds = flex.ExpandStringValueSet(v.(*schema.Set))
483499
}

internal/service/s3/service_package.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"context"
88

99
aws_sdkv1 "github.com/aws/aws-sdk-go/aws"
10+
endpoints_sdkv1 "github.com/aws/aws-sdk-go/aws/endpoints"
1011
request_sdkv1 "github.com/aws/aws-sdk-go/aws/request"
1112
session_sdkv1 "github.com/aws/aws-sdk-go/aws/session"
1213
s3_sdkv1 "github.com/aws/aws-sdk-go/service/s3"
@@ -21,6 +22,10 @@ func (p *servicePackage) NewConn(ctx context.Context, m map[string]any) (*s3_sdk
2122
S3ForcePathStyle: aws_sdkv1.Bool(m["s3_use_path_style"].(bool)),
2223
}
2324

25+
if v, ok := m["s3_us_east_1_regional_endpoint"]; ok {
26+
config.S3UsEast1RegionalEndpoint = v.(endpoints_sdkv1.S3UsEast1RegionalEndpoint)
27+
}
28+
2429
return s3_sdkv1.New(sess.Copy(config)), nil
2530
}
2631

website/docs/index.html.markdown

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ credential_process = custom-process --username jdoe
241241
|Retry Mode|`retry_mode`|`AWS_RETRY_MODE`|`retry_mode`|
242242
|Shared Config Files|`shared_config_files`|`AWS_CONFIG_FILE`|N/A|
243243
|Shared Credentials Files|`shared_credentials_files`|`AWS_SHARED_CREDENTIALS_FILE`|N/A|
244+
|S3 Use Regional Endpoint for `us-east-1`|`s3_us_east_1_regional_endpoint`|`AWS_S3_US_EAST_1_REGIONAL_ENDPOINT`|`s3_us_east_1_regional_endpoint`|
244245
|Use DualStack Endpoints|`use_dualstack_endpoint`|`AWS_USE_DUALSTACK_ENDPOINT`|`use_dualstack_endpoint`|
245246
|Use FIPS Endpoints|`use_fips_endpoint`|`AWS_USE_FIPS_ENDPOINT`|`use_fips_endpoint`|
246247

@@ -326,7 +327,13 @@ In addition to [generic `provider` arguments](https://www.terraform.io/docs/conf
326327
* `retry_mode` - (Optional) Specifies how retries are attempted.
327328
Valid values are `standard` and `adaptive`.
328329
Can also be configured using the `AWS_RETRY_MODE` environment variable or the shared config file parameter `retry_mode`.
329-
* `s3_use_path_style` - (Optional) Whether to enable the request to use path-style addressing, i.e., `https://s3.amazonaws.com/BUCKET/KEY`. By default, the S3 client will use virtual hosted bucket addressing, `https://BUCKET.s3.amazonaws.com/KEY`, when possible. Specific to the Amazon S3 service.
330+
* `s3_use_path_style` - (Optional) Whether to enable the request to use path-style addressing, i.e., `https://s3.amazonaws.com/BUCKET/KEY`.
331+
By default, the S3 client will use virtual hosted bucket addressing, `https://BUCKET.s3.amazonaws.com/KEY`, when possible.
332+
Specific to the Amazon S3 service.
333+
* `s3_us_east_1_regional_endpoint` - (Optional) Specifies whether S3 API calls in the `us-east-1` region use the legacy global endpoint or a regional endpoint.
334+
Valid values are `legacy` or `regional`.
335+
Can also be configured using the `AWS_S3_US_EAST_1_REGIONAL_ENDPOINT` environment variable or the `s3_us_east_1_regional_endpoint` shared config file parameter.
336+
Specific to the Amazon S3 service.
330337
* `secret_key` - (Optional) AWS secret key. Can also be set with the `AWS_SECRET_ACCESS_KEY` environment variable, or via a shared configuration and credentials files if `profile` is used. See also `access_key`.
331338
* `shared_config_files` - (Optional) List of paths to AWS shared config files. If not set, the default is `[~/.aws/config]`. A single value can also be set with the `AWS_CONFIG_FILE` environment variable.
332339
* `shared_credentials_files` - (Optional) List of paths to the shared credentials file. If not set and a profile is used, the default value is `[~/.aws/credentials]`. A single value can also be set with the `AWS_SHARED_CREDENTIALS_FILE` environment variable.

0 commit comments

Comments
 (0)