Ori
Ori

Reputation: 1

Looking for a simple way to stop\start machine with Azure runbook

I am an Azure rookie, I'm struggling to complete a runbook to start stop my VM. I keep getting permissions errors after I added myself as the virtual machine permissions contributor :

ERROR: (AuthorizationFailed) The client '6ffb2379-YYYYYYYYYYY' with object id '6ffb2379-YYYYYYYY' does not have authorization to perform action 'Microsoft.Compute/virtualMachines/start/action

enter image description here Would appreciate any guidance here

Tried running this script:

az login --identity --username "my identity object ID" az vm start --name "my machine name" --no-wait --resource-group "my resource group name"

Upvotes: 0

Views: 49

Answers (1)

Sridevi
Sridevi

Reputation: 22352

I agree with @wenbo, the error usually occurs if the managed identity does not have required permissions or roles to perform the operation.

Initially, I too got same error when I ran the code adding "Classic Virtual Machine Contributor" to managed identity under Azure Virtual Machine:

az login --identity --username "usermsiObjID" 
az vm start --name "vmname" --no-wait --resource-group "rgname"

Response:

enter image description here

To resolve the error, make sure to grant "Virtual Machine Contributor" role to user-assigned managed identity under your Azure Virtual Machine like this:

enter image description here

When I ran the code again after granting the role assignment, I got the response as below:

enter image description here

To confirm that, I checked the same in Portal where Azure VM started successfully as below:

enter image description here

Upvotes: 0

Related Questions