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

Inconsistency of type int allowing null in some scenarios, but not other #5938

Open
afscrome opened this issue Feb 10, 2022 · 8 comments
Open

Comments

@afscrome
Copy link
Contributor

Bicep version
VSCode v0.4.1124

Describe the bug
The bicep language seems somewhat inconsistent as to whether it allows null. In the below example, both scenarios describe a value of type int, however one allows null, and one doesn't.

Assuming this is the desired behaviour

  1. I'd like to see there be some difference in the type to make clear whether null is allowed. (e.g. the hover over for capacityReservationLevel should show the type as int? or int | null )
  2. Is there a way to specify that a parameter can be a nullable int.

To Reproduce
capacityReservationLevel is described as type int and allows null
image

However if you have a parameter of type int, then null isn't allowed
image

@ghost ghost added the Needs: Triage 🔍 label Feb 10, 2022
@alex-frankel
Copy link
Collaborator

I think the rule is "any resource property value is null-able", but it looks like we don't allow null for parameters which is interesting because what if you'd like to use that param as a property value of a resource? @majastrz / @shenglol any context on this one?

@alex-frankel
Copy link
Collaborator

We may need to introduce null-able types

@rushirg
Copy link

rushirg commented Mar 1, 2022

Faced similar issue with one of the property (defaultTtl) for CosmosDB

The docs says we can set the property to null but using bicep it throws an error (One of the specified inputs is invalid)

Bicep Version: Bicep CLI version 0.4.1008 (223b8d2)

// dummy resource
resource sqlDatabase_Container 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers@2021-10-15' = {
  name: sqlDatabaseContainer
  properties: {
    resource: {
      id: sqlDatabaseContainer
      defaultTtl: (defaultTtl >0 ? defaultTtl : null)
      }
   }
}

any plan to support this? or do we have any workaround? as there are multiple integer type of properties which we want to set as per their own conditions

@alex-frankel
Copy link
Collaborator

@rushirg - I am not able to repro this with v0.4.1272. Can you double check that you are hitting this with the latest version?

@rushirg
Copy link

rushirg commented Mar 2, 2022

@rushirg - I am not able to repro this with v0.4.1272. Can you double check that you are hitting this with the latest version?

Yes, hitting the same with Bicep CLI version 0.4.1272 (a69022d)
sharing the config for reference

param defaultTtl int = 0

resource sqlContainer 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers@2021-04-15' = {
  name: containerName
  properties: {
    resource: {
      id: containerName
      defaultTtl: ((defaultTtl > 0) ? defaultTtl : null)
      partitionKey: {
        paths: [
          '/id'
        ]
        kind: 'Hash'
      }
    }
  }
}

the only way I found to set the "Time to Live" off is by removing the property "defaultTtl" from the resource

@mszeqli
Copy link

mszeqli commented May 18, 2022

@rushirg - I am not able to repro this with v0.4.1272. Can you double check that you are hitting this with the latest version?

Yes, hitting the same with Bicep CLI version 0.4.1272 (a69022d) sharing the config for reference

param defaultTtl int = 0

resource sqlContainer 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers@2021-04-15' = {
  name: containerName
  properties: {
    resource: {
      id: containerName
      defaultTtl: ((defaultTtl > 0) ? defaultTtl : null)
      partitionKey: {
        paths: [
          '/id'
        ]
        kind: 'Hash'
      }
    }
  }
}

the only way I found to set the "Time to Live" off is by removing the property "defaultTtl" from the resource

+1 for this issue, there's no straightforward way to disable defaultTtl other than conditionally remove that property. Removing that property needs hacking as well. I'm seeing this issue using ARM template as well.

@hansmbakker
Copy link

Also hitting this when making a template for sql database.

We want to include a param that is only used for serverless databases but this results in Expected a value of type "int" but the provided value is of type "null"

@description('Minimum scaling for serverless databases. Minimum value is 1/8th of # of VCores of serverless tier. Use json(\'0.5\') syntax for decimal numbers.')
param minCapacity int = null

@ameltzer-MSFT
Copy link

ameltzer-MSFT commented Jan 12, 2024

Just to pile a +1 on to this. It was a gigantic pain to figure out how to work around this for conditionally setting a defaultTtl value for Cosmos DB instances that took hours of trial and error to get right.

Just in case anybody else is running into this, I ended up having to do something like this:

resource rCosmosDBContainer 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers@2022-08-15' = [for item in pContainers: {
  name: item.name
  parent: rCosmosDBSqlDatabase
  properties: {
    options: item.throughPutOption
    resource: union({
        id: item.name
        partitionKey: {
          paths: [
            item.partitionKey
          ]
          kind: 'hash'
        }
        indexingPolicy: {
          indexingMode: 'consistent'
          includedPaths: [
            {
              path: '/*'
            }
          ]
          excludedPaths: [
            {
              path: '/_etag/?'
            }
          ]
        }
      },
      item.ttl != null ? { defaultTtl: int(item.ttl) } : {})
  }
}]

The actual fix ended up being pretty straightforward, but figuring out the magic syntax turned out to be incredibly challenging. It also didn't help that union seems to break VSCode's ability to validate the object which meant lots of test deployments to tune everything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants