获取默认区域/区域

Get default zone / region

我正在使用 Golang google-cloud-sdk 来获取有关资源的信息(特别是这里的计算实例,但这并不重要)。

gcloud cli 允许做这样的事情:

gcloud config set compute/zone ZONE

在幕后将 ~/.config/gcloud/configurations/config_default 将这些值写入看起来像 ini 文件的内容。

(go) sdk 可以读取配置文件吗?

如果未在配置文件中定义,cli 还会读取环境变量 CLOUDSDK_COMPUTE_ZONE

sdk 也可以读取这个变量吗?

总结一下这个问题,我如何使用 gcloud cli 与 Go sdk 使用的相同配置机制?

To sum up the question , how can I use the same config mechanism the gcloud cli uses with the Go sdk ?

据我所知,你不能。您需要为所有操作指定区域。 很久以前,有人问过 CLOUDSDK_CONFIG 最后的回复很清楚:

 Resolved: we decided not to honor CLOUDSDK_CONFIG, in the interest of maintaining simplicity for the ADC spec.

https://github.com/googleapis/google-cloud-go/issues/288

而且我认为所有 CLOUDSDK_* 环境都是如此。