Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Referencing Template Specs is broken in versions 0.6.1 and 0.6.11 #6823

Closed
pb111111 opened this issue May 11, 2022 · 5 comments · Fixed by #6833
Closed

Referencing Template Specs is broken in versions 0.6.1 and 0.6.11 #6823

pb111111 opened this issue May 11, 2022 · 5 comments · Fixed by #6833

Comments

@pb111111
Copy link

pb111111 commented May 11, 2022

Bicep version
Bicep CLI version 0.6.11 (cecfb5c)

Describe the bug
With the latest version of the bicep CLI, I am unable to reference Template Spec modules. If I inspect the cached copy of the module in main.json, the mainTemplate object appears empty:

Version 0.6.11 and Version 0.6.1

❯ cat [cache-path]\[rg-name]\[tsname]\1.0.3\main.json
{
  "id": "/subscriptions/[subscription]/resourceGroups/[rg]/providers/Microsoft.Resources/templateSpecs/[tsname]/versions/1.0.3",
  "name": "1.0.3",
  "type": "Microsoft.Resources/templateSpecs/versions",
  "location": "eastus2",
  "tags": {},
  "systemData": {},
  "properties": {
    "linkedTemplates": [],
    "mainTemplate": {}
  }
}

Version 0.5.6

{
  "id": "/subscriptions/[subscription]/resourceGroups/[rg]/providers/Microsoft.Resources/templateSpecs/[tsname]/versions/1.0.3",
  "name": "1.0.3",
  "type": "Microsoft.Resources/templateSpecs/versions",
  "location": "eastus2",
  "tags": {},
  "systemData": {},
  "properties": {
    "linkedTemplates": [],
    "mainTemplate": {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "metadata": {
        "_generator": {
          "name": "bicep",
          "version": "0.6.11.53198",
          "templateHash": "13169941131891395286"
        }
      },
      "parameters": {
        "roleNames": {
          "type": "array",
          "allowedValues": [
            // omitted
          ]
        },
        "principalId": {
          "type": "string"
        },
        "principalType": {
          "type": "string",
          "allowedValues": [
            "User",
            "Group",
            "ServicePrincipal"
          ]
        }
      },
      "variables": {
        "builtInRoles": {
         // omitted
        }
      },
      "resources": [
        {
          "copy": {
            "name": "roleAssignments",
            "count": "[length(parameters('roleNames'))]"
          },
          "type": "Microsoft.Authorization/roleAssignments",
          "apiVersion": "2020-04-01-preview",
          "name": "[guid(resourceGroup().id, parameters('roleNames')[copyIndex()], parameters('principalId'))]",
          "properties": {
            "roleDefinitionId": "[subscriptionResourceId('Microsoft.Authorization/roleDefinitions', variables('builtInRoles')[parameters('roleNames')[copyIndex()]])]",
            "principalId": "[parameters('principalId')]",
            "principalType": "[parameters('principalType')]"
          }
        }
      ]
    }
  }
}

In version 0.5.6, the error message does not appear.
In version 0.6.11 and 0.6.1, the error message appears as:

❯ bicep build .\db.bicep
C:\path\file.bicep(78,60) : Error BCP104: The referenced module has errors.
C:\path\file.bicep(82,5) : Error BCP037: The property "roleNames" is not allowed on objects of type "params". No other properties are allowed.
C:\path\file.bicep(85,5) : Error BCP037: The property "principalId" is not allowed on objects of type "params". No other properties are allowed.
C:\path\file.bicep(86,5) : Error BCP037: The property "principalType" is not allowed on objects of type "params". No other properties are allowed.

To Reproduce

  • Reference a template spec in your bicep file with the latest version of the CLI.
module symbolicName 'ts/MySpecs:Name:1.0.3' = {
  scope: resourceGroup()
  name: 'deployment123'
  params: {
    roleNames: [
      'Contributor'
    ]
    principalId: userAssignedIdentity.properties.principalId
    principalType: 'ServicePrincipal'
  }
}

Additional context
Add any other context about the problem here.

@ghost ghost added the Needs: Triage 🔍 label May 11, 2022
@MichielCornilleKenze
Copy link

Can confirm. I can reproduce this with 0.6.11

@shenglol
Copy link
Contributor

Might be due to bumping Azure.ResourceManager.Resources to 1.0 (#6538) but needs further investigation to confirm.

@shenglol
Copy link
Contributor

Confirmed that it's due to a breaking change in the Azure.ResourceManager.Resources package. I'm working on a fix now.

@shenglol shenglol self-assigned this May 11, 2022
@shenglol shenglol added this to Bicep May 11, 2022
@shenglol shenglol moved this to Todo in Bicep May 11, 2022
@shenglol shenglol moved this from Todo to In Progress in Bicep May 11, 2022
@shenglol shenglol added this to the v0.7 milestone May 11, 2022
Repository owner moved this from In Progress to Done in Bicep May 12, 2022
@pb111111
Copy link
Author

pb111111 commented May 12, 2022

@shenglol I just verified this build, 0.6.18 (36324f8), fixes my issue.

@bhsubra
Copy link
Contributor

bhsubra commented May 13, 2022

This issue should be fixed with today's 0.6.18 release. Let us know if there are any concerns. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators May 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants