az.getSecret() with externalInput parameters builds invalid resourceId function

Open Beginner friendly
#20,654 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
68/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
azure
Domain
cloud

Research direction

Start by searching the Bicep codebase for getSecret() parameter compilation and the code that builds the Key Vault resourceId expression. Reproduce with the supplied .bicepparam example and inspect the generated reference.keyVault.id. The fix is done when the resource type is emitted as the single 'Microsoft.KeyVault/vaults' argument and the compiled parameters deploy without the reported resourceId error.

Written by the indexing model from the issue text.

Description

AI Triaged bug Needs: Triage :mag: story: bicep parameters

Bicep version
Bicep CLI version 0.49.2 (b34271ac51)

Describe the bug
When compiling a bicepparam file with a parameterized Key Vault secret value, e.g., az.getSecret(externalInput('sid'), externalInput('rg'), externalInput('kv'), externalInput('sn')), the resulting parameter's Key Vault ID is [resourceId(externalInputs('sid'), externalInputs('rg'), 'Microsoft.KeyVault', 'vaults', externalInputs('kv'))].

The separate 'Microsoft.KeyVault' and 'vaults' arguments should be the single string 'Microsoft.KeyVault/vaults'.

Trying to deploy with the compiled JSON fails with this error message:

Error: Code=InvalidTemplate; Message=Deployment template language expression evaluation failed: 'Unable to evaluate template language function 'resourceId': function requires exactly one multi-segmented argument which must be resource type including resource provider namespace.

To Reproduce

// test.bicep
@secure()
param secretValue string
// test.bicepparam
using 'test.bicep'

param secretValue = getSecret(externalInput('subscriptionId'), externalInput('resourceGroupName'), externalInput('keyVaultName'), externalInput('secretName'))
az bicep build-params --file test.bicepparam

Produces:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "secretValue": {
      "reference": {
        "keyVault": {
          "id": "[resourceId(externalInputs('subscriptionId_0'), externalInputs('resourceGroupName_1'), 'Microsoft.KeyVault', 'vaults', externalInputs('keyVaultName_2'))]"
        },
        "secretName": "[externalInputs('secretName_3')]"
      }
    }
  },
  "externalInputDefinitions": {
    "keyVaultName_2": {
      "kind": "keyVaultName"
    },
    "resourceGroupName_1": {
      "kind": "resourceGroupName"
    },
    "secretName_3": {
      "kind": "secretName"
    },
    "subscriptionId_0": {
      "kind": "subscriptionId"
    }
  }
}

Additional context

Dominant language
Bicep
Stars
3.7k
Forks
833
Avg merge
1d 17h
Merged PRs (30d)
81

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Azure/bicep

All issues in Azure/bicep

Similar issues

More Cloud issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.