How to define a parent if I use if expression? #15684
-
I have the bicep template below for Kusto cluster, where I am defining a resource with or without zones by using if expression (that's the only way I understood I could do it):
How to define which parent to use in |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
It would be way simpler to only define the kusto cluster once since all that changes is the "zones" property and put the if conditions on resources / variables depending on that reosurces metadata description = 'Deploys a Kusto cluster with databases and principal assignments for enhanced data management and security.'
@description('The name of the Kusto cluster.')
param __clusterName string
@description('Array of databases to be created within the Kusto cluster. Each object should include databaseName.')
param __databases array
@description('Array of principal assignments for the Kusto cluster. Each object should include role, principalIdResourceId, tenantId, and principalType.')
param __clusterPrincipals {
role: string
tenantId: string
principalType: string
principalIdResourceId: string
}[]
@description('The capacity of the SKU tier for the Kusto cluster instance.')
param __clusterSkuCapacity int
@description('The SKU name for the Kusto cluster instance.')
param __clusterSkuName string
@description('The SKU tier for the Kusto cluster instance.')
param __clusterSkuTier string
@description('The location for the Kusto cluster (e.g., East US, West Europe).')
param __location string
@description('Enable or disable the purge feature in the Kusto cluster.')
param __enablePurge bool
@description('Enable or disable streaming ingestion in the Kusto cluster.')
param __enableStreamingIngest bool
@description('Enable or disable automatic stopping of the Kusto cluster.')
param __enableAutoStop bool
@description('Enable or disable optimized autoscale for the Kusto cluster.')
param __enableOptimizedAutoscale bool
@description('The maximum scale for optimized autoscale in the Kusto cluster.')
param __scaleMaximum int
@description('The minimum scale for optimized autoscale in the Kusto cluster.')
param __scaleMinimum int
@description('The version number for optimized autoscale in the Kusto cluster.')
param __scaleVersion int
@description('Availability zones for the Kusto cluster.')
param __zones array
@description('Flag to determine if user-assigned identities should be configured for the Kusto cluster.')
param __isToConfigureUserAssignedIdentities bool
@description('Flag to determine if AvailabilityZone should be disabled for this cluster.')
param __isToDisableAvailabilityZone bool
@description('User-assigned identities for the Kusto cluster.')
param __userAssignedIdentities object
@description('The type of identity to assign to the Kusto cluster (e.g., SystemAssigned, UserAssigned).')
param __identityType string
@description('Language extensions to be enabled in the Kusto cluster, if applicable.')
param __languageExtensions object
@description('Enable or disable language extensions in the Kusto cluster.')
param __languageExtensionsEnabled bool
@description('Tags to be applied to this resource.')
param __tags object = {}
var identityTypeSettingVar = {
type: __identityType
}
var userAssignedIdentitiesSettingVar = {
userAssignedIdentities: __userAssignedIdentities
}
resource kustoCluster 'Microsoft.Kusto/clusters@2023-08-15' = {
name: __clusterName
location: __location
sku: {
name: __clusterSkuName
tier: __clusterSkuTier
capacity: __clusterSkuCapacity
}
identity: ((__isToConfigureUserAssignedIdentities == true)
? union(identityTypeSettingVar, userAssignedIdentitiesSettingVar)
: identityTypeSettingVar)
zones: __isToDisableAvailabilityZone == false ? __zones : null
properties: {
trustedExternalTenants: [
{
value: '*'
}
]
enablePurge: __enablePurge
enableStreamingIngest: __enableStreamingIngest
enableAutoStop: __enableAutoStop
enableDiskEncryption: true
optimizedAutoscale: {
isEnabled: __enableOptimizedAutoscale
maximum: __scaleMaximum
minimum: __scaleMinimum
version: __scaleVersion
}
languageExtensions: __languageExtensionsEnabled ? __languageExtensions : null
}
tags: __tags
}
@description('Database resources created within the Kusto cluster, with a default read/write kind.')
resource kustoClusterName_database 'Microsoft.Kusto/clusters/databases@2023-08-15' = [
for item in __databases: if(!__isToDisableAvailabilityZone) {
parent: kustoCluster
name: item
location: __location
kind: 'ReadWrite'
properties: {
softDeletePeriod: 'P30D'
hotCachePeriod: 'P7D'
}
}
]
@description('Principal assignments for the Kusto cluster, including role and tenant information.')
resource kustoCluster_clusterPrincipalAssignments 'Microsoft.Kusto/clusters/principalAssignments@2023-08-15' = [
for item in __clusterPrincipals: if(!__isToDisableAvailabilityZone) {
parent: kustoCluster
name: '${last(split(item.principalIdResourceId,'/'))}-${item.role}'
properties: {
principalId: reference(item.principalIdResourceId, '2023-08-15').principalId
role: item.role
tenantId: item.tenantId
principalType: item.principalType
}
}
]
@description('The ID of the deployed Kusto cluster resource.')
output kustoClusterId string = kustoCluster.id
@description('Array of database IDs created within the Kusto cluster.')
output databaseIds array = __isToDisableAvailabilityZone ? [] : map(kustoClusterName_database, (db, i) => {
databaseName: db.name
databaseId: db.id
})
@description('Array of principal assignment IDs created within the Kusto cluster.')
output clusterPrincipalAssignmentIds array = __isToDisableAvailabilityZone ? [] : map(kustoCluster_clusterPrincipalAssignments, (cpa, i) => {
principalName: cpa.name
principalId: cpa.id
})
|
Beta Was this translation helpful? Give feedback.
I am not familiar with the kusto resources so if any conditional is not needed you can remove them.
If the zones cannot be null, I would assume that you should provide as a value an array either 1, 2 or 3. If a resource is not zonal, it should select one zone at random in the backend and specifying a single zone yourself would reproduce the scenario of non zonal cluster.
A bit like how VMs can be placed in specific availability zones and if not provided, they are put in a single zone in an opaque way.
If this does not work, as an alternative, you could create a submodule to put zonal specific code in there.
EDIT:
I successfully deployed a non zonal Azure Data Explorer cluster with the fol…