This sample code from the Go SDK通过部署 ARM 模板创建虚拟机。它要求您包含来自服务主体的 clientId 和 clientSecret。
This sample code from the Go SDK使用适用于 Azure 的 Go SDK 创建虚拟机。它需要订阅 ID,但不需要服务主体(客户端 ID、客户端 key )。它也不会自动创建服务主体。
我认为创建虚拟机需要服务主体,但 GO SDK 示例能够在不指定服务主体的情况下创建虚拟机。我对服务主体和虚拟机缺少什么?
最佳答案
它使用NewDefaultAzureCredential ,此类从环境中检索身份验证信息(例如 azure CLI、环境变量)- see docs
func connectionAzure() (azcore.TokenCredential, error) {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
return nil, err
}
return cred, nil
}
关于azure - Go SDK for Azure 如何在没有服务主体的情况下创建虚拟机?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74976179/