Following my previous article about resources deployment on Azure using terraform, I will now explain how you could deploy those resources through Azure DevOps.
Then you will have to create a resource group and a storage account inside. You will need the storage account to create a container that will hold you tfstate file.
Under your storage account select containers and add a new container. I created one named terraform that will be used in the pipeline.
Pipeline explanation:
Pipeline contains three tasks. The first task will install terraform tools. The second one will initialize terraform in your working directory. Based on the user input provided in the pipeline the appropriate resource will be deployed. The code on the github contains two separate directories, one for windows and one for linux machines.
Selecting windows will deploy a windows VM using terraform
The third task will apply your terraform configuration. The working directory is generated automatically from the provided parameter.
Terraform init variables:
- task: TerraformTaskV2@2
displayName: terraform init
inputs:
provider: 'azurerm'
command: 'init'
workingDirectory: '$(Build.SourcesDirectory)/${{ parameters.image }}' // your working terraform directory
backendServiceArm: 'AzureMSDN' // azure devops service connection with your subscription
backendAzureRmResourceGroupName: 'terraform' //resource group name
backendAzureRmStorageAccountName: 'geralexgrstorageaccount' //storage account name
backendAzureRmContainerName: 'terraform' //container inside storage account
backendAzureRmKey: 'terraform.tfstate' //state file name inside your storage account
On a pipeline that I was creating I wanted to push multiple docker images on an Azure container registry based on a list. In order to do that I used the docker@2 task on a loop providing the images that I had to push as a parameter. Code is attached below.
This file contains hidden or 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
This task will run steps based on the images you provide on the parameters list. An important note is that you need to have the image named accordingly in order to get a successful result. For example if you need to push on geralexgr.azurecr.io you will need to have your images named as below.
In this article I will demonstrate how you can write a simple .NET console application to write data inside a blob container on an Azure storage account.
Storage accounts support the below four data structures.
For the cases of an application, I had to write every x seconds data on a file in order to get the coordinates of an app. For this purpose I selected a storage account container on which I will store the Latitude and Longitude in a .json format.
Inside my storage account I created a container which I will use named application.
Inside application container I created a file named locations.json. This will be the file that will get updated from the mobile app.
My console app consists of two .cs files. One is the location class which will be my model for the serialization.
public class Location
{
public Double Latitude { get; set; }
public Double Longitude { get; set; }
}
And the main code which consists of two functions. The RetrieveBlobContents function can read the stream content of a requested file from the blob. As I have specific names for my scenario, I hard coded them on the application. My containerName is application and the file which I want to read is called locations.json
The WriteContentOnBlob function will serialize a random Location object and will update the file every 5 seconds. The result is accomplished by writing a file locally and pushing this local file on the blob storage. The content of the file will be first extracted on the current directory/data folder.
Program.cs
This file contains hidden or 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
Azure Cosmos DB is a database solution provided from Microsoft Azure that provides 99.999% SLA for enterprise level solutions.
In this article I will demonstrate how you can write a simple .NET application to insert and fetch data from a Cosmos DB.
First things first, you should have already a cosmos DB created. Then you will need to navigate in the keys section on Azure and retrieve your connection keys.
Using data explorer on Azure you can easily create new Databases and Containers. Containers are like Tables, but they also include other entities like Stored Procedures Triggers and User Defined Functions.
In my test I created a new Database named Data on which I created the table Locations. In this location table I wanted to append some location entries, that they will contain Longitude and Latitude.
That is why I created a class inside my Console App named Location
public class Location
{
public Double Longtitude { get; set; }
public Double Latitude { get; set; }
[JsonProperty(PropertyName = "id")]
public string Id { get; set; }
}
My Program.cs is shown below:
This file contains hidden or 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
On the GetStartedDemoAsync the connection with the Cosmos DB is initialized using the connection strings and the database and container names. Its important to use the connectionMode Gateway because you will maybe face connection issues.
The function AddItemsToContainerAsync is used to insert values on the database. A common issue happens with the PartitionKey that is mandatory to be used on the CreateItemAsync function. In my case I use a random Guid value for it. You should define a JsonProperty on your model with the PartitionKey value and provide a value along with your data. On my Location loc constructor I append a new Guid as the Id value.
The QueryItemsAsync is used to retrieve the database values in a structure as your model.
The partition key is used to distribute your data into logical partition for scalability reasons. You should consider choosing an better value that is not random in order to take advantage of the Cosmos DB indexing engine.
Inside Task Main I used a while loop in order to insert some data on the cosmos DB database. As I do not have an external API source for the locations, the same location is added over and over again.
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here:
Cookie Policy