Welcome to Az Kung Fu, grasshopper! Scripting is the only way to ensure that your environments are the same every time and remove the risk of human error. We write scripts all the time using the Azure CLI, but it feels like we always having to figure out the same commands over and over.
Azure CLI Kung Fu is an ever-growing library of Azure CLI samples that you can use to build out your scripts quickly without having to do the heavy lifting. Our goal for Azure CLI Kung Fu is to provide real-world samples that you can use for your DevOps implementations. Microsoft provides an extensive reference, but we’ve found it be to be much easier when there are Azure CLI examples to start from!
Install the Azure CLI
The Azure CLI is a powerful and fast tool that can be used to work with almost any service in Azure. The AZ CLI is cross-platform and can be installed and run from Windows, Macs, Linux, and even a Docker container.
Visit the Azure CLI install page.
All the scripts in this reference are written in bash. If you wish to run these scripts natively on Windows you will first need to install the Windows Subsystem for Linux. After you have bash for WSL up and running, next install the Azure CLI for bash. You can also provision the Azure Kung Fu VM to get started right away with the toolkit.
All code here was written using Visual Studio Code with the Azure CLI Extension. The great thing about this product is that it supplies IntelliSense when you are writing your code and also supports running from within the terminal.
Downloading and Using the Azure Kung Fu Toolkit
Connect to the Azure Kung Fu Toolkit repo on Github and either fork, clone or download.
Open the folder using Visual Studio Code and examine the folders and scripts. Each of the folders contains scripts that we’ve built for many different types of scenarios. The folders are broken down into different Azure resource types such as Compute, Storage, Networking or Containers. In each folder, there are sample scripts.
The folders match up to the az command groups. For example, if you want to work with networking the az cli has a command group named ‘network’. You would run az network to access these commands, so in the folders, you will find the Azure Kung Fu samples in the folder /network.
If you wanted to work with vnets the az command would be ‘az network vnet’, so the samples will be in the following folder.
In the folders there are scripts that will then be named based on the resource name (noun) and the type of action (verb) based on what the script will perform. For example, a script that will create a new Virtual Network will be named:
The Azure CLI requires that you authenticate to run commands against your subscription. Run the following command to authenticate.
Make sure to use the Azure AD login account that has access to the subscriptions you wish to use.
Next, you will need to set the subscription that you wish to use with the Azure CLI. This can be done using the script in the /account/set folder.
Update the script with your subscription name or Id. Once this is set you will then be able to run this script or just the command. This will then allow you to use the other scripts in the toolkit. To run the script you can open a bash command window or use the integrated Terminal window in VS Code.
From the ../account/set folder you will need to run the following command. This same pattern can be used with all of the scripts in the toolkit.
You can also run commands from the script by highlighting text, right-click and then click Run Line in Terminal or using the key combination of Control and apostrophe (Ctrl+ ‘).
Create a VNet using the toolkit
Now, that you have are authenticated to Azure and have set your subscription you can use the toolkit samples to get started. With the Azure Kung Fu repo folder open in VS Code, use the following instructions to create a Resource Group and VNet.
First we need to create a Resource Group. Open the /group/create/group-create.azcli and update the variables with the RG name: az-kung-fu-vnet-rg and the location: eastus2.
The command will run and provide the output that the resource group is now created.
Review the notes in the script and update the variables to customize the script to your needs.
In this example, we have some instructions that explain to update the variables in order to create a new vnet which includes the resource group name, location, vnet name, and ip address scheme for the vnet.
With your variables updated simply run the script and you will have a vnet with two subnets.
Good luck with the toolkit and make sure to help us add to it! We are welcoming PR!