Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backend/oss: Adds new arguement tablestore_instance_name used to VPC scenario #36253

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading