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?

王林
Release: 2024-02-08 20:54:02
forward
896 people have browsed it

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
}
Copy after login

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!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template