microsoftgraph / msgraph-bicep-types

Repo contains Microsoft Graph resource types to integrate with bicep templates.
MIT License
43 stars 7 forks source link

User-defined types on appRoles #62

Closed Gijsreyn closed 11 months ago

Gijsreyn commented 11 months ago

Creating user-defined types on appRoles in Microsoft.Graph/applications@beta, throws me an error of the following: Property appRoles in payload has a value that does not match schema.

main.bicep

@description('Required. Name of application.')
param name string

@description('Required. Display name of the application.')
param displayName string

param appRoles appRoleType?

resource application 'Microsoft.Graph/applications@beta' = {
  name: name
  displayName: displayName
  appRoles: appRoles ?? []
}

type appRoleType = {
  @description('Required. Specify whether the app role can be assigned to users/groups or applications')
  allowedMemberTypes: ('User' | 'Application')[]

  @description('Required. If the application role is enabled or not.')
  isEnabled: bool

  @description('Required. Specify the display name of the application role e.g. Writers')
  displayName: string

  @description('Required. Specify the description of the application role')
  description: string

  @description('Requred. Specify the value which will be included in the "roles" claim')
  value: string

  @description('Required. Specify valid GUID')
  id: string
}

output appObject object = application

main.bicepparam

using 'main.bicep'

param name = 'MyApplication'

param displayName = 'My application'

param appRoles = {
  allowedMemberTypes: [
    'Application'
  ]
  isEnabled: true
  displayName: 'Writers'
  description: 'Writers'
  value: 'Writers'
  id: '3d639c6e-c986-48b1-a6bb-eed7eff0c674'
}

When simple adding the properties hardcoded, the Inputs parameters are exactly the same.

dkershaw10 commented 11 months ago

Thanks for filing this issue. We'll investigate and come back to you.

dkershaw10 commented 11 months ago

@Gijsreyn I think there might be a bug in your script definition. appRoles is an array, but it seems like you've declared your parameter as a complex type/structure (which would be a single record in the array).

When I copy your code, I even see a squiggly line under the appRoles defintions in the main.bicep file, with this error: The property "appRoles" expected a value of type "MicrosoftGraphAppRole[] | null" but the provided value is of type " | { allowedMemberTypes: ('Application' | 'User')[], isEnabled: bool, displayName: string, description: string, value: string, id: string }"

This worked for me (note I renamed the appRoles param to appRole in mine - I also needed to add provider 'microsoftGraph@1.0.0' at the beginning of the Bicep file.):

param appRole appRoleType

resource application 'Microsoft.Graph/applications@beta' = {
  name: name
  displayName: displayName
  appRoles: [appRole] ?? []
}

Does this work for you? BTW - is intellisense working for you?

Gijsreyn commented 11 months ago

@dkershaw10 Chips, just a little mistake from my end then.

No intellisense does not fully work. Doesn't it have to do something with the language server on the compiler and the provider, maybe?

dkershaw10 commented 11 months ago

Thanks. OK - closing this issue now.