Infrastructure as a code (IaC) is a practice in software engineering that involves managing and provisioning computer infrastructure through machine-readable configuration files, rather than manual configuration. With IaC, developers can treat infrastructure as they would any other code, allowing them to version control and automate the deployment, management, and scaling of their infrastructure.
IaC tools typically work by defining infrastructure configurations in a declarative language or domain-specific language (DSL), which can then be used to automatically provision and configure the necessary resources on cloud providers like Amazon Web Services (AWS), Microsoft Azure, or Google Cloud Platform (GCP). This approach helps to minimize errors and inconsistencies that can occur when manually configuring infrastructure.
• Azure Portal Prerequisite
• Azure DevOps portal Prerequisite
• Step for run code pipeline on Azure DevOps portal
(How to create Resource Group on azure portal)
Resource Group:
• ICPL-IT-IoT-Automation-RG-Connectivity
• ICPL-IT-IoT-Automation-RG-Common
• ICPL-IT-IoT-Automation-RG-UsecaseOne
• ICPL-IT-IoT-Dev-Terraform (Store .tfstate file)
Storage Account: (Inside ICPL-IT-IoT-Dev-Terraform resource Group)
• icplitiotdevstrgterraform
Container: (inside icplitiotdevstrgterraform Storage account)
• icpl-it-iot-dev-cnt-common
• icpl-it-iot-dev-cnt-connectivity
• icpl-it-iot-dev-cnt-usecaseone
(How to create service principal on azure portal)
Service Principal: • ICPL-IT-IoT-Dev-Terraform
(How to Assign permission to service principal)
Service Principal: ICPL-IT-IoT-Dev-Terraform Role: Contributor Resource Group: ICPL-IT-IoT-Automation-RG-Connectivity ICPL-IT-IoT-Automation-RG-Common ICPL-IT-IoT-Automation-RG- UsecaseOne ICPL-IT-IoT-Dev-Terraform
(How to create project in azure devOps portal)
Project Name: ICPL-IoT-Dev-Connectivity ICPL-IoT-Dev-Common ICPL-IoT-Dev-UsecaseOne
(How to add free extension (terraform))
Add terraform extension into azure devOps portal.
(How to create service connection)
Create Service connection for each Project in azure DevOps portal and follow the following naming pattern for service connection.
Project Name: ICPL-IoT-Dev-Connectivity
Service Connection: ICPL-IT-IoT-Dev-Connectivity-SC
Project Name: ICPL-IoT-Dev-Common
Service Connection: ICPL-IT-IoT-Dev-Common-SC
Project Name: ICPL-IoT-Dev-UsecaseOne
Service Connection: ICPL-IT-IoT-Dev-UsecaseOne-SC
(How to create variable group classic in azure devOps portal)
Project Name:
ICPL-IoT-Dev-Connectivity
Variable group name:
ICPL-IT-IoT-Dev-VG-Connectivity
Variables
Name | Value |
---|---|
backendAzureRmContainerName | icpl-it-iot-dev-cnt-connectivity |
backendAzureRmKey | icpl-it-iot-dev-cnt-connectivity.tfstate |
backendAzureRmResourceGroupName | ICPL-IT-IoT-Dev-Terraform |
backendAzureRmStorageAccountName | icplitiotdevstrgterraform |
backendServiceArm | ICPL-IT-IoT-Dev-Connectivity-SC |
tfvarsFileName | terraform-dev.tfvars |
Project Name:
ICPL-IoT-Dev-Common
Variable group name:
ICPL-IT-IoT-Dev-VG-Common
Variables
Name | Value |
---|---|
backendAzureRmContainerName | icpl-it-iot-dev-cnt-common |
backendAzureRmKey | icpl-it-iot-dev-cnt-common.tfstate |
backendAzureRmResourceGroupName | ICPL-IT-IoT-Dev-Terraform |
backendAzureRmStorageAccountName | icplitiotdevstrgterraform |
backendServiceArm | ICPL-IT-IoT-Dev-Common-SC |
tfvarsFileName | terraform-dev.tfvars |
Project Name:
ICPL-IoT-Dev-UsecaseOne
Variable group name:
ICPL-IT-IoT-Dev-VG-UsecaseOne
Variables
Name | Value |
---|---|
backendAzureRmContainerName | icpl-it-iot-dev-cnt-usecaseone |
backendAzureRmKey | icpl-it-iot-dev-cnt-usecaseone.tfstate |
backendAzureRmResourceGroupName | ICPL-IT-IoT-Dev-Terraform |
backendAzureRmStorageAccountName | icplitiotdevstrgterraform |
backendServiceArm | ICPL-IT-IoT-Dev-UsecaseOne-SC |
tfvarsFileName | terraform-dev.tfvars |
Terraform uses a declarative configuration language to define infrastructure as code, enabling teams to version, manage, and share their infrastructure configurations.
With Terraform, users can define their infrastructure requirements using a high-level, human-readable language, and then use Terraform to create, update, and delete resources as necessary. Terraform supports a wide range of cloud providers, including Amazon Web Services (AWS), Microsoft Azure, Google Cloud Platform (GCP), and many others.
• Declarative configuration: Terraform configurations define the desired state of infrastructure, rather than how to achieve that state. This approach allows users to manage infrastructure as code, rather than through manual configuration.
• Resource management: Terraform provides a unified interface for managing a wide range of cloud resources, including virtual machines, databases, load balancers, and more.
• Plan execution: Terraform executes changes in a planned and controlled manner, reducing the risk of errors or unexpected outcomes.
• Collaboration: Terraform supports version control systems, enabling teams to collaborate and share infrastructure configurations.
Terraform script content multiple resources going to create for azure resource group such like virtual network, iothub, event grid system topic, storage account, function app and so on.
Create private repo with name “infra-automation”. Push terraform script into your Bitbucket account. It helps when we push any changes on script that time pipeline trigger automatically.
One approach to code deployment is to use a continuous deployment (CD) pipeline, which automates the entire deployment process, from building and testing to deployment and monitoring. CD pipelines can help to reduce the risk of errors and enable teams to deploy changes more frequently, which can lead to faster innovation and a more responsive software development process.
Azure CI/CD Pipeline is a cloud-based continuous integration and continuous delivery service provided by Microsoft Azure. It enables developers to automatically build, test, and deploy their applications to any Azure service or on-premises server. Azure CI/CD Pipeline supports a variety of languages, frameworks, and platforms, including .NET, Java, Node.js, Python, and many others.
We have added terraform script into Bitbucket to integrate Bitbucket with azure DevOps. we must choose Bitbucket Cloud option for this. First , we must authorize our Bitbucket account with Azure DevOps.
Select any of bellow method for authentication.
Authentication type | Pipelines run using |
---|---|
OAuth | Your personal Bitbucket identity |
Username and password | Your personal Bitbucket identity |
Select repository “infra-automation” which we created in Bitbucket account and select branch where we pushed our terraform script.
Terraform script consists of three different folders: connectivity, common and UsecaseOne. Select specific yml file from mention folder and yml file created for different environments like dev, prod, and stage.
After Successfully running pipeline, we must give permission to pipeline , for that we must to click on “permit” option and pipeline going to running mode.
In conclusion, code deployment is a critical process in software development that involves delivering code changes to production environments. The goal of code deployment is to ensure that software changes are deployed quickly and reliably, while minimizing the risk of downtime or errors.