diff --git a/internal/backend/remote-state/oss/backend.go b/internal/backend/remote-state/oss/backend.go index 4502509a7766..6819f84bae60 100644 --- a/internal/backend/remote-state/oss/backend.go +++ b/internal/backend/remote-state/oss/backend.go @@ -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, @@ -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) diff --git a/website/docs/language/backend/oss.mdx b/website/docs/language/backend/oss.mdx index f0acbdd19c7c..b7806dc3268b 100644 --- a/website/docs/language/backend/oss.mdx +++ b/website/docs/language/backend/oss.mdx @@ -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`.