Sample code to create pipeline to execute Terraform on Azure DevOps
In this sample code we will create a Pipeline utilizing Azure Pipelines. We will automatize the creation of Infrastructure on Azure Portal. It is recommended that the Developer has at least basic knowledge of Azure DevOps, Terraform and Docker. The demonstration video will show how the sample works. Additionally, we have Support plans in case you want personalized support.
We will encompass the next topics:
- How to create Service Connection linked to Docker Hub
- How to create a transversal pipeline for multiples repositories
- How to configure Approval in a specific Stage inside the pipeline
- How to approve the next Stages in running time from a Pipeline
- How to create a Resource Group using a Pipeline
- How to create a KeyVault using a Pipeline
- How to create an Azure DevOps Project using a Pipeline
- How to destroy a previously created resource using Pipelines
Recommended knowledge:
- Experience in a programming language
- Experiences or knowledge of Azure Portal and Azure DevOps
- Experience or solid knowledge in GIT
- Some knowledge of the GitFlow methodology
- Experience with Docker commands, for example pull, push and tag
Prerequisites:
- Terminal Bash, I will use WSL on Windows 10
- Azure CLI >= 2.56
- Terraform >=1.64
- At least one active primary account in the Azure Portal
- An organization active in Azure DevOps linked to the same Directory as the main Azure account.
- An account in Docker Hub
Checking Prerequisites:
Verifying the AZ CLI version
az -v
azure-cli 2.56.0
core 2.56.0
telemetry 1.1.0
Dependencies:
msal 1.24.0b2
azure-mgmt-resource 23.1.0b2
Verifying the Terraform version
terraform -v
Terraform v1.6.4
on linux_amd64
Check access to image located in my repository
docker pull registry.hub.docker.com/jbaldeon/slave-terraform:6
Initial Settings:
Linking our PC to the Azure portal through our Microsoft account
az login
Configuring to interact with Azure DevOps
export AZDO_PERSONAL_ACCESS_TOKEN=MY_CREATED_TOKEN_ON_AZURE_DEVOPS
export AZDO_ORG_SERVICE_URL=https://dev.azure.com/MY_AZURE_DEVOPS_ORGANIZATION
Useful commands:
Find out the Object ID
Get-AzADUser -UserPrincipalName SET_YOUR_USER
Get-AzADUser -mail SET_YOUR_EMAIL
Commands to run this sample:
Validating that our code and configurations are correct
terraform init -reconfigure -backend-config="variables/backend_shared.conf" && terraform validate && terraform plan -var-file="variables/variable_shared.tfvars"
Create the resources
terraform apply -var-file="variables/variable_shared.tfvars" -auto-approve
Commands to destroy this sample:
Validating that our code and configurations are correct
terraform init -reconfigure -backend-config="variables/backend_shared.conf" && terraform validate && terraform plan -var-file="variables/variable_shared.tfvars" -destroy
Destroying the resources
terraform apply -var-file="variables/variable_shared.tfvars" -auto-approve -destroy
Price: USD $3
Jimmy Baldeón
19 december, 2023
Secure your copy now. After payment, receive an email with the download link. Let's innovate together!
Unlock the full potential of Terraform and Azure Pipeline effortlessly with my affordable, meticulously crafted sample codes. Elevate your projects without the hassle. If you encounter challenges tailoring the code to your needs, fear not - I offer comprehensive support plans tailored to assist you at every step. Choose the level of support that fits you best and let's build together with confidence.