In AzureCLI@2 you may choose from a variety of options when it comes on how this task will be executed on the agent machine. I usually choose powershell for windows machines and powershell core for Unix based machines (pwsh).
Recently I got an error on a Windows machine when using Powershell core. The latest version of powershell which is currently on 7.* version can be used as pscore in the AzureCLI@2 task.
##[error]Script failed with error: Error: Unable to locate executable file: ‘pwsh’. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also verify the file has a valid extension for an executable file.
In order to bypass this problem you should make sure that the latest version of powershell which is multiplatform should be installed on your system. At the time of this article this version is 7.*
After installing powershell you should make a restart also on the machine in order for the environmental variables to be added on PATH. Then you can execute your pwsh tasks on your agent machines.
Sometimes you may need to automatically create windows disk for a virtual server using an automation mechanism. With the below powershell you can initialize a new emtpy disk with GPT partition and format it according to your needs.
You can get your available disks using:
You can use the below powershell and change the below settings:
DriveLetter : What your drive letter will be AllocationUnitSize: Default is 4k, but in my case I define 64k DiskNumber: number of disk from Get-Disk command NewFileSystemLabel: name of the volume
Terraform is one of the best automation providers for DevOps purposes used by hundred of Engineers. It is an open source tool that can be used by anyone for free. In this article I will explain how to deploy windows and linux virtual machines on Azure using a Terraform template.
First things first you will need to have the az cli installed. Then you will have to set your subscription on your current powershell session.
az account set --subscription "12abc123-4567-1234-12345-asdr4334fsd"
Then you will need to create an app role assignment for your subscription. This will be used from terraform for the provision of the resources.
az ad sp create-for-rbac --role="Contributor" --scopes="/subscriptions/12abc123-4567-1234-12345-asdr4334fsd"
That’s all. You can now deploy your resources through terraform. In the links below I have provided my Github repository along with instructions for the template use.
A tricky part of the deployment is the vm image selection. In order to locate the available azure images names you can use: