Skip to content

Commit be8b9a4

Browse files
committed
backend/oss: Add new argument tablestore_instance_name used in VPC context
1 parent 8865218 commit be8b9a4

3 files changed

Lines changed: 19 additions & 2 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: ENHANCEMENTS
2+
body: 'backend/oss: Add new argument tablestore_instance_name used in VPC context '
3+
time: 2025-02-17T15:34:30.738421+08:00
4+
custom:
5+
Issue: "36253"

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@ func New() backend.Backend {
176176
},
177177
Default: "terraform.tfstate",
178178
},
179+
"tablestore_instance_name": {
180+
Type: schema.TypeString,
181+
Optional: true,
182+
Description: "The instance name of tableStore table belongs",
183+
Default: "",
184+
},
179185

180186
"tablestore_table": {
181187
Type: schema.TypeString,
@@ -414,13 +420,16 @@ func (b *Backend) configure(ctx context.Context) error {
414420
client, err := oss.New(endpoint, accessKey, secretKey, options...)
415421
b.ossClient = client
416422
otsEndpoint := d.Get("tablestore_endpoint").(string)
423+
otsInstanceName := d.Get("tablestore_instance_name").(string)
417424
if otsEndpoint != "" {
418425
if !strings.HasPrefix(otsEndpoint, "http") {
419426
otsEndpoint = fmt.Sprintf("%s://%s", schma, otsEndpoint)
420427
}
421428
b.otsEndpoint = otsEndpoint
422-
parts := strings.Split(strings.TrimPrefix(strings.TrimPrefix(otsEndpoint, "https://"), "http://"), ".")
423-
b.otsClient = tablestore.NewClientWithConfig(otsEndpoint, parts[0], accessKey, secretKey, securityToken, tablestore.NewDefaultTableStoreConfig())
429+
if otsInstanceName == "" {
430+
otsInstanceName = strings.Split(strings.TrimPrefix(strings.TrimPrefix(otsEndpoint, "https://"), "http://"), ".")[0]
431+
}
432+
b.otsClient = tablestore.NewClientWithConfig(otsEndpoint, otsInstanceName, accessKey, secretKey, securityToken, tablestore.NewDefaultTableStoreConfig())
424433
}
425434
b.otsTable = d.Get("tablestore_table").(string)
426435

website/docs/language/backend/oss.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ The following configuration options or environment variables are supported:
9595

9696
* `tablestore_endpoint` / `ALICLOUD_TABLESTORE_ENDPOINT` - (Optional) A custom endpoint for the TableStore API.
9797

98+
* `tablestore_instance_name` - (Optional, Available since v1.11.0) A instance name of TableStore belongs. Default to parsing from `tablestore_endpoint`.
99+
It should be set Access URL explicitly when tablestore endpoint is a VPC access url
100+
98101
* `tablestore_table` - (Optional) A TableStore table for state locking and consistency. The table must have a primary key named `LockID` of type `String`.
99102

100103
* `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`.

0 commit comments

Comments
 (0)