This solution will deploy a secure VM with Terraform
Steps :
Here’s a simplified SetUp steps to follow :
- Login to Azure: Sign in to your Azure Subscription.
- Create a Service Principal:
- Open the Azure Cloud Shell and run the following command to create a service principal and save the output.
az ad sp create-for-rbac --name "bankwork1" --role="Contributor"
--scopes="/subscriptions/<subscriptionID>"
- Add Client Secret in Azure DevOps:
- Go to Azure DevOps → Pipelines → Library and add the
client_secretfrom the output of the previous step.
- Create your own SSH Key and keep id_rsa.pub for further use .
- Generate an SSH key for secure login to the VM by running:
ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa
- Copy the
id_rsa.pubfile for later use.
- Create Azure DevOps Pipeline:
- Write a pipeline YAML file (
Azure-pipeline.yml) that includes the secret variable (client_secret) to deploy resources.
- Push Files to Azure DevOps:
- Go to Azure DevOps → Create an organization → Repos.
- Push the following files to the repository:
main.tfuser_data.shid_rsa.pubAzure-pipeline.yml- Update
main.tf:
- Edit the
main.tffile and add thesubscription_id,client_id,client_secret, andtenant_idobtained from Step 2.
- Run the Pipeline:
- Trigger the pipeline using
Azure-pipeline.yml. Once it finishes successfully, the output will be the NGINX URL. - Pipeline ask for Authentication before starting .
- Put the URL in the Browser to see the NGINX Welcome Page .
- Check Resources:
- Go to the Azure portal to verify the resources under your resource group, access the SSH key, and manage the VM.