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

extensionResourceId from Bicep flagged in ARM-TTK #765

Open
chgeuer opened this issue Feb 26, 2024 · 0 comments
Open

extensionResourceId from Bicep flagged in ARM-TTK #765

chgeuer opened this issue Feb 26, 2024 · 0 comments

Comments

@chgeuer
Copy link
Member

chgeuer commented Feb 26, 2024

Bicep generates code which gets rejected by ARM-TTK; unclear how to work around that.

In a Bicep template, I'm using the getSecret function to fetch a secret from an existing KeyVault, to get KeyVault access, and pass it as parameter to a nested template:

resource publisherKeyVaultWithBootstrapSecret 'Microsoft.KeyVault/vaults@2023-07-01' existing = {
  name: meteringConfiguration.publisherVault.vaultName
  scope: resourceGroup(meteringConfiguration.publisherVault.publisherSubscription, meteringConfiguration.publisherVault.vaultResourceGroupName)
}

module setupMeteredBillingConfigurationModule './nestedtemplates/meteredBillingDependencies.bicep' = {
  name: '...'
  params: {
    bootstrapSecretValue: publisherKeyVaultWithBootstrapSecret.getSecret(meteringConfiguration.publisherVault.bootstrapSecretName)
  }
}

When Bicep compiles this, it results in the following ARM template, which uses the extensionResourceId function to reference the KeyVault:

"parameters": {
 "bootstrapSecretValue": {
    "reference": {
        "keyVault": {
           "id": "[extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', variables('meteringConfiguration').publisherVault.publisherSubscription, variables('meteringConfiguration').publisherVault.vaultResourceGroupName), 'Microsoft.KeyVault/vaults', variables('meteringConfiguration').publisherVault.vaultName)]"
        },
        "secretName": "[variables('meteringConfiguration').publisherVault.bootstrapSecretName]"
    }
 }

Unfortunately, this Bicep-generated code is flagged by ARM-TTK validation tool as not OK, because it calls concat() or format() within extensionResourceId(). This regex in ARM TTK flags it as an error:

https://github.com/Azure/arm-ttk/blob/master/arm-ttk/testcases/deploymentTemplate/ResourceIds-should-not-contain.test.ps1#L31

As a workaround, I can replace

extensionResourceId(
    format('/subscriptions/{0}/resourceGroups/{1}', 
        variables('meteringConfiguration').publisherVault.publisherSubscription, 
        variables('meteringConfiguration').publisherVault.vaultResourceGroupName
    ), 
    'Microsoft.KeyVault/vaults', 
    variables('meteringConfiguration').publisherVault.vaultName
)

with


resourceId(
    variables('meteringConfiguration').publisherVault.publisherSubscription, 
    variables('meteringConfiguration').publisherVault.vaultResourceGroupName, 
    'Microsoft.KeyVault/vaults', 
    variables('meteringConfiguration').publisherVault.vaultName
)

So in JSON:

{
    "old": "[extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', parameters('meteringConfiguration').publisherVault.publisherSubscription, parameters('meteringConfiguration').publisherVault.vaultResourceGroupName), 'Microsoft.KeyVault/vaults', parameters('meteringConfiguration').publisherVault.vaultName)]"

    "new": "[resourceId(variables('meteringConfiguration').publisherVault.publisherSubscription, variables('meteringConfiguration').publisherVault.vaultResourceGroupName, 'Microsoft.KeyVault/vaults', variables('meteringConfiguration').publisherVault.vaultName)]"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant