Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User-defined types optional property failing bicep deployment #11986

Closed
georgeollis opened this issue Sep 30, 2023 · 3 comments
Closed

User-defined types optional property failing bicep deployment #11986

georgeollis opened this issue Sep 30, 2023 · 3 comments
Assignees
Labels

Comments

@georgeollis
Copy link

georgeollis commented Sep 30, 2023

Hi, just curious, is this a known restriction within bicep or am I missing something? I'm trying to deploy an AVD host pool, I'm using a hostPoolProperties type with an optional friendlyName string. See below

image

I'm validating that the string may be null, and if so, it won't be used within the deployment.

image

I'm then calling the bicep file via a module that isn't specifying the friendlyName attribute because it's optional. Is the error expected?

image

image

@github-project-automation github-project-automation bot moved this to Todo in Bicep Sep 30, 2023
@georgeollis georgeollis changed the title User-defined optional property failing bicep deployment User-defined types optional property failing bicep deployment Sep 30, 2023
@jeskew
Copy link
Member

jeskew commented Oct 2, 2023

The expression empty(hostPoolObject.friendlyName) is what is failing at runtime because attempting to access a missing property in ARM will raise an error. There's an explanation for why ARM behaves this way in #11912 (comment)

Bicep introduced the .? (safe dereference) to try to help with this. empty(hostPoolObject.?friendlyName) will return false if the friendlyName property is missing, null, or an empty string (hostPoolObject.?friendlyName will evaluate to null if the property is missing).

It might help to have a linter rule that emits a warning diagnostic with a quick fix to replace a . (property access) operator with a .? operator if the accessed property is nullable.

@georgeollis
Copy link
Author

georgeollis commented Oct 4, 2023

Awesome, thank you. I would love to see that linter rule added.

@anthony-c-martin
Copy link
Member

Closed by #15838

@github-project-automation github-project-automation bot moved this from Todo to Done in Bicep Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

No branches or pull requests

5 participants