UDIT GAURAV
UDIT GAURAV

Reputation: 53

Azure Go SDK for stopping an instance and restarting it

Description

I wanted to perform the following task using GO SDK for which I couldn't found any good example:

  1. The first part is establishing the connection for which I used:
package main

import (
        "fmt"
        "github.com/Azure/go-autorest/autorest/azure/auth"
)

func main() {
  authorizer, err := auth.NewAuthorizerFromEnvironment()

not sure it is the correct one. Anything else we need to set up here.

  1. For stopping the VM couldn't get the exact function but in the Go SDK code I found one:

https://github.com/Azure-Samples/azure-sdk-for-go-samples/blob/ffcdafe9818d55dbc2134db1548e1ed10b4a6092/compute/vm.go#L168

  1. Same for starting the VM:

https://github.com/Azure-Samples/azure-sdk-for-go-samples/blob/ffcdafe9818d55dbc2134db1548e1ed10b4a6092/compute/vm.go#L184

How to use it in GO SDK using the client?

Upvotes: 0

Views: 302

Answers (1)

Charles Xu
Charles Xu

Reputation: 31424

Of course, you can use the environment to authenticate and already set all the necessary environment variables. Then there is no problem with the samples.

If you're not familiar with the necessary environment variables, I recommend you use file-based authentication. It's more simple.

You can simply create the VM client with your select authorizer:

vmClient := compute.NewVirtualMachinesClient("subcriptionID")

This VM client will help you start and stop the VM as you want.

Upvotes: 1

Related Questions