Skip to content

Commit

Permalink
feat(provider): add default value for shared config file (#6091)
Browse files Browse the repository at this point in the history
  • Loading branch information
niuzhenguo authored Dec 30, 2024
1 parent d48b9f2 commit 56316e2
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion huaweicloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"log"
"os"
"runtime"
"strings"
"sync"

Expand Down Expand Up @@ -2575,12 +2576,13 @@ func configureProvider(_ context.Context, d *schema.ResourceData, terraformVersi

conf.Region = d.Get("region").(string)

if conf.SharedConfigFile != "" {
if conf.SharedConfigFile != "" || conf.Profile != "" {
err := readConfig(&conf)
if err != nil {
return nil, diag.FromErr(err)
}
}

if conf.Region == "" {
return nil, diag.Errorf("region should be provided")
}
Expand Down Expand Up @@ -2724,6 +2726,13 @@ func getCloudDomain(cloud, region string) string {
}

func readConfig(c *config.Config) error {
if c.SharedConfigFile == "" {
c.SharedConfigFile = fmt.Sprintf("%s/.hcloud/config.json", os.Getenv("HOME"))
if runtime.GOOS == "windows" {
c.SharedConfigFile = fmt.Sprintf("%s/.hcloud/config.json", os.Getenv("USERPROFILE"))
}
}

profilePath, err := homedir.Expand(c.SharedConfigFile)
if err != nil {
return err
Expand Down

0 comments on commit 56316e2

Please sign in to comment.