ResourceModules icon indicating copy to clipboard operation
ResourceModules copied to clipboard

[Bug Report]: Microsoft.Cache/redis - privateDnsZoneGroups was provided an invalid value

Open DanielLarsenNZ opened this issue 3 years ago • 1 comments

Describe the bug

When deploying Azure Redis Cache with a private endpoint and the privateDnsZoneGroups param is not set, the deployment fails with:

Template parameter 'privateDnsZoneGroups' was provided an invalid value. Expected a value of type 'Array', but received a value of type 'Object'

The problem is that line 256 defaults to an empty object instead of an empty array:

privateDnsZoneGroup: contains(privateEndpoint, 'privateDnsZoneGroup') ? privateEndpoint.privateDnsZoneGroup : {}

https://github.com/Azure/ResourceModules/blob/main/modules/Microsoft.Cache/redis/deploy.bicep#L256

The line should be changed to:

privateDnsZoneGroup: contains(privateEndpoint, 'privateDnsZoneGroup') ? privateEndpoint.privateDnsZoneGroup : []

To reproduce

Run this bicep:

module vnetModule 'modules/Microsoft.Network/virtualNetworks/deploy.bicep' = {
  name: 'vnet'
  params: {
    location: location
    addressPrefixes: [
      '10.0.0.0/16'
    ]
    name: vnet
    subnets: [
      {
        addressPrefix: '10.0.4.0/24'
        name: 'redis'
        privateEndpointNetworkPolicies: 'Disabled'
        privateLinkServiceNetworkPolicies: 'Enabled'
      }
    ]
  }
}

module privateRedisDnsZone 'modules/Microsoft.Network/privateDnsZones/deploy.bicep' = {
  name: 'privateRedisDnsZone'
  params: {
    name: 'privatelink.redis.cache.windows.net'
  }
}

module redisCacheModule 'modules/Microsoft.Cache/redis/deploy.bicep' = {
  name: redis
  params: {
    name: redis
    location: location
    skuName: 'Premium'
    capacity: 1
    privateEndpoints: [
      {
        name: '${redis}-pep'
        subnetResourceId: vnetModule.outputs.subnetResourceIds[4]
        service: 'redisCache'
        privateDnsZoneResourceIds: [
          privateRedisDnsZone.outputs.resourceId
        ]
      }
    ]
    publicNetworkAccess: 'Disabled'
  }
}

Deployment will throw "'Template parameter 'privateDnsZoneGroups' was provided an invalid value. Expected a value of type 'Array', but received a value of type 'Object'."

Code snippet

No response

Relevant log output

{"status":"Failed","error":{"code":"DeploymentFailed","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.","details":[{"code":"Conflict","message":"{\r\n  \"status\": \"Failed\",\r\n  \"error\": {\r\n    \"code\": \"ResourceDeploymentFailure\",\r\n    \"message\": \"The resource operation completed with terminal provisioning state 'Failed'.\",\r\n    \"details\": [\r\n      {\r\n        \"code\": \"DeploymentFailed\",\r\n        \"message\": \"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.\",\r\n        \"details\": [\r\n          {\r\n            \"code\": \"BadRequest\",\r\n            \"message\": \"{\\r\\n  \\\"error\\\": {\\r\\n    \\\"code\\\": \\\"InvalidTemplate\\\",\\r\\n    \\\"message\\\": \\\"Deployment template validation failed: 'Template parameter 'privateDnsZoneGroups' was provided an invalid value. Expected a value of type 'Array', but received a value of type 'Object'. Please see https://aka.ms/resource-manager-parameter-files for usage details.'.\\\",\\r\\n    \\\"additionalInfo\\\": [\\r\\n      {\\r\\n        \\\"type\\\": \\\"TemplateViolation\\\",\\r\\n        \\\"info\\\": {\\r\\n          \\\"lineNumber\\\": 1,\\r\\n          \\\"linePosition\\\": 1668,\\r\\n          \\\"path\\\": \\\"properties.template.parameters.privateDnsZoneGroups\\\"\\r\\n        }\\r\\n      }\\r\\n    ]\\r\\n  }\\r\\n}\"\r\n          }\r\n        ]\r\n      }\r\n    ]\r\n  }\r\n}"}]}}

DanielLarsenNZ avatar Aug 19 '22 05:08 DanielLarsenNZ

I will create a PR for this.

DanielLarsenNZ avatar Aug 19 '22 05:08 DanielLarsenNZ

Closing as agreed in PR #1799. The issue was caused by incorrect parameter usage documentation and fixed by PR #1805

eriqua avatar Oct 24 '22 10:10 eriqua