Search code examples
azure-aksazure-resource-managerazure-rm-templateazure-container-apps

Container App or Container App Environment ARM Template


I am trying to create a container app using ARM template. The container app is within a VNet and ingress connection is also limited to VNet. I downloaded the template for automation from portal and it has this in template


{
    "name": "[parameters('environmentName')]",
    "location": "[parameters('location')]",
    "dependsOn": [
        "[concat('Microsoft.OperationalInsights/workspaces/', parameters('workspaceName'))]",
        "Microsoft.Resources/deployments/newInfrastructureSubnetTemplate"
    ],
    "properties": {
        "internalLoadBalancerEnabled": false,
        "appLogsConfiguration": {
            "destination": "log-analytics",
            "logAnalyticsConfiguration": {
                "customerId": "[reference(concat('Microsoft.OperationalInsights/workspaces/', parameters('workspaceName')), '2020-08-01').customerId]",
                "sharedKey": "[listKeys(concat('Microsoft.OperationalInsights/workspaces/', parameters('workspaceName')), '2020-08-01').primarySharedKey]"
            }
        },
        "vnetConfiguration": {
            "infrastructureSubnetId": "/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.Network/virtualNetworks/containerapps-vnet/subnets/containerapps-subnet-0",
            "internal": true
        },
        "zoneRedundant": false
    },
    "apiVersion": "2022-03-01",
    "type": "Microsoft.App/managedEnvironments"
}

But this fails with an error because of failure due to managed cluster.

New-AzResourceGroupDeployment : 3:11:14 PM - The deployment 'template' failed with error(s). Showing 1 out of 1 error(s).
Status Message: Managed environment failed to initialize due to managed clusters failed. (Code:OperationFailed)
CorrelationId: <correlation-id>
At line:1 char:1
+ New-AzResourceGroupDeployment -ResourceGroupName dhapi-ml -TemplateFi ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [New-AzResourceGroupDeployment], Exception
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGroupDeploymentCmdlet

VNet, subnet and log-analytics workspace are also created using the same template as below for your reference.


{
    "apiVersion": "2020-08-01",
    "name": "[parameters('workspaceName')]",
    "type": "Microsoft.OperationalInsights/workspaces",
    "location": "[parameters('workspaceLocation')]",
    "dependsOn": [],
    "properties": {
        "sku": {
            "name": "PerGB2018"
        },
        "retentionInDays": 30,
        "workspaceCapping": {}
    }
},
{
    "type": "Microsoft.Resources/deployments",
    "apiVersion": "2020-06-01",
    "name": "newInfrastructureSubnetTemplate",
    "resourceGroup": "<resource-group-name>",
    "subscriptionId": "<subscription-id>",
    "properties": {
        "mode": "Incremental",
        "template": {
            "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
            "contentVersion": "1.0.0.0",
            "parameters": {},
            "variables": {},
            "resources": [
                {
                    "type": "Microsoft.Network/virtualNetworks/subnets",
                    "apiVersion": "2020-07-01",
                    "name": "containerapps-vnet/containerapps-subnet-0",
                    "properties": {
                        "delegations": [],
                        "serviceEndpoints": [],
                        "addressPrefix": "10.0.0.0/23"
                    }
                }
            ]
        }
    },
    "dependsOn": [
        "[resourceId('Microsoft.Network/virtualNetworks', 'containerapps-vnet')]"
    ]
},
{
    "type": "Microsoft.Network/virtualNetworks",
    "apiVersion": "2020-07-01",
    "location": "eastus",
    "name": "containerapps-vnet",
    "properties": {
        "addressSpace": {
            "addressPrefixes": [
                "10.0.0.0/16"
            ]
        },
        "subnets": []
    }
}

Solution

  • The subscription was not registered to use Microsoft.ContainerService I just registered it from portal or you can use powershell/azcli to do it. And then it worked to create the container app.