Azure / template-specs

MIT License
31 stars 4 forks source link

Get-AzTemplateSpec should include the ability to expose the 'template' property #39

Closed stweb1963 closed 3 years ago

stweb1963 commented 3 years ago

Currently the only way to retrieve the template version is to use Export-AzTemplateSpec which requires saving the template to a file location

It would be an advantage to have the template output exposed using Get-AzTemplateSpec ... -Version [version]

Our DevOps pipeline does preprocessing on the template to inject a standard set of parameters that are within each of our templates

This would currently require exporting first, importing with ConvertFrom-Json, then perform the preprocessing

stuartko commented 3 years ago

The version object and the artifact object both have a Template property exposed, but for versions it is not currently displayed in the output by the default formatter (we have plans to change this). To get the template for a specific version, you can call Get-AzTemplateSpec ... -Version [version], and then access .Versions[0].Template on the returned object.

For example:

PS C:\Windows\system32> $ts = Get-AzTemplateSpec -ResourceGroupName stuartko_rg1 -Name artifactDemoSpec -Version v1
PS C:\Windows\system32> $ts.Versions[0].Template
{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {},
  "functions": [],
  "variables": {},
  "resources": [
    {
      "name": "setupNetwork",
      "type": "Microsoft.Resources/deployments",
      "apiVersion": "2020-06-01",
      "properties": {
        "mode": "Incremental",
        "templateLink": {
          "relativePath": "./artifacts/network.json"
        }
      }
    },
    {
      "name": "setupStorage",
      "type": "Microsoft.Resources/deployments",
      "apiVersion": "2020-06-01",
      "properties": {
        "mode": "Incremental",
        "templateLink": {
          "relativePath": "./artifacts/storage.json"
        }
      }
    }
  ],
  "outputs": {
    "fromNetwork": {
      "type": "string",
      "value": "[reference('setupNetwork').outputs.vnetName.value]"
    },
    "fromStorage": {
      "type": "string",
      "value": "[reference('setupStorage').outputs.storageInfo.value]"
    }
  }
}
stuartko commented 3 years ago

@stweb1963 : Is the example/behavior above sufficient for your pipeline?

stweb1963 commented 3 years ago

I have tested and this will be sufficient Thanks