Azure / bicep

Bicep is a declarative language for describing and deploying Azure resources
MIT License
3.21k stars 745 forks source link

Deployment doesn't handle default parameter values that are interpolated string expressions #8154

Closed StephenWeatherford closed 1 year ago

StephenWeatherford commented 2 years ago
param dataFactoryName string = 'datafactory${uniqueString(resourceGroup().id)}'
param location string = resourceGroup().location
param storageAccountName string = 'storage${uniqueString(resourceGroup().id)}'
param blobContainerName string = 'blob${uniqueString(resourceGroup().id)}'
param managedIdentityName string = 'blob${uniqueString(resourceGroup().id)}'
param _artifactsLocation string = deployment().properties.templateLink.uri
@secure()
param _artifactsLocationSasToken string = ''

output dataFactoryName string = dataFactoryName
output location string = location
output storageAccountName string = storageAccountName
output blobContainerName string = blobContainerName
output managedIdentityName string = managedIdentityName
output _artifactsLocation string = _artifactsLocation
#disable-next-line outputs-should-not-contain-secrets
output _artifactsLocationSasToken string = _artifactsLocationSasToken

1) deploy !) you get asked questions like this: image EXPECTED: Should be asking whether to use the default value as an expression or to enter a specific value (like other expressions) 2) allow it to create a params file !)

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "_artifactsLocation": {
      "value": "none"
    },
    "dataFactoryName": {
      "value": "[format('datafactory{0}', uniqueString(resourceGroup().id))]"
    },
    "storageAccountName": {
      "value": "[format('storage{0}', uniqueString(resourceGroup().id))]"
    },
    "blobContainerName": {
      "value": "[format('blob{0}', uniqueString(resourceGroup().id))]"
    },
    "managedIdentityName": {
      "value": "[format('blob{0}', uniqueString(resourceGroup().id))]"
    }
  }
}

EXPECTED: Either a new value entered by user or nothing for default

dciborow commented 1 year ago

to hack around this, I have started wrapping my strings with string().

param dataFactoryName string = string('datafactory${uniqueString(resourceGroup().id)}')
param location string = resourceGroup().location
param storageAccountName string = string('storage${uniqueString(resourceGroup().id)}')
param blobContainerName string = string('blob${uniqueString(resourceGroup().id)}')
param managedIdentityName string = string('blob${uniqueString(resourceGroup().id)}')
param _artifactsLocation string = deployment().properties.templateLink.uri
@secure()
param _artifactsLocationSasToken string = ''
bahrep commented 1 year ago

Same here. VSCode 1.74.3 (Universal) on MacOS, Bicep extension v0.13.1.

The string() workaround works, but I don't want to modify the template's code just to workaround a bug in IDE. I'll use PowerShell until it's fixed.

PS First asked a question on StackOverflow and found this ticket later.