bicep icon indicating copy to clipboard operation
bicep copied to clipboard

`existing` and `this.existingResource()` can't read write-only properties

Open torreymicrosoft opened this issue 3 weeks ago • 0 comments

existing and this.existingResource() read a resource with a GET, so values a resource provider only returns through a list action come back empty. For example, on Bicep 0.49.2 with API version 2024-04-01, a GET on Microsoft.Web/sites/config appsettings returns properties: {}, the settings only come back from a POST to .../config/appsettings/list, and union(newSettings, this.existingResource().?properties) removes the existing settings. This is a known issue today, and this issue tracks letting this.existingResource() and existing read through the type's list function, or at least warning before deployment when they can't return the value. Until then, read the values with the list function and write the merged result from a module (reading needs the list permission, which for app settings is Microsoft.Web/sites/config/list/Action):

// main.bicep
param siteName string

resource site 'Microsoft.Web/sites@2024-04-01' existing = {
  name: siteName
}

resource currentSettings 'Microsoft.Web/sites/config@2024-04-01' existing = {
  parent: site
  name: 'appsettings'
}

var additionalAppSettings = {
  APP_SPECIFIC_SETTING_1: 'SomeValue'
  APP_SPECIFIC_SETTING_2: 'AnotherValue'
}

module mergeAppSettings 'merge-app-settings.bicep' = {
  name: 'merge-app-settings'
  params: {
    siteName: siteName
    currentAppSettings: currentSettings.list().properties
    newAppSettings: additionalAppSettings
  }
}
// merge-app-settings.bicep
param siteName string

@secure()
param currentAppSettings object

@secure()
param newAppSettings object

resource site 'Microsoft.Web/sites@2024-04-01' existing = {
  name: siteName
}

resource siteAppSettings 'Microsoft.Web/sites/config@2024-04-01' = {
  parent: site
  name: 'appsettings'
  properties: union(currentAppSettings, newAppSettings)
}

Related: #18572, Azure/bicep-types-az#2639 (the App Service side), Azure/bicep-types-az#2145 (existing on a type with no GET at all).

torreymicrosoft avatar Nov 09 '26 21:11 torreymicrosoft