Greetings my fellow Technology Advocates and Specialists.
This is Chapter #4 of my Terraform CDK (Cloud Development Kit) Series.
In this Session, I will walk you through If CDK (Cloud Development Kit) for Terraform is available in Microsoft Hosted Linux Build Agent.
I had the Privilege to talk on this topic in ONE Azure Community:-
NAME OF THE AZURE COMMUNITY
TYPE OF SPEAKER SESSION
.NET Zurich User Group
In-Person
EVENT ANNOUNCEMENTS:-
IN-PERSON SESSION:-
LIVE DEMO was Recorded as part of my Presentation in .NET Zurich User Group Forum/Platform
Start Time of My Demo = 01 Hour 08 Mins 03 Secs
Duration of My Demo = 47 Mins 51 Secs
VIDEO
#
TOPICS
1.
If Terraform is installed in Microsoft Hosted Linux Build Agent. If not, Pipeline will install and then validate.
2.
If Node is installed in Microsoft Hosted Linux Build Agent.
3.
If Yarn is installed in Microsoft Hosted Linux Build Agent.
4.
If CDK for Terraform is installed in Microsoft Hosted Linux Build Agent. If not, Pipeline will install and then validate.
Azure Subscription.
Azure DevOps Organisation and Project.
Service Principal with Required RBAC ( Contributor) applied on Subscription or Resource Group(s).
Azure Resource Manager Service Connection in Azure DevOps.
Terraform CDK Series with Azure
Terraform CDK Series with Azure:-
Greetings to my fellow Technology Advocates and Specialists.
In this Session, I talk and run Demo on TERRAFORM CDK SERIES in below TECH COMMUNITIES :-
NAME OF THE TECH COMMUNITIES:-
Global Azure - 2024
So, here goes the answer:
"No, Terraform and CDK for Terraform DOES NOT come installed by default in Microsoft Hosted Linux Build Agent ."
AZURE DEVOPS YAML PIPELINE (azure-pipelines-with-CDK-For-Terraform-Lin-v1.0.yml):-
trigger:
none
######################
#DECLARE VARIABLES:-
######################
variables:
ServiceConnection: amcloud-cicd-service-connection
BuildAgent_Lin: ubuntu-latest
envName: NonProd
#########################
# Declare Build Agents:-
#########################
pool:
vmImage: $(BuildAgent_Lin)
###################
# Declare Stages:-
###################
stages:
- stage: TEST_CDK_FOR_TERRAFORM_ON_LINUX
jobs:
- job: TEST_CDK_FOR_TERRAFORM_ON_LINUX
displayName: TEST CDK FOR TERRAFORM ON LINUX
steps:
##################################################
# Test CDK for Terraform in Linux Build Agent:-
##################################################
- task: AzureCLI@2
displayName: Test CDK for Terraform on Linux
inputs:
azureSubscription: $(ServiceConnection)
scriptType: pscore
scriptLocation: inlineScript
inlineScript: |
echo "Terraform is NOT INSTALLED!."
echo " Proceed to installation..."
echo "##########################################################"
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install terraform
$tf_validate_install = terraform -v
echo "##########################################################"
echo "The latest terraform version installed is: $tf_validate_install"
echo "##########################################################"
$node_ver = node --version
echo "The latest node version installed is: $node_ver"
echo "##########################################################"
$yarn_ver = yarn --version
echo "The latest yarn version installed is: $yarn_ver"
echo "##########################################################"
echo "CDK for Terraform is NOT INSTALLED!."
echo "Proceed to installation..."
npm install --global cdktf-cli@latest
npm install @cdktf/provider-azurerm
echo "##########################################################"
$cdktf_validate_install = cdktf --version
echo "The latest cdktf version installed is: $cdktf_validate_install"
echo "##########################################################"
Enter fullscreen mode
Exit fullscreen mode
Now, let me explain each part of YAML Pipeline for better understanding.
BELOW FOLLOWS PIPELINE VARIABLES CODE SNIPPET:-
######################
#DECLARE VARIABLES:-
######################
variables:
ServiceConnection: amcloud-cicd-service-connection
BuildAgent_Lin: ubuntu-latest
envName: NonProd
Enter fullscreen mode
Exit fullscreen mode
NOTE:-
1. Please change the values of the variables accordingly.
2. The entire YAML pipeline is build using Variables. No Values are Hardcoded.
This is a Single Stage Pipeline - TEST_CDK_FOR_TERRAFORM_ON_LINUX (with 1 Pipeline Task):-
stages:
- stage: TEST_CDK_FOR_TERRAFORM_ON_LINUX
jobs:
- job: TEST_CDK_FOR_TERRAFORM_ON_LINUX
displayName: TEST CDK FOR TERRAFORM ON LINUX
steps:
Enter fullscreen mode
Exit fullscreen mode
PIPELINE TASK #1:-:-
1. Install and validate Terraform .
2. Validate Node .
3. Validate Yarn .
4. Install and validate CDK for Terraform .
##################################################
# Test CDK for Terraform in Linux Build Agent:-
##################################################
- task: AzureCLI@2
displayName: Test CDK for Terraform on Linux
inputs:
azureSubscription: $(ServiceConnection)
scriptType: pscore
scriptLocation: inlineScript
inlineScript: |
echo "Terraform is NOT INSTALLED!."
echo " Proceed to installation..."
echo "##########################################################"
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install terraform
$tf_validate_install = terraform -v
echo "##########################################################"
echo "The latest terraform version installed is: $tf_validate_install"
echo "##########################################################"
$node_ver = node --version
echo "The latest node version installed is: $node_ver"
echo "##########################################################"
$yarn_ver = yarn --version
echo "The latest yarn version installed is: $yarn_ver"
echo "##########################################################"
echo "CDK for Terraform is NOT INSTALLED!."
echo "Proceed to installation..."
npm install --global cdktf-cli@latest
npm install @cdktf/provider-azurerm
echo "##########################################################"
$cdktf_validate_install = cdktf --version
echo "The latest cdktf version installed is: $cdktf_validate_install"
echo "##########################################################"
Enter fullscreen mode
Exit fullscreen mode
NOW ITS TIME TO TEST!!!
TEST CASES:-
1. Pipeline executed successfully.
2. Terraform Installed and Validated Successfully on MS Hosted Linux Build Agent.
3. Node and Yarn version validated Successfully on MS Hosted Linux Build Agent.
4. CDK for Terraform Installed and Validated Successfully on MS Hosted Linux Build Agent.
Hope You Enjoyed the Session!!!
Stay Safe | Keep Learning | Spread Knowledge
Top comments (0)