@@ -319,20 +319,14 @@ func (b *Backend) configure(ctx context.Context) error {
319319 }
320320
321321 if endpoint == "" {
322- endpointItem , _ := b .getOSSEndpointByRegion (accessKey , secretKey , securityToken , region )
323- if endpointItem != nil && len (endpointItem .Endpoint ) > 0 {
324- if len (endpointItem .Protocols .Protocols ) > 0 {
325- // HTTP or HTTPS
326- schma = strings .ToLower (endpointItem .Protocols .Protocols [0 ])
327- for _ , p := range endpointItem .Protocols .Protocols {
328- if strings .ToLower (p ) == "https" {
329- schma = strings .ToLower (p )
330- break
331- }
332- }
322+ endpointsResponse , _ := b .getOSSEndpointByRegion (accessKey , secretKey , securityToken , region )
323+ for _ , endpointItem := range endpointsResponse .Endpoints .Endpoint {
324+ if endpointItem .Type == "openAPI" {
325+ endpoint = endpointItem .Endpoint
326+ break
333327 }
334- endpoint = endpointItem . Endpoint
335- } else {
328+ }
329+ if endpoint == "" {
336330 endpoint = fmt .Sprintf ("oss-%s.aliyuncs.com" , region )
337331 }
338332 }
@@ -367,8 +361,8 @@ func (b *Backend) configure(ctx context.Context) error {
367361 return err
368362}
369363
370- func (b * Backend ) getOSSEndpointByRegion (access_key , secret_key , security_token , region string ) (* location.DescribeEndpointResponse , error ) {
371- args := location .CreateDescribeEndpointRequest ()
364+ func (b * Backend ) getOSSEndpointByRegion (access_key , secret_key , security_token , region string ) (* location.DescribeEndpointsResponse , error ) {
365+ args := location .CreateDescribeEndpointsRequest ()
372366 args .ServiceCode = "oss"
373367 args .Id = region
374368 args .Domain = "location-readonly.aliyuncs.com"
@@ -379,7 +373,7 @@ func (b *Backend) getOSSEndpointByRegion(access_key, secret_key, security_token,
379373
380374 }
381375 locationClient .AppendUserAgent (TerraformUA , TerraformVersion )
382- endpointsResponse , err := locationClient .DescribeEndpoint (args )
376+ endpointsResponse , err := locationClient .DescribeEndpoints (args )
383377 if err != nil {
384378 return nil , fmt .Errorf ("Describe oss endpoint using region: %#v got an error: %#v." , region , err )
385379 }
0 commit comments