Azure / bicep

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

Argument of type "null | string" is not assignable to parameter of type "null | string" #8890

Closed mexyn closed 1 year ago

mexyn commented 1 year ago

Bicep version 0.12.1

Describe the bug After upgrading to 0.12.1 we get the following error on conditional property values using the ternary operator. The code did work for at least 16 months before, but after the upgrade the compilation fails. Even the error message is confusing as the mentioned types match:

Argument of type "null | string" is not assignable to parameter of type "null | string"

We are getting this error for the following resource block:

image

We didn't change that code for over a year.

To Reproduce See screenshot

Additional context We compiled the exact same code with previous bicep versions and it works. So it seems this error is definitely caused by version 0.12.1

tyconsulting commented 1 year ago

yes, I have the exact error too. @alex-frankel @briandmoore I have emailed you my error earlier today. this is impacting customer's deployments when using Azure Pipeline with Microsoft Hosted agents since this version has already made its way to Azure DevOps

samtulpinck commented 1 year ago

Same issue here

bdanse commented 1 year ago

Same issue with object

Argument of type "null | object" is not assignable to parameter of type "Identity | null" (BCP070) image

SeSeicht commented 1 year ago

having the same today. Yesterday there was no issue with that code. Error BCP070: Argument of type "null | object | object" is not assignable to parameter of type "Identity | null".

BenjaminEngeset commented 1 year ago

yes, I have the exact error too. @alex-frankel @briandmoore I have emailed you my error earlier today. this is impacting customer's deployments when using Azure Pipeline with Microsoft Hosted agents since this version has already made its way to Azure DevOps

Not able to uninstall the current binary and replace it with a install of the older binary either, I had no luck. System environment variable can be changed so it references the old binary. This works on Windows.

SeSeicht commented 1 year ago

What else I have noticed, I only got this error in local modules. Using the same module published in an ACR will not produce this error!

BenjaminEngeset commented 1 year ago

What else I have noticed, I only got this error in local modules. Using the same module published in an ACR will not produce this error!

Same here.

alex-frankel commented 1 year ago

Working on it! We will work on getting a new release out ASAP. In the meantime, are folks able to downgrade to an older version using az bicep install --version v0.11.1?

SeSeicht commented 1 year ago

Working on it! We will work on getting a new release out ASAP. In the meantime, are folks able to downgrade to an older version using az bicep install --version v0.11.1?

I haven't updated bicep since a while and also getting this error in vscode and in a pipeline with ubuntu (ms-hosted) agents. Both are not using v12

image

alex-frankel commented 1 year ago

@SeSeicht -- VS Code and the hosted agents are both capable of auto-upgrading. Can you confirm you are not running v0.12 by checking az bicep version in your pipeline and/or checking the extension:

image
SeSeicht commented 1 year ago

@SeSeicht -- VS Code and the hosted agents are both capable of auto-upgrading. Can you confirm you are not running v0.12 by checking az bicep version in your pipeline and/or checking the extension: image

you are right, my vscode extension is updated automatically, even az bicep version is still showing the old version image

SeSeicht commented 1 year ago

@SeSeicht -- VS Code and the hosted agents are both capable of auto-upgrading. Can you confirm you are not running v0.12 by checking az bicep version in your pipeline and/or checking the extension: image

2022-11-04T15:58:56.9203654Z /home/vsts/work/1/s/policies/assignments/policyAssignmentsModule/resourceGroup/deploy.bicep(74,20) : Error BCP070: Argument of type "null | object | object" is not assignable to parameter of type "Identity | null".
2022-11-04T15:58:56.9204601Z /home/vsts/work/1/s/policies/assignments/policyAssignmentsModule/resourceGroup/deploy.bicep(74,20) : Error BCP070: Argument of type "null | object | object" is not assignable to parameter of type "Identity | null".
2022-11-04T15:58:56.9207063Z /home/vsts/work/1/s/policies/assignments/policyAssignmentsModule/managementGroup/deploy.bicep(59,20) : Error BCP070: Argument of type "null | object | object" is not assignable to parameter of type "Identity | null".
2022-11-04T15:58:56.9207814Z /home/vsts/work/1/s/policies/assignments/policyAssignmentsModule/managementGroup/deploy.bicep(59,20) : Error BCP070: Argument of type "null | object | object" is not assignable to parameter of type "Identity | null".
2022-11-04T15:58:56.9209356Z /home/vsts/work/1/s/policies/assignments/PolicyAssignments_cx.bicep(105,31) : Error BCP104: The referenced module has errors.
2022-11-04T15:58:56.9209986Z /home/vsts/work/1/s/policies/assignments/policyAssignmentsModule/deploy.bicep(1,1) : Info Bicep Linter Configuration: Custom bicepconfig.json file found (/home/vsts/work/1/s/bicepconfig.json).
2022-11-04T15:58:56.9210620Z /home/vsts/work/1/s/policies/assignments/policyAssignmentsModule/deploy.bicep(79,28) : Error BCP104: The referenced module has errors.
2022-11-04T15:58:56.9211518Z /home/vsts/work/1/s/policies/assignments/policyAssignmentsModule/deploy.bicep(101,29) : Error BCP104: The referenced module has errors.
2022-11-04T15:58:56.9212075Z /home/vsts/work/1/s/policies/assignments/policyAssignmentsModule/deploy.bicep(123,28) : Error BCP104: The referenced module has errors.
2022-11-04T15:58:56.9212693Z /home/vsts/work/1/s/policies/exemptions/PolicyExemptions_cx.bicep(1,1) : Info Bicep Linter Configuration: Custom bicepconfig.json file found (/home/vsts/work/1/s/bicepconfig.json).
2022-11-04T15:58:56.9213385Z /home/vsts/work/1/s/policies/definitions/PolicyDefinitions_cx.bicep(1,1) : Info Bicep Linter Configuration: Custom bicepconfig.json file found (/home/vsts/work/1/s/bicepconfig.json).
2022-11-04T15:58:56.9214109Z /home/vsts/work/1/s/policies/assignments/policyAssignmentsModule/subscription/deploy.bicep(1,1) : Info Bicep Linter Configuration: Custom bicepconfig.json file found (/home/vsts/work/1/s/bicepconfig.json).
2022-11-04T15:58:56.9214873Z /home/vsts/work/1/s/policies/assignments/policyAssignmentsModule/subscription/deploy.bicep(59,20) : Error BCP070: Argument of type "null | object | object" is not assignable to parameter of type "Identity | null".
2022-11-04T15:58:56.9215619Z /home/vsts/work/1/s/policies/assignments/policyAssignmentsModule/subscription/deploy.bicep(59,20) : Error BCP070: Argument of type "null | object | object" is not assignable to parameter of type "Identity | null".
2022-11-04T15:58:56.9216313Z /home/vsts/work/1/s/policies/deploy.bicep(1,1) : Info Bicep Linter Configuration: Custom bicepconfig.json file found (/home/vsts/work/1/s/bicepconfig.json).
2022-11-04T15:58:56.9216849Z /home/vsts/work/1/s/policies/deploy.bicep(16,27) : Error BCP104: The referenced module has errors.
2022-11-04T15:58:56.9996289Z [33;1mVERBOSE: Invoke task with[0m
2022-11-04T15:58:57.0046898Z [33;1mVERBOSE: {
2022-11-04T15:58:57.0047307Z   "subscriptionId": "$(subscriptionId)",
2022-11-04T15:58:57.0047656Z   "templateFilePath": "/home/vsts/work/1/s/policies/deploy.bicep",
2022-11-04T15:58:57.0047968Z   "additionalParameters": {},
2022-11-04T15:58:57.0048339Z   "parameterFilePath": "/home/vsts/work/1/s/policies/.parameters/dev.weu.parameters.json",
2022-11-04T15:58:57.0048712Z   "location": "westeurope",
2022-11-04T15:58:57.0049127Z   "managementGroupId": "dev-mg-cx",
2022-11-04T15:58:57.0049443Z   "resourceGroupName": "$(resourceGroupName)"
2022-11-04T15:58:57.0049690Z }
2022-11-04T15:58:57.0049980Z [0m
2022-11-04T15:58:57.0336886Z [33;1mVERBOSE: Determined deployment scope [managementGroup][0m
2022-11-04T15:58:57.0439327Z [33;1mVERBOSE: Testing with deployment name [policies-20221104T1511570378Z][0m
2022-11-04T15:58:57.0457514Z [33;1mVERBOSE: Performing the operation "Test" on target "Management group level deployment".[0m
2022-11-04T15:59:03.9792490Z [33;1mVERBOSE: Using Bicep v0.11.1[0m
...
2022-11-04T15:59:31.0609020Z [33;1mVERBOSE: 15:59:31 - Template is valid.[0m
2022-11-04T15:59:31.1892187Z [33;1mVERBOSE: Template is valid[0m
2022-11-04T15:59:31.6351996Z ##[error]Script failed with exit code: 1
2022-11-04T15:59:31.6373994Z [command]/usr/bin/az account clear

@alex-frankel this is a shortend output from an ADO pipeline with ubuntu-latest which says that its using bicep v0.11.1

and again, this only happens using a local module. Not when I use the same module publishen in an ACR!

AlexanderSehr commented 1 year ago

@SeSeicht Fun fact: If you wrap the place where the variable is used into an any(...), the error goes away. Not really nice, but at least a workaround.

SeSeicht commented 1 year ago

@SeSeicht Fun fact: If you wrap the place where the variable is used into an any(...), the error goes away. Not really nice, but at least a workaround.

this workaround works for me aswell!