Azure / bicep-types-az

Bicep type definitions for ARM resources
MIT License
84 stars 27 forks source link

Unable to parse request payload when creating services on Microsoft.DocumentDB/databaseAccounts #2167

Open royberris opened 4 months ago

royberris commented 4 months ago

Bicep version Bicep CLI version 0.27.1 (4b41cb6d4b)

Describe the bug When trying to create a services child resource on Microsoft.DocumentDB/databaseAccounts@2024-02-15-preview it gives me the error that the payload cannot be parsed.

https://learn.microsoft.com/en-us/azure/templates/microsoft.documentdb/2024-02-15-preview/databaseaccounts/services?pivots=deployment-language-bicep#resource-format

To Reproduce

param cosmosAccountName string
param enableDedicatedGateway bool

resource cosmosAccount 'Microsoft.DocumentDB/databaseAccounts@2024-02-15-preview' = {
  name: cosmosAccountName
  location: location
  kind: 'GlobalDocumentDB'
  tags: {
    defaultExperience: 'Core (SQL)'
    'hidden-cosmos-mmspecial': ''
  }
  properties: {
    publicNetworkAccess: 'Enabled'
    enableAutomaticFailover: false
    enableMultipleWriteLocations: false
    isVirtualNetworkFilterEnabled: false
    virtualNetworkRules: []
    disableKeyBasedMetadataWriteAccess: false
    enableFreeTier: false
    enableAnalyticalStorage: false
    analyticalStorageConfiguration: {
      schemaType: 'WellDefined'
    }
    databaseAccountOfferType: 'Standard'
    enableMaterializedViews: false
    defaultIdentity: 'FirstPartyIdentity'
    networkAclBypass: 'None'
    disableLocalAuth: false
    enablePartitionMerge: false
    enablePerRegionPerPartitionAutoscale: false
    enableBurstCapacity: false
    enablePriorityBasedExecution: false
    minimalTlsVersion: 'Tls12'
    consistencyPolicy: {
      defaultConsistencyLevel: 'Session'
      maxIntervalInSeconds: 5
      maxStalenessPrefix: 100
    }
    locations: [
      {
        locationName: 'West Europe'
        failoverPriority: 0
        isZoneRedundant: false
      }
    ]
    cors: []
    capabilities: [
      {
        name: 'EnableServerless'
      }
    ]
    ipRules: []
    backupPolicy: {
      type: 'Periodic'
      periodicModeProperties: {
        backupIntervalInMinutes: 240
        backupRetentionIntervalInHours: 8
        backupStorageRedundancy: 'Geo'
      }
    }
    networkAclBypassResourceIds: []
    diagnosticLogSettings: {
      enableFullTextQuery: 'None'
    }
    capacity: {
      totalThroughputLimit: 4000
    }
  }

  resource dedicatedGateway 'services' = if (enableDedicatedGateway) {
    name: 'gateway'
    properties: {
      instanceCount: 1
      instanceSize: 'Cosmos.D4s'
    }
  }
}

Additional context

This is being deployed to an existing cosmos db that does not yet have a dedicated gateway.

Error from Azure Portal deployments on the resource group:

{
  "code": "DeploymentFailed",
  "target": "/subscriptions/xxxx/resourceGroups/dev-rg/providers/Microsoft.Resources/deployments/cosmosDb",
  "message": "At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-deployment-operations for usage details.",
  "details": [
    {
      "code": "BadRequest",
      "target": "/subscriptions/xxxx/resourceGroups/dev-rg/providers/Microsoft.DocumentDB/databaseAccounts/dev-cosmos/services/gateway",
      "message": "Unable to parse request payload. \r\nActivityId: 74d83e42-8fde-4de4-86df-a01a967e3b63, Microsoft.Azure.Documents.Common/2.14.0"
    }
  ]
}
royberris commented 4 months ago

After looking through issues I found https://github.com/Azure/bicep-types-az/issues/2043

Correct configuration is as following:

resource dedicatedGateway 'services' = if (enableDedicatedGateway) {
    name: 'SqlDedicatedGateway'
    properties: {
      instanceCount: 1
      instanceSize: 'Cosmos.D4s'
      serviceType: 'SqlDedicatedGateway'
    }
  }

For Cosmos DB Dedicated Gateway the name has to be SqlDedicatedGateway and a property named serviceType needs to be set to SqlDedicatedGateway. This is not documented anywhere and bicep doesn't recognize the serviceType.

I'm keeping this issue open because bicep should recognize a problem here and warn me about it.

alex-frankel commented 4 months ago

Tagging @markjbrown - any documentation we can update or swagger enums we can add to reduce friction here?

markjbrown commented 4 months ago

Thanks @alex-frankel. Will take up with the team. We will revert on this soon. Thanks.

pjohari-ms commented 3 months ago

@royberris the serviceType options have been updated in the documentation: https://learn.microsoft.com/en-us/rest/api/cosmos-db-resource-provider/service/create?view=rest-cosmos-db-resource-provider-2024-05-15-preview&tabs=HTTP

pjohari-ms commented 3 months ago

https://learn.microsoft.com/en-us/azure/templates/microsoft.documentdb/2024-05-15-preview/databaseaccounts/services?pivots=deployment-language-bicep#resource-format For the bicep link

markjbrown commented 3 months ago

@alex-frankel , this has been fixed. Feel free to close this issue.

Thanks!