Skip to content

Commit 3534df8

Browse files
authored
Merge pull request #29850 from hashicorp/backport/xiaozhu/moderately-ample-gelding
Backport of backend/oss: Supports the new attribute sts_endpoint into v1.0
2 parents 5e80168 + 4850e12 commit 3534df8

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

internal/backend/remote-state/oss/backend.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7+
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/endpoints"
78
"io/ioutil"
89
"log"
910
"net/http"
@@ -69,6 +70,12 @@ func New() backend.Backend {
6970
Description: "The region of the OSS bucket.",
7071
DefaultFunc: schema.EnvDefaultFunc("ALICLOUD_REGION", os.Getenv("ALICLOUD_DEFAULT_REGION")),
7172
},
73+
"sts_endpoint": {
74+
Type: schema.TypeString,
75+
Optional: true,
76+
Description: "A custom endpoint for the STS API",
77+
DefaultFunc: schema.EnvDefaultFunc("ALICLOUD_STS_ENDPOINT", ""),
78+
},
7279
"tablestore_endpoint": {
7380
Type: schema.TypeString,
7481
Optional: true,
@@ -262,6 +269,7 @@ func (b *Backend) configure(ctx context.Context) error {
262269
securityToken := getBackendConfig(d.Get("security_token").(string), "sts_token")
263270
region := getBackendConfig(d.Get("region").(string), "region_id")
264271

272+
stsEndpoint := d.Get("sts_endpoint").(string)
265273
endpoint := d.Get("endpoint").(string)
266274
schma := "https"
267275

@@ -311,7 +319,7 @@ func (b *Backend) configure(ctx context.Context) error {
311319
}
312320

313321
if roleArn != "" {
314-
subAccessKeyId, subAccessKeySecret, subSecurityToken, err := getAssumeRoleAK(accessKey, secretKey, securityToken, region, roleArn, sessionName, policy, sessionExpiration)
322+
subAccessKeyId, subAccessKeySecret, subSecurityToken, err := getAssumeRoleAK(accessKey, secretKey, securityToken, region, roleArn, sessionName, policy, stsEndpoint, sessionExpiration)
315323
if err != nil {
316324
return err
317325
}
@@ -383,7 +391,7 @@ func (b *Backend) getOSSEndpointByRegion(access_key, secret_key, security_token,
383391
return endpointsResponse, nil
384392
}
385393

386-
func getAssumeRoleAK(accessKey, secretKey, stsToken, region, roleArn, sessionName, policy string, sessionExpiration int) (string, string, string, error) {
394+
func getAssumeRoleAK(accessKey, secretKey, stsToken, region, roleArn, sessionName, policy, stsEndpoint string, sessionExpiration int) (string, string, string, error) {
387395
request := sts.CreateAssumeRoleRequest()
388396
request.RoleArn = roleArn
389397
request.RoleSessionName = sessionName
@@ -401,6 +409,9 @@ func getAssumeRoleAK(accessKey, secretKey, stsToken, region, roleArn, sessionNam
401409
if err != nil {
402410
return "", "", "", err
403411
}
412+
if stsEndpoint != "" {
413+
endpoints.AddEndpointMapping(region, "STS", stsEndpoint)
414+
}
404415
response, err := client.AssumeRole(request)
405416
if err != nil {
406417
return "", "", "", err

website/docs/language/settings/backends/oss.html.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ The following configuration options or environment variables are supported:
8888
* `key` - (Optional) The name of the state file. Defaults to `terraform.tfstate`.
8989
* `tablestore_endpoint` / `ALICLOUD_TABLESTORE_ENDPOINT` - (Optional) A custom endpoint for the TableStore API.
9090
* `tablestore_table` - (Optional) A TableStore table for state locking and consistency. The table must have a primary key named `LockID` of type `String`.
91+
* `sts_endpoint` - (Optional, Available in 1.0.11+) Custom endpoint for the AliCloud Security Token Service (STS) API. It supports environment variable `ALICLOUD_STS_ENDPOINT`.
9192
* `encrypt` - (Optional) Whether to enable server side
9293
encryption of the state file. If it is true, OSS will use 'AES256' encryption algorithm to encrypt state file.
9394
* `acl` - (Optional) [Object

0 commit comments

Comments
 (0)