From 56316e25bde821c510a51eb627f7c859fcc3e206 Mon Sep 17 00:00:00 2001 From: Zhenguo Niu Date: Mon, 30 Dec 2024 16:56:32 +0800 Subject: [PATCH] feat(provider): add default value for shared config file (#6091) --- huaweicloud/provider.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/huaweicloud/provider.go b/huaweicloud/provider.go index 159d8abefc..0defdb0053 100644 --- a/huaweicloud/provider.go +++ b/huaweicloud/provider.go @@ -6,6 +6,7 @@ import ( "fmt" "log" "os" + "runtime" "strings" "sync" @@ -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") } @@ -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