Quick test on Terraform with Azure DevOps

Trying to terraform with Azure DevOps, and using these instructions available in internet:
https://www.carbonlogiq.io/post/azure-devops-pipeline-terraform-deployment-tutorial

The original pipeline and terraform files are available at
https://github.com/andrew-kelleher/terraformadopipeline

The files I used are summarized below:

Pipeline files consist of 2 files:

deploy/tfdemo-env01-terraform.yml
- name: Terraform - deploy Service Bus to env01
- stages: template: templates/terraform-template.yml

deploy/templates/terraform-template.yml
- stages: 
  - stage: 'Terraform_Plan'
  - stage: 'Terraform_Apply'

Terraform files are:

terraform/main.tf
- resource "azurerm_resource_group"

terraform/providers.tf
- required_providers azurerm
- backend "azurerm"

terraform/servicebus.tf
- resource "azurerm_servicebus_namespace"
- resource "azurerm_servicebus_queue" "queue01"
- resource "azurerm_servicebus_queue" "queue02"

terraform/variables.tf
- Variable definitions

terraform/tfdemo.env01.tfvars
- Variables values

The main relationships between the files are shown in the picture below.

Pipeline defines the stages Plan and Apply, and refers to all Terraform files located in the Terraform folder.
The actual Terraform commands are executed in the pool agent.

In order to get things working, one has to create self-hosted agent.
The overall working setup is depicted in the picture below:

Fixing naming conflicts in files:

- providers.tf 
- tfdemo.env01.tfvars

Had to define local pool in tfdemo.env01.tfvars:

- pool:
    name: Local
    demands: Agent.Name -equals MUNACER

and in terraform-template.yml:

- pool: Local

For creating self-hosted agents for the local pool, one can download the software via Azure DevOps:
https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/windows-agent?view=azure-devops

How to delete virtual resources

Something not mentioned in the original instructions, is how to delete the resources you have just created.

One way to delete the resources is to use a duplicate of the pipeline and adding
“-destroy” parameter to all Terraform plan and apply commands

Here is an example below:

tfdemo-destroy-part1.yml
- pointing the template to the next yml file:
  template: tfdemo-destroy-part2.yml
tfdemo-destroy-part2.yml
- adding "-destroy" to Plan and Apply stages:
  terraform plan -destroy ...
  terraform apply -destroy ...