Skip to content

Commit 3990cdc

Browse files
committed
Fix: ConfigureRegion() throws error if the region is set by environment variable
1 parent 0f45891 commit 3990cdc

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

core/config/config.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,10 +499,12 @@ func ConfigureRegion(cfg *Configuration) error {
499499
availableRegions = append(availableRegions, strings.TrimSuffix(regionWithDotSuffix, "."))
500500
}
501501

502+
isRegionSetByEnv := false
502503
if cfg.Region == "" {
503504
// Check region
504505
envVarRegion, _ := os.LookupEnv("STACKIT_REGION")
505506
cfg.Region = envVarRegion
507+
isRegionSetByEnv = true
506508
}
507509

508510
if oasRegion.DefaultValue != "" && oasRegion.DefaultValue != global {
@@ -524,9 +526,9 @@ func ConfigureRegion(cfg *Configuration) error {
524526
return fmt.Errorf("the provided region is not available for this API, available regions are: %s", availableRegions)
525527
}
526528
// Global API.
527-
// If a region is provided by the user via WithRegion() or via environment variable return an error.
529+
// If a region is provided by the user via WithRegion() return an error.
528530
// The region is provided as a function argument instead of being set in the client configuration.
529-
if cfg.Region != "" {
531+
if cfg.Region != "" && !isRegionSetByEnv {
530532
return fmt.Errorf("this API does not support setting a region in the the client configuration, please check if the region can be specified as a function parameter")
531533
}
532534
// If the url is a template, generated using deprecated config.json, the region variable is replaced

0 commit comments

Comments
 (0)