?? Excited to share Azure DevOps pipelines for deploying an Azure Web App using Terraform! ????
Ong Hong Teck
Microsoft Most Valuable Professional (MVP) - Alumni | Microsoft Certified Trainer (MCT) Driving Innovation and Success as a Cloud Solution Architect @ Microsoft
Step 1: Pushing Code to Azure Repos ??
To kickstart our deployment journey, we first uploaded our Terraform code to Azure Repos. Azure Repos provides a secure and centralized location to store our code, making collaboration a breeze. With version control, we could easily track changes, revert to previous versions, and manage our infrastructure-as-code efficiently.
#?Configure?the?Azure?provide
terraform?{
??required_providers?{
????azurerm?=?{
??????source??=?"hashicorp/azurerm"
??????version?=?"~>?3.0.0"
????}
??}
??required_version?=?">=?0.14.9"
}
provider?"azurerm"?{
??features?{}
}
#?Generate?a?random?integer?to?create?a?globally?unique?name
resource?"random_integer"?"ri"?{
??min?=?10000
??max?=?99999
}
#?Create?the?resource?group
resource?"azurerm_resource_group"?"rg"?{
??name?????=?"myResourceGroup-${random_integer.ri.result}"
??location?=?"southeastasia"
}
#?Create?the?Linux?App?Service?Plan
resource?"azurerm_service_plan"?"appserviceplan"?{
??name????????????????=?"webapp-asp-${random_integer.ri.result}"
??location????????????=?azurerm_resource_group.rg.location
??resource_group_name?=?azurerm_resource_group.rg.name
??os_type?????????????=?"Linux"
??sku_name????????????=?"B1"
}
#?Create?the?web?app,?pass?in?the?App?Service?Plan?ID
resource?"azurerm_linux_web_app"?"webapp"?{
??name??????????????????=?"webapp-${random_integer.ri.result}"
??location??????????????=?azurerm_resource_group.rg.location
??resource_group_name???=?azurerm_resource_group.rg.name
??service_plan_id???????=?azurerm_service_plan.appserviceplan.id
??https_only????????????=?true
??site_config?{?
????minimum_tls_version?=?"1.2"
??}
}
#??Deploy?code?from?a?public?GitHub?repo
resource?"azurerm_app_service_source_control"?"sourcecontrol"?{
??app_id?????????????=?azurerm_linux_web_app.webapp.id
??repo_url???????????=?"https://[email protected]/XXX/Demo/_git/Demo"
??branch?????????????=?"main"
??use_manual_integration?=?true
??use_mercurial??????=?false
}r
Step 2: Setting Up Pipelines ??
Once our code was safely stored in Azure Repos, we proceeded to set up our CI/CD pipelines. Azure DevOps makes this process intuitive and streamlined. We started by defining our pipeline as code, allowing us to version control and automate the pipeline itself. This way, the pipeline setup becomes repeatable, maintainable, and easier to collaborate on.
Step 3: Creating the Release Pipeline ????
In the previous steps, we covered setting up the Continuous Integration (CI) pipeline for our Terraform code. Now, let's take a look at how we create the Release Pipeline in Azure DevOps to deploy our Azure Web App.
领英推荐
Terraform - Init
Terraform - Plan
Terraform - Apply
Benefits of Azure DevOps for CI/CD and Release Pipelines:
? End-to-End Automation: Azure DevOps provides a comprehensive suite of tools for CI/CD, making it easier to automate the entire development and deployment lifecycle. From code commits to production deployment, the process can be streamlined and consistent.
? Collaboration: Azure DevOps fosters collaboration among team members, breaking down silos and promoting communication. With everything in one place, developers, testers, and operations teams can work together seamlessly.
? Flexibility: Whether you're using Azure or other cloud platforms, Azure DevOps is flexible and supports a wide range of technologies and tools. This flexibility allows teams to choose the best tools that suit their workflows.
? Scalability: Azure DevOps is designed to support projects of all sizes. It can easily scale as your team and project grow, ensuring that your CI/CD pipelines can handle increased workloads.
? Security: Security is a top priority for Azure DevOps. It offers robust security features to protect your code, artifacts, and pipelines. Access controls and permissions can be managed efficiently.
? Insights and Analytics: Azure DevOps provides valuable insights and analytics, helping teams identify areas for improvement in the development and deployment process. Data-driven decisions can lead to continuous optimization.
? Extensibility: Azure DevOps can be extended with a vast marketplace of extensions, integrating with third-party tools to enhance your workflows.
Principal Consultant and Trainer at PT. NOZYRA
1 年Nice artichle, thanks for the sharing Ong Hong Teck