1

Is there a way to extract azure resource template formats programmatically (REST API, Powershell, Azure CLI)?

The end result should be something along the lines of the JSON presented here, that includes datatypes etc.: https://learn.microsoft.com/en-us/azure/templates/Microsoft.KeyVault/vaults?tabs=json

Preferably being able to select API-version too: https://learn.microsoft.com/en-us/azure/templates/Microsoft.KeyVault/2015-06-01/vaults?tabs=json

I have tried using az provider and expand properties, but properties are always null.

az provider show -n Microsoft.KeyVault --expand resourceTypes/properties

az resource seems only to work on existing resources.

TechnoCowboy
  • 344
  • 2
  • 15
  • if you use az rest, it should work. https://learn.microsoft.com/en-us/cli/azure/reference-index?view=azure-cli-latest#az_rest – Thomas Jun 10 '21 at 09:10
  • Thanks @Thomas Can you tell me which endpoint to hit if I want to get the template for e.g. the Microsoft.KeyVault/vaults? I can't find any information about this. I can find the REST endpoints for key vaults, but that does not provide the template definition. – TechnoCowboy Jun 10 '21 at 09:44

1 Answers1

1

If you just want to extract Azure ARM template format, try the PowerShell below:

$webRequest = Invoke-WebRequest "https://learn.microsoft.com/en-us/azure/templates/Microsoft.KeyVault/2019-09-01/vaults"
 
$webRequest.ParsedHTML.getElementsByClassName("lang-json") | % innerHTML

It works under 5.0: enter image description here

Stanley Gong
  • 11,522
  • 1
  • 8
  • 16
  • Thanks, Stanley. I am not too happy about scraping for a long-term solution. I would prefer a more reliable method, But this will do for a start. – TechnoCowboy Jun 10 '21 at 10:50
  • @TechnoCowboy, I see, pls share your final solution in the end and if my post is helpful in the end, pls accept it :) – Stanley Gong Jun 10 '21 at 12:20
  • @TechnoCowboy, How's going? Do you have any other solutions? As far as I know , this is the only way to do this. If you find other ways, pls share it thx ! – Stanley Gong Jun 16 '21 at 13:29
  • No, unfortunately not. But I will use your solution for now, and continue my search :-) – TechnoCowboy Jun 16 '21 at 14:46