Using new AzureRM provider functions in Terraform

Using new AzureRM provider functions in Terraform

There are two new pretty neat provider-defined functions with the new major release version of the Terraform AzureRM provider which I kind of missed initially but seem pretty cool to use.

normalise_resource_id which tries to "normalise" the case-senitive segments of a resource ID in Azure.

parse_resource_id which takes a resource ID and splits it into its different component parts.

Demo

I created some quick code just to try the features and wrote the following:

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "4.4.0"
    }
  }
}

provider "azurerm" {
  features {}
}

locals {
  parsed_nsg = provider::azurerm::parse_resource_id("/subscriptions/(sub-ID)/resourceGroups/rg-prod-we-core/providers/Microsoft.Network/networkSecurityGroups/nsg-prod-we-core-dmz")
}

output "parsed_nsg" {
  value = local.parsed_nsg
}

output "parsed_nsg_resource_type" {
  value = local.parsed_nsg["resource_type"]
}

And the output in my terminal is the following:

parent_resources is empty in this case as the NSG is not assigned any parent resources. A subnet would point to its virtual network.

My initial feeling is that these two functions should be very useful to have since dealing with resource IDs in Azure is not always the most fun as they can be pretty lengthy.

What are some use cases you will find with these two new functions?

References

What’s New in the AzureRM Provider Version 4?
The world of technology is constantly shifting and evolving. Stay up to date on the latest concepts and conversations with these posts from Ned in the Cloud.
Terraform Registry

About me

About me
If you have landed on my page you will have already understood my passion for tech, but obviously there is more to life than that. Here I will try and outline a few of my other hobbies. Strength training I am a person who loves to move around and challenge