{"record":{"id":"b6a845b696c3689a","repo":"hashicorp/terraform","slug":"unable-to-initialize-the-location-client-v","errorCode":null,"errorMessage":"unable to initialize the location client: %#v","messagePattern":"unable to initialize the location client: %#v","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/backend/remote-state/oss/backend.go","lineNumber":452,"sourceCode":"\t\tif otsInstanceName == \"\" {\n\t\t\totsInstanceName = strings.Split(strings.TrimPrefix(strings.TrimPrefix(otsEndpoint, \"https://\"), \"http://\"), \".\")[0]\n\t\t}\n\t\tb.otsClient = tablestore.NewClientWithConfig(otsEndpoint, otsInstanceName, accessKey, secretKey, securityToken, tablestore.NewDefaultTableStoreConfig())\n\t}\n\tb.otsTable = d.Get(\"tablestore_table\").(string)\n\n\treturn err\n}\n\nfunc (b *Backend) getOSSEndpointByRegion(access_key, secret_key, security_token, region string) (*location.DescribeEndpointsResponse, error) {\n\targs := location.CreateDescribeEndpointsRequest()\n\targs.ServiceCode = \"oss\"\n\targs.Id = region\n\targs.Domain = \"location-readonly.aliyuncs.com\"\n\n\tlocationClient, err := location.NewClientWithOptions(region, getSdkConfig(), credentials.NewStsTokenCredential(access_key, secret_key, security_token))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to initialize the location client: %#v\", err)\n\n\t}\n\tlocationClient.AppendUserAgent(TerraformUA, TerraformVersion)\n\tendpointsResponse, err := locationClient.DescribeEndpoints(args)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"describe oss endpoint using region: %#v got an error: %#v\", region, err)\n\t}\n\treturn endpointsResponse, nil\n}\n\nfunc getAssumeRoleAK(accessKey, secretKey, stsToken, region, roleArn, sessionName, policy, stsEndpoint string, sessionExpiration int) (string, string, string, error) {\n\trequest := sts.CreateAssumeRoleRequest()\n\trequest.RoleArn = roleArn\n\trequest.RoleSessionName = sessionName\n\trequest.DurationSeconds = requests.NewInteger(sessionExpiration)\n\trequest.Policy = policy\n\trequest.Scheme = \"https\"\n","sourceCodeStart":434,"sourceCodeEnd":470,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/backend/remote-state/oss/backend.go#L434-L470","documentation":"Returned by getOSSEndpointByRegion when location.NewClientWithOptions fails while constructing the Alibaba Cloud Location SDK client used to discover the OSS endpoint for a region. The %#v renders the SDK error struct (usually a credential or config error).","triggerScenarios":"The backend is configured without an explicit endpoint, so configure() calls getOSSEndpointByRegion. location.NewClientWithOptions fails because the STS token credential (access_key/secret_key/security_token) is malformed or nil, or the region string is empty/invalid.","commonSituations":"Missing or blank ALICLOUD_ACCESS_KEY/SECRET_KEY env vars; empty region; running on ECS without ecs_role_name and without static creds; security_token expired; region set to an unsupported value.","solutions":["Provide valid access_key/secret_key (and security_token if using STS) in the backend block or via ALICLOUD_* env vars.","Set a valid region (e.g. cn-hangzhou, us-west-1) via region attr or ALICLOUD_REGION.","If on an ECS instance, set ecs_role_name so creds are fetched from the metadata service instead.","Avoid passing an empty string for any of access_key/secret_key/security_token."],"exampleFix":"# before\nregion  = \"\"\n# creds missing -> location client init fails\n\n# after\nregion     = \"cn-hangzhou\"\naccess_key = \"LTAI...\"\nsecret_key = \"abc...\"","handlingStrategy":"validation","validationCode":"func validateCreds(ak, sk, token, region string) error {\n    if ak == \"\" || sk == \"\" || region == \"\" {\n        return fmt.Errorf(\"access_key, secret_key and region are required when endpoint is unset\")\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if _, err := b.getOSSEndpointByRegion(ak, sk, tok, region); err != nil {\n    log.Printf(\"[WARN] location discovery failed: %v\", err)\n    endpoint = fmt.Sprintf(\"oss-%s.aliyuncs.com\", region)\n}","preventionTips":["Always set region.","Provide complete credential triples (ak, sk, optional token).","On ECS, use ecs_role_name instead of partial static creds."],"tags":["oss","auth","credentials","location","config","backend"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}