I'm trying to create a TemplateSpec using Bicep and the New-AzTemplateSpec command in Az-PS. However, I'm encountering an error and need some help to resolve it:
{
"error": {
"code": "InvalidSchema",
"message": "The template is invalid. Error: 'The template resource 'subscriptionDeployment' at line '168' and column '18' is invalid. The api-version '2018-11-01' used to deploy the template does not support 'Scope' property. Please use api-version '2019-05-01' or later to deploy the template. Please see https://aka.ms/arm-syntax-resources for usage details.'"
}
}
Here is the corresponding snippet from the ARM Template gets compiled after execution:
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2022-09-01",
"name": "subscriptionDeployment",
"scope": "/",
"location": "[deployment().location]",
Created from this Bicep snippet:
resource subscriptionRes 'Microsoft.Subscription/aliases@2021-10-01' = {
name: subscriptionName
scope: tenant()
properties: {
displayName: subscriptionName
billingScope: '/billingAccounts/${billingAccountName}/billingProfiles/${billingProfileName}/invoiceSections/${invoiceSectionName}'
additionalProperties: {
managementGroupId: managementGroupId
}
}
}
This is what my PS command looks like:
New-AzTemplateSpec -Name name -Version "0.0.1" -ResourceGroupName rgname -Location westeurope -TemplateFile "<path_to_bicep_file>"
I found similar posts, mentioning that the Cmdlets need to be updated and this is the part where I am not exactly sure. My Az.Resources PowerShell module which I thought is responsible for creating the TemplateSpec is on the newest version:
Get-InstalledModule -Name Az.Resources
Version Name Repository Description
------- ---- ---------- -----------
6.9.0 Az.Resources PSGallery Microsoft Azure PowerShell - Azure Resource Manager and Active Directory cmdlets in Windows PowerShell and …
Also, I am using the newest PowerShell 7 version:
$PSVersionTable. PSVersion
Major Minor Patch PreReleaseLabel BuildLabel
----- ----- ----- --------------- ----------
7 3 6
Any advice is much appreciated!
Edit: The output I get from listing the api versions of my installed Microsoft.Resources module are as follows:
(Get-AzResourceProvider -ProviderNamespace Microsoft.Resources).ResourceTypes | Where-Object ResourceTypeName -eq 'templateSpecs'
ResourceTypeName : templateSpecs
Locations : {East Asia, Southeast Asia, Australia East, Australia Central…}
ApiVersions : {2022-02-01, 2021-05-01, 2021-03-01-preview, 2019-06-01-preview}
Edit 2: This is the way I import the deployment into the main bicep file:
// Subscription
module sub 'artifacts/subscription.bicep' = {
scope: tenant()
name: 'subscriptionDeployment'
params: {
managementGroupId: managementGroupId
subscriptionName: subscriptionName
billingAccountName: billingAccountName
billingProfileName: billingProfileName
invoiceSectionName: invoiceSectionName
budgetName: '${subShortName}-budget'
amount: amount
category: category
timeGrain: timeGrain
startDate: startDate
endDate: endDate
}
}