Azure communication service/email ARM deployment error with dependsOn ... how do I get this to work?

Allen Langlois 0 Reputation points
2023-03-14T18:00:15.0666667+00:00

error:

cli.azure.cli.core.azclierror: {"code": "InvalidTemplate", "target": "/subscriptions/5ebb90ca-e01c-4193-89c6-d450f0496981/resourceGroups/SIM-MARKETPLACE-6/providers/Microsoft.Resources/deployments/acsemailTemplate", "message": "Deployment template validation failed: 'The template resource 'Noneeastus71bacse-cs' at line '44' and column '9' is not valid: Unable to evaluate template language function 'resourceId': function requires exactly one multi-segmented argument which must be resource type including resource provider namespace. Current function arguments 'Microsoft.Communication/emailServices/domains,Noneeastus71bacse-email/domains/AzureManagedDomain'. Please see https://aka.ms/arm-resource-functions/#resourceid for usage details.. Please see https://aka.ms/arm-functions for usage details.'.", "additionalInfo": [{"type": "TemplateViolation", "info": {"lineNumber": 44, "linePosition": 9, "path": "resources[2]"}}]}

az_command_data_logger: {"code": "InvalidTemplate", "target": "/subscriptions/5ebb90ca-e01c-4193-89c6-d450f0496981/resourceGroups/SIM-MARKETPLACE-6/providers/Microsoft.Resources/deployments/acsemailTemplate", "message": "Deployment template validation failed: 'The template resource 'Noneeastus71bacse-cs' at line '44' and column '9' is not valid: Unable to evaluate template language function 'resourceId': function requires exactly one multi-segmented argument which must be resource type including resource provider namespace. Current function arguments 'Microsoft.Communication/emailServices/domains,Noneeastus71bacse-email/domains/AzureManagedDomain'. Please see https://aka.ms/arm-resource-functions/#resourceid for usage details.. Please see https://aka.ms/arm-functions for usage details.'.", "additionalInfo": [{"type": "TemplateViolation", "info": {"lineNumber": 44, "linePosition": 9, "path": "resources[2]"}}]}

here is the ARM Template:

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "acsemailName": {
            "type": "string"
        },
        "tagsByResource": {
            "type": "object"
        },
        "dataLocation": {
            "type": "string"
        }
    },
    "variables": { 
        "acseResourceName": "[concat(parameters('acsemailName'),'-email','/domains/AzureManagedDomain')]"
    },
    "resources": [
        {
            "apiVersion": "2021-10-01-preview",
            "name": "[concat(parameters('acsemailName'),'-email')]",
            "location": "global",
            "type": "Microsoft.Communication/emailServices",
            "tags": "[ if(contains(parameters('tagsByResource'), 'Microsoft.Communication/EmailServices'), parameters('tagsByResource')['Microsoft.Communication/EmailServices'], json('{}')) ]",
            "properties": {
                "dataLocation": "[parameters('dataLocation')]"
            } 
        },
        {
            "type": "Microsoft.Communication/emailServices/domains",
            "apiVersion": "2022-07-01-preview",
            "name": "[concat(parameters('acsemailName'),'-email','/AzureManagedDomain')]",
            "location": "global",
            "tags": "[parameters('tagsByResource')]",
            "properties": {
                "domainManagement": "AzureManaged",
                "userEngagementTracking": "Enabled",
                "validSenderUsernames": {"DoNotReply": "DoNotReply"}
            },
            "dependsOn": [
                    "[resourceId('Microsoft.Communication/emailServices', concat(parameters('acsemailName'),'-email'))]"
                ]
        },
        {
        "type": "Microsoft.Communication/CommunicationServices",
        "apiVersion": "2022-07-01-preview",
        "name": "[concat(parameters('acsemailName'),'-cs')]",
        "location": "global",
        "tags": "[parameters('tagsByResource')]",
        "properties": {
            "dataLocation": "[parameters('dataLocation')]",
            "linkedDomains": [
                "[concat(resourceId('Microsoft.Communication/emailServices', concat(parameters('acsemailName'),'-email')),
                 '/domains/AzureManagedDomain')]"
            ]
        },
        "dependsOn": [
                "[resourceId('Microsoft.Communication/emailServices',concat(parameters('acsemailName'),'-email'))]",
                "[resourceId('Microsoft.Communication/emailServices/domains',variables('acseResourceName'))]"
        ]
    } 
]
}

Azure Communication Services
Azure Communication Services
An Azure communication platform for deploying applications across devices and platforms.
684 questions
{count} votes

1 answer

Sort by: Most helpful
  1. VenkateshDodda-MSFT 18,441 Reputation points Microsoft Employee
    2023-03-15T10:41:50.4866667+00:00

    @Allen Langlois Thank you for reaching out to Microsoft Q&A, apologize for any inconvenience caused on this.
    We have tried to deploy the above the shared template and it failed with same error message.

    Upon checking further, in your template in communication service resource block you have added dependson property on both emailservices and email services/domains it should be dependent only on emailservices/domains only.

    I have made the below changes to the above shared template and tested it as well it is working fine and I would suggest you validate from your end as well.

    Here is the Modified template:

    {
        "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
        "contentVersion": "1.0.0.0",
        "parameters": {
            "acsemailName": {
                "type": "string"
            },
            "tagsByResource": {
                "type": "object"
            },
            "dataLocation":{
                "type": "string"
            }
        },
        "functions": [],
        "variables": {
            "acsename": "[concat(parameters('acsemailName'),'-email')]"
            
        },
        "resources": [
            {
                "type": "Microsoft.Communication/emailServices",
                "apiVersion": "2022-07-01-preview",
                "location": "global",
                "name" :"[variables('acsename')]",
                "tags": "[parameters('tagsByResource')]",
                "properties":{
                    "dataLocation" :"[parameters('dataLocation')]"
                }
            },
            {
                "type": "Microsoft.Communication/communicationServices",
                "apiVersion": "2022-07-01-preview",
                "location": "global",
                "name" : "[concat(parameters('acsemailName'),'-cs')]",
                "tags": "[parameters('tagsByResource')]",
                "dependsOn":[
                    "[resourceId('Microsoft.Communication/emailServices/domains',variables('acsename'),'AzureManagedDomain')]"
                ],
                "properties": {
                    "dataLocation":"[parameters('dataLocation')]",
                    "linkedDomains": [
                        "[resourceId('Microsoft.Communication/emailServices/domains',variables('acsename'),'AzureManagedDomain')]"
                    ]
                }
            },
            {
                "type": "Microsoft.Communication/emailServices/domains",
                "apiVersion": "2022-07-01-preview",
                "location": "global",
                "name": "[concat(variables('acsename'),'/AzureManagedDomain')]",
                "tags":"[parameters('tagsByResource')]",
                "properties":{
                    "domainManagement": "AzureManaged",
                    "userEngagementTracking": "Enabled",
                    "validSenderUsernames":{"DoNotReply": "DoNotReply"}
                },
                "dependsOn": [
                    "[resourceId('Microsoft.Communication/emailServices', variables('acsename'))]"
                ]
            }
        ],
        "outputs": {}
    }
    
    

    We have passed the parameters as a hashtable to the New-AzResourceGroupdeployment here is the sample cmdlet that we have used to deploy the above template from local visual studio code.

    $parms= @{ acsemailName="<AcsName>"                                                                                                                          tagsByResource= @{test="Microsoft.communication/EmailServices";
    teste2="checker"}
    dataLocation="unitedstates"}
    
    New-AzResourceGroupDeployment -Name '<deploymentName>' -ResourceGroupName '<resourceGroupName>' -TemplateFile <localMachinePath> -TemplateParameterObject $parms -Verbose 
    

    Feel free to reach back to me if you have any further questions on this.