Dean Schulze
Dean Schulze

Reputation: 10303

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

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

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

I would think that a service principal would be required to create a VM, but the GO SDK example is able to create a VM without specifying a service principal. What a I missing about service principals and virtual machines?

Upvotes: 0

Views: 219

Answers (1)

burna
burna

Reputation: 2962

It uses the NewDefaultAzureCredential, this class retrieves the auth info from the environment (e.g. azure CLI, environment vars) - see docs

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

enter image description here

Upvotes: 1

Related Questions