top of page
Search

All about AZD - Azure Developer CLI

  • Writer: Nathan
    Nathan
  • 4 minutes ago
  • 4 min read

The Azure Developer CLI, aka AZD, is a tool that can assist you with easily building an app and deploying it to Azure, all with simple-to-use CLI commands.



AZD Templates



AZD uses templates, which contain all of the files & folders required to build and deploy an app. A Template is nothing more than a folder, or GitHub repo, that contains a few key items. Above you will see a picture showing an example template highlighting the most common components. One, it contains the source code and build files for your app. Another key item would be the Bicep or Terraform infrastructure-as-code files which describe the Azure infrastructure that's required by your app. Finally, an AZD template includes a file named "azure.yaml" which is the master configuration file describing how the template works. This is not an exhaustive list, and a template can include more files (such as CI/CD pipelines) or it could contain files in different places (like putting the source code in the root directory). Please see the docs for more information.


Also, see the Awesome AZD website for a collection of hundreds of different example templates that you could use for your project.


Initializing a Template


You have a few options when it comes to initializing an AZD Template as the "azd init" command can be used in different ways:


  • Just run "azd init" with no options, and you will be given some interactive choices to help guide you in initializing a template:

    • If you are working with an existing app with existing source code, then you can pick the option to "Scan current directory" and azd will create the necessary template files based on what it detects in your source code.

    • Or, you could pick "Select a template" and you will be given a curated list of online templates that you could pick from.

  • You can also run "azd init --template" and manually specify a template to use:

    • Specify a full URI to an online template

    • Specify a GitHub repo in the form of "<owner>/<repo>"

    • Specify a GitHub repo found under https://github.com/Azure-Samples in the form of "<repo>"

    • Specify the path to a local directory that contains template files

  • Lastly, you could run "azd init --minimal" to create a minimal, barebones template



Common AZD Commands


So, once you have initialized an AZD Template what are your next steps? Let's talk about a few common AZD commands and what they are used for:



First, let's talk about the "azd up" command. This is a very popular command that you will see often in the Microsoft docs. "azd up" combines three other commands into one, easy-to-use command. First, it runs "azd package" in order to prepare the app's source code. Depending on your app, this can include various things like building or compiling the app, bundling dependencies, or creating deployment artifacts such as Docker container images. Next, it runs "azd provision" which creates all of the Azure infrastructure required by your app. This is driven by the IaC files founder under the "infra" folder of your template. Lastly, it runs "azd deploy" which takes the application artifacts that were created in stage 1 and deploys them onto the Azure infrastructure created in stage 2.


Another important command is "azd auth". This allows you to login to Azure, which is required before you can deploy or update any resources in Azure.


Lastly, there is the "azd down" command, which deletes all resources that were provisioned to Azure.


These are just a few examples. There are many more azd commands not covered here. Please see the docs for more information.



The azure.yaml file


The azure.yaml file is the main configuration file used by azd. It controls everything about how azd operates. For the full, official schema of the azure.yaml see this link: https://aka.ms/azure.yaml.json


The azure.yaml file only has 2 required elements: "name" and "services"


  • The "name" field is self-explanatory.

  • The "services" object defines one or more services that make up your app. Each service has multiple required fields:

    • "project" points to the location of the service's source code in the azd template

    • "host" defines which type of Azure hosting this service will be deployed on. Examples include Container Apps, Functions, Static Web Apps, and more. For a full list of supported hosts please see the docs. Note: the list of available options can also be updated/changed by installing azd extensions.

    • "language" defines the language that the service uses. Examples include Node.js, Python, Java, and more. For a full list of supported languages please see the docs.


This is just a quick intro. There are many, many more fields available. For more details about azure.yaml and the rest of its structure please see the docs.


One final question ... the azure.yaml file specifies the source code of each service, and it specifies what type of Azure hosting to use for each service, but how does it choose which specific Azure resource to actually deploy to? One option is to manually configure that by specifying the "resourceGroup" and "resourceName" options of your "service". But, if those fields are omitted, then there is some built-in logic that reads the Azure Tags of your resources:

  • It looks for resource groups that have a tag of "azd-env-name" with a value that matches the currently selected azd environment. (I have not discussed azd environments yet ... maybe that will be a future blog post?).

  • Then, inside those matching resource groups it looks for Azure resources that have a tag of "azd-service-name" with a value that matches the service name found in the azure.yaml file



This was a quick introduction to the Azure Developer CLI and how to get started using it. Hopefully you found it useful. Let me know if you want me to cover any other subjects regarding AZD.

 
 
 
bottom of page