Skip to content

Commit

Permalink
backend/oss: Adds new arguement tablestore_instance_name used to VPC …
Browse files Browse the repository at this point in the history
…scenario
  • Loading branch information
xiaozhu36 committed Jan 2, 2025
1 parent 7a00c51 commit 5846769
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
13 changes: 11 additions & 2 deletions internal/backend/remote-state/oss/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@ func New() backend.Backend {
},
Default: "terraform.tfstate",
},
"tablestore_instance_name": {
Type: schema.TypeString,
Optional: true,
Description: "The instance name of tableStore table belongs",
Default: "",
},

"tablestore_table": {
Type: schema.TypeString,
Expand Down Expand Up @@ -414,13 +420,16 @@ func (b *Backend) configure(ctx context.Context) error {
client, err := oss.New(endpoint, accessKey, secretKey, options...)
b.ossClient = client
otsEndpoint := d.Get("tablestore_endpoint").(string)
otsInstanceName := d.Get("tablestore_instance_name").(string)
if otsEndpoint != "" {
if !strings.HasPrefix(otsEndpoint, "http") {
otsEndpoint = fmt.Sprintf("%s://%s", schma, otsEndpoint)
}
b.otsEndpoint = otsEndpoint
parts := strings.Split(strings.TrimPrefix(strings.TrimPrefix(otsEndpoint, "https://"), "http://"), ".")
b.otsClient = tablestore.NewClientWithConfig(otsEndpoint, parts[0], accessKey, secretKey, securityToken, tablestore.NewDefaultTableStoreConfig())
if otsInstanceName == "" {
otsInstanceName = strings.Split(strings.TrimPrefix(strings.TrimPrefix(otsEndpoint, "https://"), "http://"), ".")[0]
}
b.otsClient = tablestore.NewClientWithConfig(otsEndpoint, otsInstanceName, accessKey, secretKey, securityToken, tablestore.NewDefaultTableStoreConfig())
}
b.otsTable = d.Get("tablestore_table").(string)

Expand Down
3 changes: 3 additions & 0 deletions website/docs/language/backend/oss.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ The following configuration options or environment variables are supported:

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

* `tablestore_instance_name` - (Optional, Available since v1.11.0) A instance name of TableStore belongs. Default to parsing from `tablestore_endpoint`.
It should be set Access URL explicitly when tablestore endpoint is a VPC access url

* `tablestore_table` - (Optional) A TableStore table for state locking and consistency. The table must have a primary key named `LockID` of type `String`.

* `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`.
Expand Down

0 comments on commit 5846769

Please sign in to comment.