Decompiler generates bad template if parameter used for API version
- Dominant language
- Bicep
- Stars
- 3.6k
- Forks
- 830
- Avg merge
- 1d 21m
- Merged PRs (30d)
- 79
Description
When using bicep cli (version >= 0.12.40) to build the next module:
```
module postgresServer 'core/database/postgresql/flexibleserver.bicep' = {
name: 'postgresql'
scope: resourceGroup
params: {
name: '${prefix}-postgresql'
location: location
tags: tags
sku: {
name: 'Standard_B1ms'
tier: 'Burstable'
}
storage: {
storageSizeGB: 32
}
version: '13'
administratorLogin: postgresUser
administratorLoginPassword: postgresPassword
databaseNames: [postgresDatabaseName]
allowAzureIPsFirewall: true
}
}
```
bicep cli is generating:
```
{
"type": "Microsoft.DBforPostgreSQL/flexibleServers",
"apiVersion": "2022-12-01",
"name": "[parameters('name')]",
"location": "[parameters('location')]",
"tags": "[parameters('tags')]",
"sku": "[parameters('sku')]",
"properties": {
"version": "[parameters('version')]",
"administratorLogin": "[parameters('administratorLogin')]",
"administratorLoginPassword": "[parameters('administratorLoginPassword')]",
"storage": "[parameters('storage')]",
"highAvailability": {
"mode": "Disabled"
}
}
}
```
Note the value for `apiVersion` = "apiVersion": "2022-12-01",
I used the Azure portal to generate the ARM template for the `Microsoft.DBforPostgreSQL/flexibleServers` and got:
```
{
"apiVersion": "[parameters('apiVersion')]",
"location": "[parameters('location')]",
"name": "[parameters('serverName')]",
"identity": "[if(empty(parameters('identityData')), json('null'), parameters('identityData'))]",
"properties": {
"version": "[parameters('version')]",
"administratorLogin": "[parameters('administratorLogin')]",
"administratorLoginPassword": "[parameters('administratorLoginPassword')]",
"Network": "[if(empty(parameters('vnetData').Network), json('null'), parameters('vnetData').Network)]",
"availabilityZone": "[parameters('availabilityZone')]",
"Storage": {
"StorageSizeGB": "[parameters('storageSizeGB')]",
"Autogrow": "[parameters('storageAutogrow')]"
},
"Backup": {
"backupRetentionDays": "[parameters('backupRetentionDays')]",
"geoRedundantBackup": "[parameters('geoRedundantBackup')]"
},
"highAvailability": {
"mode": "[parameters('haEnabled')]",
"standbyAvailabilityZone": "[parameters('standbyAvailabilityZone')]"
},
"dataencryption": "[if(empty(parameters('dataEncryptionData')), json('null'), parameters('dataEncryptionData'))]",
"authConfig": "[if(empty(parameters('authConfig')), json('null'), parameters('authConfig'))]"
},
"sku": {
"name": "[parameters('vmName')]",
"tier": "[parameters('serverEdition')]"
},
"tags": "[parameters('tags')]",
"type": "Microsoft.DBforPostgreSQL/flexibleServers"
}
```
Note `"apiVersion": "[parameters('apiVersion')]",` The version is in `[ ]`
When trying to deploy the output of `bicep build bicepfile` we get:
```
ERROR: deployment failed: error deploying infrastructure: failed deploying: deploying to subscription:
Deployment Error Details:
ParameterOutOfRange: The value of the 'Version' should be in: []. Verify that the specified parameter value is correct.
```
The Version is expected to be within `[ ]`
See related: https://github.com/pamelafox/flask-surveys-container-app/issues/19
Contributor guide
Research direction
Reproduce the issue with the Bicep CLI at version 0.12.40 or later by running `bicep build bicepfile` on the shown PostgreSQL flexible server module. Inspect the generated ARM JSON, focusing on the `apiVersion` value, and verify the corrected output deploys without the reported ParameterOutOfRange error while preserving the API-version parameter expression.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure
- Domain
- cloud, compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100