Home >Backend Development >Golang >Go SDK for Azure How to create a virtual machine without a service principal?

Go SDK for Azure How to create a virtual machine without a service principal?

王林
王林forward
2024-02-08 20:54:02895browse

Go SDK for Azure 如何在没有服务主体的情况下创建虚拟机?

Question content

This sample code in the Go SDK creates a virtual machine by deploying an ARM template. It requires you to include the clientId and clientSecret from the service principal.

This sample code from Go SDK creates a virtual machine using the Go SDK for Azure. It requires a subscription ID but not a service principal (client ID, client secret). It also does not automatically create service principals.

I thought that creating a virtual machine requires a service principal, but the GO SDK sample is able to create a virtual machine without specifying a service principal. What am I missing about service principals and virtual machines?


Correct answer


It uses newdefaultazurecredential, this class retrieves authentication information from the environment (e.g. azure cli, environment variables) - View documentation

func connectionAzure() (azcore.TokenCredential, error) {
    cred, err := azidentity.NewDefaultAzureCredential(nil)
    if err != nil {
        return nil, err
    }
    return cred, nil
}

The above is the detailed content of Go SDK for Azure How to create a virtual machine without a service principal?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete