In this article I will demonstrate how one can deploy app service code on Azure through Azure DevOps. App service is a hosting provider for your applications (web app) that can be created with multiple hosting options and application specific settings.
When creating an app service you can choose from many available options like different code frameworks or even container deployments.
For my demo I wanted to deploy an asp .net core web api using .net 6 version hosted on windows app service.
My repository structure is shown below. The app service that I want to deploy is the one located under Front folder.
The pipeline code can be found below:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In more detail there are three necessary steps for the deployment.
The first task will build the .NET app using VSbuild task. The build will use as parameters the deployonBuild and the webpublishmethod as filesystem in order to specify the path on which the build output will be stored.
The second task will bundle this build output to a zip file and then the third task will upload this .zip file in the app service using a service connection with the subscription. The two parameters that should be changed are azureSubscription and WebAppName which should be the app service name.
When running the pipeline, a build folder will be created as shown in the below screenshot that will host the build output.
This output will be then zipped to a file that will be uploaded to the app service.
In this article I will demonstrate how one can create different environments for development needs through terraform modules. Modules provide great extensibility and code reuse. In this example I will use an appservice resource on Azure cloud.
The result of the deployment will be two different resource groups with two app services. The code of the demonstration is located at the bottom of the page.
You should first init your module. Navigate to the module folder and perform init
cd modules; terraform init
cd .. ; terraform init
Then validate your terraform code
The last step is to apply your configuration
You may encounter an error during the creation of the resources because of the app service name. It should be globally unique.
Change your name and perform a terraform apply again. Terraform will read your .tfstate file and will only implement the differences on infrastructure.
After the successful run you will see the green result output from terraform cli.
On Azure there should be two resource groups created. One for prod environment and one for test.
Inside each resource group there should be a different app service the one that it is created through the module according with the settings provided.