diff --git a/huaweicloud/provider.go b/huaweicloud/provider.go index 72e2247395e..ef8bc03689a 100644 --- a/huaweicloud/provider.go +++ b/huaweicloud/provider.go @@ -6,6 +6,7 @@ import ( "fmt" "log" "os" + "runtime" "strings" "sync" @@ -2558,7 +2559,22 @@ func configureProvider(_ context.Context, d *schema.ResourceData, terraformVersi if err != nil { return nil, diag.FromErr(err) } + } else if conf.Profile != "" { + conf.SharedConfigFile = fmt.Sprintf("%s/.hcloud/config.json", os.Getenv("HOME")) + if runtime.GOOS == "windows" { + conf.SharedConfigFile = fmt.Sprintf("%s/.hcloud/config.json", os.Getenv("USERPROFILE")) + } + + _, err := os.Stat(conf.SharedConfigFile) + if os.IsNotExist(err) { + return nil, diag.FromErr(err) + } + err = readConfig(&conf) + if err != nil { + return nil, diag.FromErr(err) + } } + if conf.Region == "" { return nil, diag.Errorf("region should be provided") }