Check resource reference dependency in ARM template

I have the template below where I am checking whether database exist before assignment the principals, but I am still having problems with ADF doesn’t exist, I assume this is happening in the properties, but I wasn’t able to find the solution.

I have added an if statement in that reference, but I still having the same problem. How can bypass this?

My ARM template:

{
  "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "0.0.0.0",
  "parameters": {
    "clusterName": {
      "type": "string"
    },
    "databaseIDPrincipals": {
      "type": "array"
    },
    "databaseADFPrincipals": {
      "type": "array"
    },
    "databaseSYNPrincipals": {
      "type": "array"
    },
    "description": {
      "type": "string",
      "defaultValue": ""
    }
  },
  "resources": [
    {
      "condition": "[empty(resourceId('Microsoft.Kusto/clusters/databases', parameters('clusterName'), parameters('databaseIDPrincipals')[copyIndex()].databaseName))]",
      "type": "Microsoft.Kusto/clusters/databases/principalAssignments",
      "apiVersion": "2019-11-09",
      "name": "[concat(parameters('clusterName'), '/', parameters('databaseIDPrincipals')[copyIndex()].databaseName, '/', concat(parameters('databaseIDPrincipals')[copyIndex()].principalId, parameters('databaseIDPrincipals')[copyIndex()].role))]",
      "copy": {
        "name": "databaseIDPrincipalsCopy",
        "count": "[length(parameters('databaseIDPrincipals'))]"
      },
      "properties": {
        "principalId": "[parameters('databaseIDPrincipals')[copyIndex()].principalId]",
        "role": "[parameters('databaseIDPrincipals')[copyIndex()].role]",
        "tenantId": "[parameters('databaseIDPrincipals')[copyIndex()].tenantId]",
        "principalType": "[parameters('databaseIDPrincipals')[copyIndex()].principalType]"
      },
      "tags": {
        "Version": "0.0.0.0",
        "Description": "[parameters('description')]"
      }
    },
    {
      "condition": "[empty(resourceId('Microsoft.Kusto/clusters/databases', parameters('clusterName'), parameters('databaseADFPrincipals')[copyIndex()].databaseName))]",
      "type": "Microsoft.Kusto/clusters/databases/principalAssignments",
      "apiVersion": "2019-11-09",
      "name": "[concat(parameters('clusterName'), '/', parameters('databaseADFPrincipals')[copyIndex()].databaseName, '/', concat(parameters('databaseADFPrincipals')[copyIndex()].principalId, parameters('databaseADFPrincipals')[copyIndex()].role))]",
      "copy": {
        "name": "databaseADFPrincipalsCopy",
        "count": "[length(parameters('databaseADFPrincipals'))]"
      },
      "properties": {
        "principalId": "[reference(resourceId(parameters('databaseADFPrincipals')[copyIndex()].subscriptionId, parameters('databaseADFPrincipals')[copyIndex()].resourceGroup, 'Microsoft.DataFactory/factories', parameters('databaseADFPrincipals')[copyIndex()].principalId), '2018-06-01','Full').identity.principalId]",
        "role": "[parameters('databaseADFPrincipals')[copyIndex()].role]",
        "tenantId": "[parameters('databaseADFPrincipals')[copyIndex()].tenantId]",
        "principalType": "[parameters('databaseADFPrincipals')[copyIndex()].principalType]"
      },
      "tags": {
        "Version": "0.0.0.0",
        "Description": "[parameters('description')]"
      }
    },
    {
      "condition": "[empty(resourceId('Microsoft.Kusto/clusters/databases', parameters('clusterName'), parameters('databaseSYNPrincipals')[copyIndex()].databaseName))]",
      "type": "Microsoft.Kusto/clusters/databases/principalAssignments",
      "apiVersion": "2019-11-09",
      "name": "[concat(parameters('clusterName'), '/', parameters('databaseSYNPrincipals')[copyIndex()].databaseName, '/', concat(parameters('databaseSYNPrincipals')[copyIndex()].principalId, parameters('databaseSYNPrincipals')[copyIndex()].role))]",
      "copy": {
        "name": "databaseSYNPrincipalsCopy",
        "count": "[length(parameters('databaseSYNPrincipals'))]"
      },
      "properties": {
        "principalId": "[reference(resourceId(parameters('databaseSYNPrincipals')[copyIndex()].subscriptionId, parameters('databaseSYNPrincipals')[copyIndex()].resourceGroup, 'Microsoft.Synapse/workspaces', parameters('databaseSYNPrincipals')[copyIndex()].principalId), '2021-06-01','Full').identity.principalId]",
        "role": "[parameters('databaseSYNPrincipals')[copyIndex()].role]",
        "tenantId": "[parameters('databaseSYNPrincipals')[copyIndex()].tenantId]",
        "principalType": "[parameters('databaseSYNPrincipals')[copyIndex()].principalType]"
      },
      "tags": {
        "Version": "0.0.0.0",
        "Description": "[parameters('description')]"
      }
    }
  ]
}

My error:

Reference dependency in ARM template

In general, the issue you mentioned occurs when the format for referencing the Data factory resource (Microsoft.DataFactory/factories) is not found during the deployment.

Make sure this resource is readily available while running the arm template. You can also use if function or add validation logic to check the existence of resources.

I tried to sample arm template where you will be able to fetch the resource existence as per the requirement.

ARM template:

{
  "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "0.0.0.0",
  "parameters": {
    "clusterName": {
      "type": "string",
      "defaultValue": "testvvvk"
    },
    "description": {
      "type": "string",
      "defaultValue": "ADF and Synapse Principal Assignment"
    }
  },
  "resources": [
    {
      "type": "Microsoft.Kusto/clusters/databases/principalAssignments",
      "apiVersion": "2019-11-09",
      "name": "[concat(parameters('clusterName'), '/testdbvkks/0d8bdfe2-c6ac-4a0a-af35-f9600bccf6a6')]",
      "properties": {
        "principalId": "",
        "role": "Admin",  // Use a valid Kusto database role
        "tenantId": "",
        "principalType": "App"  // Changed to valid value
      },
      "tags": {
        "Version": "0.0.0.0",
        "Description": "[parameters('description')]"
      }
    },
    {
      "type": "Microsoft.Kusto/clusters/databases/principalAssignments",
      "apiVersion": "2019-11-09",
      "name": "[concat(parameters('clusterName'), '/testdbvkks/sampleadfvkks')]",
      "properties": {
        "principalId": "[reference(resourceId('', 'vinay-rg', 'Microsoft.DataFactory/factories', 'sampleadfvkks'), '2018-06-01', 'Full').identity.principalId]",
        "role": "Viewer",  // Use a valid Kusto database role
        "tenantId": "",
        "principalType": "App"  // Changed to valid value
      },
      "tags": {
        "Version": "0.0.0.0",
        "Description": "[parameters('description')]"
      }
    },
    {
      "type": "Microsoft.Kusto/clusters/databases/principalAssignments",
      "apiVersion": "2019-11-09",
      "name": "[concat(parameters('clusterName'), '/testdbvkks/samplesyvkksb')]",
      "properties": {
        "principalId": "[reference(resourceId('', 'vinay-rg', 'Microsoft.Synapse/workspaces', 'samplesyvkksb'), '2021-06-01', 'Full').identity.principalId]",
        "role": "User",  // Use a valid Kusto database role
        "tenantId": "",
        "principalType": "App"  // Changed to valid value
      },
      "tags": {
        "Version": "0.0.0.0",
        "Description": "[parameters('description')]"
      }
    }
  ]
}

Deployment:

az deployment group create --resource-group vinay-rg --template-file armtemplate.json --parameters clusterName=testvvvk description="ADF and Synapse Principal Assignment"

Refer:

https://learn.microsoft.com/en-us/azure/data-explorer/add-database-principal?tabs=csharp

https://shisho.dev/dojo/providers/azurerm/Data_Explorer/azurerm-kusto-database-principal-assignment/

Recognized by Microsoft Azure Collective

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật