I’m not going to explain what Azure DevOps is, because it’s easy to find when you search for it. I wanted to take you with me on my journey in order to setup and maintain a cloud infrastructure through Azure DevOps. The Azure Portal is nice but we want to do everything automated with Infrastructure as Code! This is also called Continuous Integration/Continuous Delivery (CI/CD).
Infrastructure as Code (IaC) is the management of infrastructure (networks, virtual machines, load balancers, and connection topology) in a descriptive model, using the same versioning as DevOps team uses for source code. Like the principle that the same source code generates the same binary, an IaC model generates the same environment every time it is applied. IaC is a key DevOps practice and is used in conjunction with continuous delivery.Source: Microsoft
First we need to figure out how our environment will look like, since it is my first journey into the cloud I’ll start off with a Virtual Network and a few Virtual Network peers. The first virtual network will be hosting some shared resources and the Virtual Network peers are for DEV, TST, ACC and PRD.
We could configure all through the Azure Portal, but we want to automate. In order to automate we need to make use Azure Resource Templates or ARM Templates. In order to create an ARM Template you could begin with an empty template. Since I have no idea how to start, it’s easier to start within the Azure Portal.
Creating an ARM Template
Open the Azure Portal and search for virtual networks in the search bar. Select Virtual Networks and within the virtual network blade select ADD. Create a new network and provide the input needed.
At this point we do not want to select create because that will build a virtual network through the Azure Portal. We want to have an ARM Template instead to be able to automate creation or updating. So select Automation Options. Here we will be presented with an ARM Template with the all the settings. Keep the Azure Portal open, because now we need to setup Azure DevOps.
Creating an Azure DevOps
- Open in a new tab again the Azure Portal and search for Devops.
- Select the My Azure Devops Organizations link
- Select Create New Organization
- Follow the on-screen suggestions, set a name and the region and press continue
- First thing to do is create a new project
- Give your project a name, for instance Cloud Infrastructure and select Create Project
Create a Repository
We need to have a repository to store our code.
- Select on the left side Repos
There’s already a repos with the same name as the project, but i want to name the repos network because that’s what i’m doing (trying to) build a network. Renaming is a peace of cake!
- Select the arrow next to the name of the repos in the breadcrumb and select Manage repositories
- Select the 3-dots next to the name of the repository and select Rename repository
Rename the repository to whatever you like.
Go to the repository that’s been renamed and you’ll see that we need some code. It’s pretty empty here and there’s no editor. We need to clone the repository with an editor that can be used to create or edit ARM templates. I’ll be using Visual Code, select Clone in VS Code and Visual Code will be opened.
Create a new file give the file a name, but the extension of the file must be .json. For example: vnet-core-infra.json. This will be our ARM template, copy the contents of the json which has been created via the Azure Portal into the file. Next thing to do is upload the code to the repository.
Now that the repository has been created, the next step will be to create a build pipeline.
Create a Build Pipeline
What are Azure Pipelines? According to Microsoft:
Azure Pipelines is a cloud service that you can use to automatically build and test your code project and make it available to other users. It works with just about any language or project type.
Azure Pipelines combines continuous integration (CI) and continuous delivery (CD) to constantly and consistently test and build your code and ship it to any target.Source: Microsoft
- Select Pipeline on the left side
- Select Create Pipeline
- Select Use the classic editor (if you select Azure Repos Git you will end up with a YAML file)
- Select Continue
- Select Empty job
- Select the plus sign next to Agent job 1and search for copy
- Select Add with Copy files
- Select the newly added Copy files, adjust the following:
- Display name (if desired)
- Source folder (leave it empty)
- Target Folder: $(Build.ArtifactStagingDirectory)
- Select the plus sign next to Agent job 1and search for build
- Select Add with Publish build artifacts
- Select Triggers and select Enable continuous integration
- Select Save and Queue
- Add a comment and select Run
The pipeline will run and tell you if the code is ok.
In the next blog I’ll continue my journey with IaC and hopefully building a network and more.