Azure / bicep

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

Error: BCP036 The property "properties" expected a value of type "object" but the provided value is of type "string" #2572

Closed Divyenth-K closed 3 years ago

Divyenth-K commented 3 years ago

Bicep version Bicep version o.3.255

Desctiption:

i have a arm template that has has a piece of code that looks like


"variables": {
        "storageApiVersion": "2019-06-01",
        "LinuxApp": "[if(equals(parameters('runTimeStack'),'DOCKER'), 'app,linux,container', 'app,linux')]",
        "WindowsApp": "app",
        "LinuxPython": {
            "linuxFxVersion": "[concat('PYTHON|', parameters('runTimeStackVersion'))]"
        },
        "LinuxRuby": {
            "linuxFxVersion": "[concat('RUBY|', parameters('runTimeStackVersion'))]"
        },
        "LinuxNODE": {
            "linuxFxVersion": "[concat('NODE|', parameters('runTimeStackVersion'))]"
        },
        "LinuxJAVATomcat": {
             "linuxFxVersion": "[concat('TOMCAT|', parameters('runTimeTomcatVersion'),'-java', parameters('runTimeStackVersion'))]"
        },
        "LinuxJAVASE": {
            "linuxFxVersion": "[concat('JAVA|',parameters('runTimeStackVersion'),'-java', parameters('runTimeStackVersion'))]"
        },
        "LinuxDOTNETCORE": {
            "linuxFxVersion": "[concat('DOTNETCORE|', parameters('runTimeStackVersion'))]"
        },
}

these variables are used to set the property to a resource

{
    "type": "Microsoft.Web/sites/config",
    "apiVersion": "2018-11-01",
    "name": "[concat(parameters('webappName'), '/web')]",
    "location": "[parameters('Location')]",
    "dependsOn": [
        "[resourceId('Microsoft.Web/sites', parameters('webappName'))]"
        ],
    "properties": "[if(equals(parameters('OS'),'Linux'),variables(concat('Linux', parameters('runTimeStack'))),variables(concat('Windows', parameters('runTimeStack'))))]"
}

runTimeStack is a parameter in which can have values like python, ruby, etc. Based on the runtime stack the property is set using hte respective variable declared above.

Example:

If the runTimeStack is python and OS is linux then LinuxPython variable will property

"property" : LinuxPython This worked fine in my ARM templates.

I 'am trying to convert this arm template to bicep but this scenario does not seem to work in bicep

this is my code in bicep


resource webappName_web 'Microsoft.Web/sites/config@2018-11-01' = {
  name: '${webappName_resource.name}/web'
  properties: ((OS == 'Linux') ? 'Linux${runTimeStack}' : 'Windows${runTimeStack}')
}

here iam getting an error saying

"The property "properties" expected a value of type "object" but the provided value is of type "string"."

could u please help me convert this to bicep. Thanks!!

matsest commented 3 years ago

Sorry, you can't have dynamic variable names like this in Bicep. For type safety, this is a good thing - if you change your variables a bit you can do something similar with:

@description('description')
param runTimeStack string = 'python'

@description('description')
param runTimeStackVersion string = '3.6'

@description('description')
param runTimeTomcatVersion string = 'jre8'

@description('description')
param webappName string

@description('description')
param OS string = 'Linux'

//empty if not java or tomcat
var suffix = (runTimeStack == 'java') || (runTimeStack == 'tomcat') ? '-java${runTimeTomcatVersion}' : ''

resource webApp 'Microsoft.Web/sites@2020-12-01' existing = {
  name: webappName
}

resource webAppConfig 'Microsoft.Web/sites/config@2018-11-01' = {
  name: 'web'
  parent: webApp
  properties: {
    linuxFxVersion: (OS == 'Linux') ? '${toUpper(runTimeStack)}|${runTimeStackVersion}${suffix}': any(null)
  }
}
alex-frankel commented 3 years ago

Thanks @matsest. @Divyenth-K - let us know if this fix works for you.

Divyenth-K commented 3 years ago

Thanks this solution did work for me..