{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "metadata": {
    "_generator": {
      "name": "bicep",
      "version": "0.18.4.5664",
      "templateHash": "15046971136878174535"
    }
  },
  "parameters": {
    "prefix": {
      "type": "string",
      "defaultValue": "$uniqueString(resourceGroup().id)",
      "metadata": {
        "description": "Specifies the name prefix."
      }
    },
    "letterCaseType": {
      "type": "string",
      "defaultValue": "UpperCamelCase",
      "allowedValues": [
        "CamelCase",
        "UpperCamelCase",
        "KebabCase"
      ],
      "metadata": {
        "description": "Specifies whether name resources are in CamelCase, UpperCamelCase, or KebabCase."
      }
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Specifies the location."
      }
    },
    "tags": {
      "type": "object",
      "defaultValue": {
        "IaC": "Bicep",
        "Demo": "Azure Container Apps Jobs"
      },
      "metadata": {
        "description": "Specifies the resource tags."
      }
    },
    "containerAppEnvironmentName": {
      "type": "string",
      "defaultValue": "[if(equals(parameters('letterCaseType'), 'UpperCamelCase'), format('{0}{1}Environment', toUpper(first(parameters('prefix'))), toLower(substring(parameters('prefix'), 1, sub(length(parameters('prefix')), 1)))), if(equals(parameters('letterCaseType'), 'CamelCase'), format('{0}Environment', toLower(parameters('prefix'))), format('{0}-environment', toLower(parameters('prefix')))))]",
      "metadata": {
        "description": "Specifies the name of the Azure Container Apps Environment."
      }
    },
    "internal": {
      "type": "bool",
      "defaultValue": false,
      "metadata": {
        "description": "Specifies whether the environment only has an internal load balancer. These environments do not have a public static IP resource. They must provide infrastructureSubnetId if enabling this property"
      }
    },
    "dockerBridgeCidr": {
      "type": "string",
      "defaultValue": "10.2.0.1/16",
      "metadata": {
        "description": "Specifies the IP range in CIDR notation assigned to the Docker bridge, network. Must not overlap with any other provided IP ranges."
      }
    },
    "platformReservedCidr": {
      "type": "string",
      "defaultValue": "10.1.0.0/16",
      "metadata": {
        "description": "Specifies the IP range in CIDR notation that can be reserved for environment infrastructure IP addresses. Must not overlap with any other provided IP ranges."
      }
    },
    "platformReservedDnsIP": {
      "type": "string",
      "defaultValue": "10.1.0.2",
      "metadata": {
        "description": "Specifies an IP address from the IP range defined by platformReservedCidr that will be reserved for the internal DNS server."
      }
    },
    "zoneRedundant": {
      "type": "bool",
      "defaultValue": true,
      "metadata": {
        "description": "Specifies whether the Azure Container Apps environment should be zone-redundant."
      }
    },
    "logAnalyticsWorkspaceName": {
      "type": "string",
      "defaultValue": "[if(equals(parameters('letterCaseType'), 'UpperCamelCase'), format('{0}{1}Workspace', toUpper(first(parameters('prefix'))), toLower(substring(parameters('prefix'), 1, sub(length(parameters('prefix')), 1)))), if(equals(parameters('letterCaseType'), 'CamelCase'), format('{0}Workspace', toLower(parameters('prefix'))), format('{0}-workspace', toLower(parameters('prefix')))))]",
      "metadata": {
        "description": "Specifies the name of the Log Analytics workspace."
      }
    },
    "logAnalyticsRetentionInDays": {
      "type": "int",
      "defaultValue": 30,
      "metadata": {
        "description": "Specifies the workspace data retention in days. -1 means Unlimited retention for the Unlimited Sku. 730 days is the maximum allowed for all other Skus."
      }
    },
    "logAnalyticsSku": {
      "type": "string",
      "defaultValue": "PerNode",
      "allowedValues": [
        "Free",
        "Standalone",
        "PerNode",
        "PerGB2018"
      ],
      "metadata": {
        "description": "Specifies the service tier of the workspace: Free, Standalone, PerNode, Per-GB."
      }
    },
    "virtualNetworkName": {
      "type": "string",
      "defaultValue": "[if(equals(parameters('letterCaseType'), 'UpperCamelCase'), format('{0}{1}Vnet', toUpper(first(parameters('prefix'))), toLower(substring(parameters('prefix'), 1, sub(length(parameters('prefix')), 1)))), if(equals(parameters('letterCaseType'), 'CamelCase'), format('{0}Vnet', toLower(parameters('prefix'))), format('{0}-vnet', toLower(parameters('prefix')))))]",
      "metadata": {
        "description": "Specifies the name of the virtual network."
      }
    },
    "virtualNetworkAddressPrefixes": {
      "type": "string",
      "defaultValue": "10.0.0.0/8",
      "metadata": {
        "description": "Specifies the address prefixes of the virtual network."
      }
    },
    "infrastructureSubnetName": {
      "type": "string",
      "defaultValue": "InfrastructureSubnet",
      "metadata": {
        "description": "Specifies the name of a subnet for the Azure Container Apps environment infrastructure components. This subnet must be in the same VNET as the subnet defined in runtimeSubnetId. Must not overlap with any other provided IP ranges."
      }
    },
    "infrastructureSubnetAddressPrefix": {
      "type": "string",
      "defaultValue": "10.0.0.0/21",
      "metadata": {
        "description": "Specifies the address prefix of a subnet for the Azure Container Apps environment infrastructure components. This subnet must be in the same VNET as the subnet defined in runtimeSubnetId. Must not overlap with any other provided IP ranges."
      }
    },
    "privateLinkServiceSubnetName": {
      "type": "string",
      "defaultValue": "PrivateSubnet",
      "metadata": {
        "description": "Specifies the name of the subnet hosting the worker nodes of the user agent pool of the AKS cluster."
      }
    },
    "privateLinkServiceSubnetAddressPrefix": {
      "type": "string",
      "defaultValue": "10.0.16.0/21",
      "metadata": {
        "description": "Specifies the address prefix of the subnet hosting the worker nodes of the user agent pool of the AKS cluster."
      }
    },
    "serviceBusNamespace": {
      "type": "string",
      "defaultValue": "[if(equals(parameters('letterCaseType'), 'UpperCamelCase'), format('{0}{1}ServiceBus', toUpper(first(parameters('prefix'))), toLower(substring(parameters('prefix'), 1, sub(length(parameters('prefix')), 1)))), if(equals(parameters('letterCaseType'), 'CamelCase'), format('{0}ServiceBus', toLower(parameters('prefix'))), format('{0}-servicebus', toLower(parameters('prefix')))))]",
      "metadata": {
        "description": "Specifies the name of the Service Bus namespace."
      }
    },
    "serviceBusZoneRedundant": {
      "type": "bool",
      "defaultValue": true,
      "metadata": {
        "description": "Enabling this property creates a Premium Service Bus Namespace in regions supported availability zones."
      }
    },
    "serviceBusSkuName": {
      "type": "string",
      "defaultValue": "Premium",
      "allowedValues": [
        "Basic",
        "Premium",
        "Standard"
      ],
      "metadata": {
        "description": "Specifies the name of Service Bus namespace SKU."
      }
    },
    "serviceBusCapacity": {
      "type": "int",
      "defaultValue": 1,
      "metadata": {
        "description": "Specifies the messaging units for the Service Bus namespace. For Premium tier, capacity are 1,2 and 4."
      }
    },
    "serviceBusQueueNames": {
      "type": "array",
      "defaultValue": [
        "parameters",
        "results"
      ],
      "metadata": {
        "description": "Specifies the name of the Service Bus queue."
      }
    },
    "serviceBusQueueLockDuration": {
      "type": "string",
      "defaultValue": "PT5M",
      "metadata": {
        "description": "Specifies the lock duration of the queue."
      }
    },
    "serviceBusQueueMaxDeliveryCount": {
      "type": "int",
      "defaultValue": 10,
      "metadata": {
        "description": "Specifies the maximum delivery count of the queue."
      }
    },
    "serviceBusQueueRequiresDuplicateDetection": {
      "type": "bool",
      "defaultValue": false,
      "metadata": {
        "description": "Specifies whether duplication is enabled on the queue."
      }
    },
    "serviceBusQueueRequiresSession": {
      "type": "bool",
      "defaultValue": false,
      "metadata": {
        "description": "Specifies whether session is enabled on the queue."
      }
    },
    "serviceBusQueueDeadLetteringOnMessageExpiration": {
      "type": "bool",
      "defaultValue": false,
      "metadata": {
        "description": "Specifies whether dead lettering is enabled on the queue."
      }
    },
    "serviceBusQueueDuplicateDetectionHistoryTimeWindow": {
      "type": "string",
      "defaultValue": "PT10M",
      "metadata": {
        "description": "Specifies the duplicate detection history time of the queue."
      }
    },
    "serviceBusNamespacePrivateEndpointName": {
      "type": "string",
      "defaultValue": "[if(equals(parameters('letterCaseType'), 'UpperCamelCase'), format('{0}{1}ServiceBusNamespacePrivateEndpoint', toUpper(first(parameters('prefix'))), toLower(substring(parameters('prefix'), 1, sub(length(parameters('prefix')), 1)))), if(equals(parameters('letterCaseType'), 'CamelCase'), format('{0}ServiceBusNamespacePrivateEndpoint', toLower(parameters('prefix'))), format('{0}-service-bus-namespace-private-endpoint', toLower(parameters('prefix')))))]",
      "metadata": {
        "description": "Specifies the name of the private link to the storage account."
      }
    },
    "managedIdentityName": {
      "type": "string",
      "defaultValue": "[if(equals(parameters('letterCaseType'), 'UpperCamelCase'), format('{0}{1}JobManagedIdentity', toUpper(first(parameters('prefix'))), toLower(substring(parameters('prefix'), 1, sub(length(parameters('prefix')), 1)))), if(equals(parameters('letterCaseType'), 'CamelCase'), format('{0}JobManagedIdentity', toLower(parameters('prefix'))), format('{0}-job-managed-identity', toLower(parameters('prefix')))))]",
      "metadata": {
        "description": "Specifies the name of the user-defined managed identity."
      }
    },
    "acrName": {
      "type": "string",
      "defaultValue": "[if(equals(parameters('letterCaseType'), 'UpperCamelCase'), format('{0}{1}Acr', toUpper(first(parameters('prefix'))), toLower(substring(parameters('prefix'), 1, sub(length(parameters('prefix')), 1)))), if(equals(parameters('letterCaseType'), 'CamelCase'), format('{0}Acr', toLower(parameters('prefix'))), format('{0}-acr', toLower(parameters('prefix')))))]",
      "maxLength": 50,
      "minLength": 5,
      "metadata": {
        "description": "Specifies the name of the Azure Container Registry"
      }
    },
    "acrAdminUserEnabled": {
      "type": "bool",
      "defaultValue": false,
      "metadata": {
        "description": "Enable admin user that have push / pull permission to the registry."
      }
    },
    "acrPrivateEndpointName": {
      "type": "string",
      "defaultValue": "[if(equals(parameters('letterCaseType'), 'UpperCamelCase'), format('{0}{1}AcrPrivateEndpoint', toUpper(first(parameters('prefix'))), toLower(substring(parameters('prefix'), 1, sub(length(parameters('prefix')), 1)))), if(equals(parameters('letterCaseType'), 'CamelCase'), format('{0}AcrPrivateEndpoint', toLower(parameters('prefix'))), format('{0}-acr-private-endpoint', toLower(parameters('prefix')))))]",
      "metadata": {
        "description": "Specifies the name of the private link to the Azure Container Registry."
      }
    },
    "acrSkuName": {
      "type": "string",
      "defaultValue": "Premium",
      "allowedValues": [
        "Basic",
        "Standard",
        "Premium"
      ],
      "metadata": {
        "description": "Specifies the SKU name of the Azure Container Registry."
      }
    }
  },
  "resources": [
    {
      "type": "Microsoft.Resources/deployments",
      "apiVersion": "2022-09-01",
      "name": "workspace",
      "properties": {
        "expressionEvaluationOptions": {
          "scope": "inner"
        },
        "mode": "Incremental",
        "parameters": {
          "name": {
            "value": "[parameters('logAnalyticsWorkspaceName')]"
          },
          "sku": {
            "value": "[parameters('logAnalyticsSku')]"
          },
          "retentionInDays": {
            "value": "[parameters('logAnalyticsRetentionInDays')]"
          },
          "location": {
            "value": "[parameters('location')]"
          },
          "tags": {
            "value": "[parameters('tags')]"
          }
        },
        "template": {
          "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
          "contentVersion": "1.0.0.0",
          "metadata": {
            "_generator": {
              "name": "bicep",
              "version": "0.18.4.5664",
              "templateHash": "1345435483846805772"
            }
          },
          "parameters": {
            "name": {
              "type": "string",
              "metadata": {
                "description": "Specifies the name of the Log Analytics workspace."
              }
            },
            "sku": {
              "type": "string",
              "defaultValue": "PerNode",
              "allowedValues": [
                "Free",
                "Standalone",
                "PerNode",
                "PerGB2018"
              ],
              "metadata": {
                "description": "Specifies the service tier of the workspace: Free, Standalone, PerNode, Per-GB."
              }
            },
            "retentionInDays": {
              "type": "int",
              "defaultValue": 60,
              "metadata": {
                "description": "Specifies the workspace data retention in days. -1 means Unlimited retention for the Unlimited Sku. 730 days is the maximum allowed for all other Skus."
              }
            },
            "location": {
              "type": "string",
              "defaultValue": "[resourceGroup().location]",
              "metadata": {
                "description": "Specifies the location."
              }
            },
            "tags": {
              "type": "object",
              "metadata": {
                "description": "Specifies the resource tags."
              }
            }
          },
          "resources": [
            {
              "type": "Microsoft.OperationalInsights/workspaces",
              "apiVersion": "2021-12-01-preview",
              "name": "[parameters('name')]",
              "tags": "[parameters('tags')]",
              "location": "[parameters('location')]",
              "properties": {
                "sku": {
                  "name": "[parameters('sku')]"
                },
                "retentionInDays": "[parameters('retentionInDays')]"
              }
            }
          ],
          "outputs": {
            "id": {
              "type": "string",
              "value": "[resourceId('Microsoft.OperationalInsights/workspaces', parameters('name'))]"
            },
            "name": {
              "type": "string",
              "value": "[parameters('name')]"
            },
            "customerId": {
              "type": "string",
              "value": "[reference(resourceId('Microsoft.OperationalInsights/workspaces', parameters('name')), '2021-12-01-preview').customerId]"
            }
          }
        }
      }
    },
    {
      "type": "Microsoft.Resources/deployments",
      "apiVersion": "2022-09-01",
      "name": "namespace",
      "properties": {
        "expressionEvaluationOptions": {
          "scope": "inner"
        },
        "mode": "Incremental",
        "parameters": {
          "name": {
            "value": "[parameters('serviceBusNamespace')]"
          },
          "location": {
            "value": "[parameters('location')]"
          },
          "tags": {
            "value": "[parameters('tags')]"
          },
          "zoneRedundant": {
            "value": "[parameters('serviceBusZoneRedundant')]"
          },
          "skuName": {
            "value": "[parameters('serviceBusSkuName')]"
          },
          "capacity": {
            "value": "[parameters('serviceBusCapacity')]"
          },
          "queueNames": {
            "value": "[parameters('serviceBusQueueNames')]"
          },
          "lockDuration": {
            "value": "[parameters('serviceBusQueueLockDuration')]"
          },
          "maxDeliveryCount": {
            "value": "[parameters('serviceBusQueueMaxDeliveryCount')]"
          },
          "requiresDuplicateDetection": {
            "value": "[parameters('serviceBusQueueRequiresDuplicateDetection')]"
          },
          "requiresSession": {
            "value": "[parameters('serviceBusQueueRequiresSession')]"
          },
          "deadLetteringOnMessageExpiration": {
            "value": "[parameters('serviceBusQueueDeadLetteringOnMessageExpiration')]"
          },
          "duplicateDetectionHistoryTimeWindow": {
            "value": "[parameters('serviceBusQueueDuplicateDetectionHistoryTimeWindow')]"
          },
          "workspaceId": {
            "value": "[reference(resourceId('Microsoft.Resources/deployments', 'workspace'), '2022-09-01').outputs.id.value]"
          }
        },
        "template": {
          "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
          "contentVersion": "1.0.0.0",
          "metadata": {
            "_generator": {
              "name": "bicep",
              "version": "0.18.4.5664",
              "templateHash": "6642034885011448787"
            }
          },
          "parameters": {
            "name": {
              "type": "string",
              "metadata": {
                "description": "Specifies the name of the Service Bus namespace."
              }
            },
            "zoneRedundant": {
              "type": "bool",
              "defaultValue": true,
              "metadata": {
                "description": "Enabling this property creates a Premium Service Bus Namespace in regions supported availability zones."
              }
            },
            "skuName": {
              "type": "string",
              "defaultValue": "Standard",
              "allowedValues": [
                "Basic",
                "Premium",
                "Standard"
              ],
              "metadata": {
                "description": "Specifies the name of Service Bus namespace SKU."
              }
            },
            "capacity": {
              "type": "int",
              "defaultValue": 1,
              "metadata": {
                "description": "Specifies the messaging units for the Service Bus namespace. For Premium tier, capacity are 1,2 and 4."
              }
            },
            "queueNames": {
              "type": "array",
              "defaultValue": [],
              "metadata": {
                "description": "Specifies the name of the Service Bus queue."
              }
            },
            "lockDuration": {
              "type": "string",
              "defaultValue": "PT5M",
              "metadata": {
                "description": "Specifies the lock duration of the queue."
              }
            },
            "maxDeliveryCount": {
              "type": "int",
              "defaultValue": 10,
              "metadata": {
                "description": "Specifies the maximum delivery count of the queue."
              }
            },
            "requiresDuplicateDetection": {
              "type": "bool",
              "defaultValue": false,
              "metadata": {
                "description": "Specifies whether duplication is enabled on the queue."
              }
            },
            "requiresSession": {
              "type": "bool",
              "defaultValue": false,
              "metadata": {
                "description": "Specifies whether session is enabled on the queue."
              }
            },
            "deadLetteringOnMessageExpiration": {
              "type": "bool",
              "defaultValue": false,
              "metadata": {
                "description": "Specifies whether dead lettering is enabled on the queue."
              }
            },
            "duplicateDetectionHistoryTimeWindow": {
              "type": "string",
              "defaultValue": "PT10M",
              "metadata": {
                "description": "Specifies the duplicate detection history time of the queue."
              }
            },
            "workspaceId": {
              "type": "string",
              "metadata": {
                "description": "Specifies the resource id of the Log Analytics workspace."
              }
            },
            "retentionInDays": {
              "type": "int",
              "defaultValue": 60,
              "metadata": {
                "description": "Specifies the workspace data retention in days."
              }
            },
            "location": {
              "type": "string",
              "defaultValue": "[resourceGroup().location]",
              "metadata": {
                "description": "Specifies the location."
              }
            },
            "tags": {
              "type": "object",
              "metadata": {
                "description": "Specifies the resource tags."
              }
            }
          },
          "variables": {
            "copy": [
              {
                "name": "logs",
                "count": "[length(variables('logCategories'))]",
                "input": {
                  "category": "[variables('logCategories')[copyIndex('logs')]]",
                  "enabled": true,
                  "retentionPolicy": {
                    "enabled": true,
                    "days": "[parameters('retentionInDays')]"
                  }
                }
              },
              {
                "name": "metrics",
                "count": "[length(variables('metricCategories'))]",
                "input": {
                  "category": "[variables('metricCategories')[copyIndex('metrics')]]",
                  "enabled": true,
                  "retentionPolicy": {
                    "enabled": true,
                    "days": "[parameters('retentionInDays')]"
                  }
                }
              }
            ],
            "diagnosticSettingsName": "diagnosticSettings",
            "logCategories": [
              "OperationalLogs",
              "VNetAndIPFilteringLogs",
              "RuntimeAuditLogs",
              "ApplicationMetricsLogs"
            ],
            "metricCategories": [
              "AllMetrics"
            ],
            "serviceBusEndpoint": "[format('{0}/AuthorizationRules/RootManageSharedAccessKey', resourceId('Microsoft.ServiceBus/namespaces', parameters('name')))]"
          },
          "resources": [
            {
              "type": "Microsoft.ServiceBus/namespaces",
              "apiVersion": "2022-10-01-preview",
              "name": "[parameters('name')]",
              "location": "[parameters('location')]",
              "tags": "[parameters('tags')]",
              "sku": {
                "name": "[parameters('skuName')]",
                "capacity": "[parameters('capacity')]"
              },
              "properties": {
                "zoneRedundant": "[if(equals(parameters('skuName'), 'Premium'), parameters('zoneRedundant'), false())]"
              }
            },
            {
              "copy": {
                "name": "queue",
                "count": "[length(parameters('queueNames'))]"
              },
              "type": "Microsoft.ServiceBus/namespaces/queues",
              "apiVersion": "2022-10-01-preview",
              "name": "[format('{0}/{1}', parameters('name'), parameters('queueNames')[copyIndex()])]",
              "properties": {
                "lockDuration": "[parameters('lockDuration')]",
                "maxSizeInMegabytes": 1024,
                "requiresDuplicateDetection": "[parameters('requiresDuplicateDetection')]",
                "requiresSession": "[parameters('requiresSession')]",
                "deadLetteringOnMessageExpiration": "[parameters('deadLetteringOnMessageExpiration')]",
                "duplicateDetectionHistoryTimeWindow": "[parameters('duplicateDetectionHistoryTimeWindow')]",
                "maxDeliveryCount": "[parameters('maxDeliveryCount')]"
              },
              "dependsOn": [
                "[resourceId('Microsoft.ServiceBus/namespaces', parameters('name'))]"
              ]
            },
            {
              "type": "Microsoft.Insights/diagnosticSettings",
              "apiVersion": "2021-05-01-preview",
              "scope": "[format('Microsoft.ServiceBus/namespaces/{0}', parameters('name'))]",
              "name": "[variables('diagnosticSettingsName')]",
              "properties": {
                "workspaceId": "[parameters('workspaceId')]",
                "logs": "[variables('logs')]",
                "metrics": "[variables('metrics')]"
              },
              "dependsOn": [
                "[resourceId('Microsoft.ServiceBus/namespaces', parameters('name'))]"
              ]
            }
          ],
          "outputs": {
            "id": {
              "type": "string",
              "value": "[resourceId('Microsoft.ServiceBus/namespaces', parameters('name'))]"
            },
            "name": {
              "type": "string",
              "value": "[parameters('name')]"
            },
            "connectionString": {
              "type": "string",
              "value": "[listKeys(variables('serviceBusEndpoint'), '2022-10-01-preview').primaryConnectionString]"
            },
            "queues": {
              "type": "array",
              "copy": {
                "count": "[length(parameters('queueNames'))]",
                "input": {
                  "name": "[parameters('name')]",
                  "id": "[resourceId('Microsoft.ServiceBus/namespaces/queues', parameters('name'), parameters('queueNames')[copyIndex()])]"
                }
              }
            }
          }
        }
      },
      "dependsOn": [
        "[resourceId('Microsoft.Resources/deployments', 'workspace')]"
      ]
    },
    {
      "type": "Microsoft.Resources/deployments",
      "apiVersion": "2022-09-01",
      "name": "network",
      "properties": {
        "expressionEvaluationOptions": {
          "scope": "inner"
        },
        "mode": "Incremental",
        "parameters": {
          "name": {
            "value": "[parameters('virtualNetworkName')]"
          },
          "location": {
            "value": "[parameters('location')]"
          },
          "tags": {
            "value": "[parameters('tags')]"
          },
          "addressPrefixes": {
            "value": "[parameters('virtualNetworkAddressPrefixes')]"
          },
          "infrastructureSubnetName": {
            "value": "[parameters('infrastructureSubnetName')]"
          },
          "infrastructureSubnetAddressPrefix": {
            "value": "[parameters('infrastructureSubnetAddressPrefix')]"
          },
          "privateLinkServiceSubnetName": {
            "value": "[parameters('privateLinkServiceSubnetName')]"
          },
          "privateLinkServiceSubnetAddressPrefix": {
            "value": "[parameters('privateLinkServiceSubnetAddressPrefix')]"
          },
          "workspaceId": {
            "value": "[reference(resourceId('Microsoft.Resources/deployments', 'workspace'), '2022-09-01').outputs.id.value]"
          },
          "serviceBusNamespacePrivateEndpointEnabled": {
            "value": "[equals(parameters('serviceBusSkuName'), 'Premium')]"
          },
          "serviceBusNamespacePrivateEndpointName": {
            "value": "[parameters('serviceBusNamespacePrivateEndpointName')]"
          },
          "serviceBusNamespaceId": {
            "value": "[reference(resourceId('Microsoft.Resources/deployments', 'namespace'), '2022-09-01').outputs.id.value]"
          },
          "acrPrivateEndpointEnabled": {
            "value": "[equals(parameters('acrSkuName'), 'Premium')]"
          },
          "acrPrivateEndpointName": {
            "value": "[parameters('acrPrivateEndpointName')]"
          },
          "acrId": {
            "value": "[reference(resourceId('Microsoft.Resources/deployments', 'containerRegistry'), '2022-09-01').outputs.id.value]"
          }
        },
        "template": {
          "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
          "contentVersion": "1.0.0.0",
          "metadata": {
            "_generator": {
              "name": "bicep",
              "version": "0.18.4.5664",
              "templateHash": "7146871086920983355"
            }
          },
          "parameters": {
            "name": {
              "type": "string",
              "metadata": {
                "description": "Specifies the name of the Azure Container Apps Environment."
              }
            },
            "addressPrefixes": {
              "type": "string",
              "defaultValue": "10.0.0.0/8",
              "metadata": {
                "description": "Specifies the address prefixes of the virtual network."
              }
            },
            "infrastructureSubnetName": {
              "type": "string",
              "defaultValue": "InfrastructureSubnet",
              "metadata": {
                "description": "Specifies the name of a subnet for the Azure Container Apps environment infrastructure components. This subnet must be in the same VNET as the subnet defined in runtimeSubnetId. Must not overlap with any other provided IP ranges."
              }
            },
            "infrastructureSubnetAddressPrefix": {
              "type": "string",
              "defaultValue": "10.0.0.0/21",
              "metadata": {
                "description": "Specifies the address prefix of a subnet for the Azure Container Apps environment infrastructure components. This subnet must be in the same VNET as the subnet defined in runtimeSubnetId. Must not overlap with any other provided IP ranges."
              }
            },
            "privateLinkServiceSubnetName": {
              "type": "string",
              "defaultValue": "PlsSubnet",
              "metadata": {
                "description": "Specifies the name of the subnet hosting the worker nodes of the user agent pool of the AKS cluster."
              }
            },
            "privateLinkServiceSubnetAddressPrefix": {
              "type": "string",
              "defaultValue": "10.0.16.0/21",
              "metadata": {
                "description": "Specifies the address prefix of the subnet hosting the worker nodes of the user agent pool of the AKS cluster."
              }
            },
            "serviceBusNamespacePrivateEndpointEnabled": {
              "type": "bool",
              "defaultValue": false,
              "metadata": {
                "description": "Specifies whether enabling the private link to the Azure Service Bus namespace."
              }
            },
            "serviceBusNamespacePrivateEndpointName": {
              "type": "string",
              "defaultValue": "ServiceBusNamespacePrivateEndpoint",
              "metadata": {
                "description": "Specifies the name of the private link to the Azure Service Bus namespace."
              }
            },
            "serviceBusNamespaceId": {
              "type": "string",
              "metadata": {
                "description": "Specifies the resource id of the Azure Service Bus namespace."
              }
            },
            "acrPrivateEndpointEnabled": {
              "type": "bool",
              "defaultValue": false,
              "metadata": {
                "description": "Specifies whether enabling the private link to the Azure Container Registry."
              }
            },
            "acrPrivateEndpointName": {
              "type": "string",
              "defaultValue": "AcrPrivateEndpoint",
              "metadata": {
                "description": "Specifies the name of the private link to the Azure Container Registry."
              }
            },
            "acrId": {
              "type": "string",
              "metadata": {
                "description": "Specifies the resource id of the Azure Container Registry."
              }
            },
            "workspaceId": {
              "type": "string",
              "metadata": {
                "description": "Specifies the resource id of the Log Analytics workspace."
              }
            },
            "retentionInDays": {
              "type": "int",
              "defaultValue": 60,
              "metadata": {
                "description": "Specifies the workspace data retention in days."
              }
            },
            "location": {
              "type": "string",
              "defaultValue": "[resourceGroup().location]",
              "metadata": {
                "description": "Specifies the location."
              }
            },
            "tags": {
              "type": "object",
              "metadata": {
                "description": "Specifies the resource tags."
              }
            }
          },
          "variables": {
            "copy": [
              {
                "name": "vnetLogs",
                "count": "[length(variables('vnetLogCategories'))]",
                "input": {
                  "category": "[variables('vnetLogCategories')[copyIndex('vnetLogs')]]",
                  "enabled": true,
                  "retentionPolicy": {
                    "enabled": true,
                    "days": "[parameters('retentionInDays')]"
                  }
                }
              },
              {
                "name": "vnetMetrics",
                "count": "[length(variables('vnetMetricCategories'))]",
                "input": {
                  "category": "[variables('vnetMetricCategories')[copyIndex('vnetMetrics')]]",
                  "enabled": true,
                  "retentionPolicy": {
                    "enabled": true,
                    "days": "[parameters('retentionInDays')]"
                  }
                }
              }
            ],
            "diagnosticSettingsName": "diagnosticSettings",
            "vnetLogCategories": [
              "VMProtectionAlerts"
            ],
            "vnetMetricCategories": [
              "AllMetrics"
            ]
          },
          "resources": [
            {
              "type": "Microsoft.Network/virtualNetworks",
              "apiVersion": "2022-07-01",
              "name": "[parameters('name')]",
              "location": "[parameters('location')]",
              "tags": "[parameters('tags')]",
              "properties": {
                "addressSpace": {
                  "addressPrefixes": [
                    "[parameters('addressPrefixes')]"
                  ]
                },
                "subnets": [
                  {
                    "name": "[parameters('infrastructureSubnetName')]",
                    "properties": {
                      "addressPrefix": "[parameters('infrastructureSubnetAddressPrefix')]",
                      "delegations": [],
                      "privateEndpointNetworkPolicies": "Disabled",
                      "privateLinkServiceNetworkPolicies": "Enabled"
                    }
                  },
                  {
                    "name": "[parameters('privateLinkServiceSubnetName')]",
                    "properties": {
                      "addressPrefix": "[parameters('privateLinkServiceSubnetAddressPrefix')]",
                      "delegations": [],
                      "privateEndpointNetworkPolicies": "Disabled",
                      "privateLinkServiceNetworkPolicies": "Disabled"
                    }
                  }
                ],
                "virtualNetworkPeerings": [],
                "enableDdosProtection": false
              }
            },
            {
              "condition": "[parameters('serviceBusNamespacePrivateEndpointEnabled')]",
              "type": "Microsoft.Network/privateDnsZones",
              "apiVersion": "2020-06-01",
              "name": "[format('privatelink.{0}', if(equals(toLower(environment().name), 'azureusgovernment'), 'servicebus.usgovcloudapi.net', 'servicebus.windows.net'))]",
              "location": "global",
              "tags": "[parameters('tags')]"
            },
            {
              "condition": "[parameters('acrPrivateEndpointEnabled')]",
              "type": "Microsoft.Network/privateDnsZones",
              "apiVersion": "2020-06-01",
              "name": "[format('privatelink.{0}', if(equals(toLower(environment().name), 'azureusgovernment'), 'azurecr.us', 'azurecr.io'))]",
              "location": "global",
              "tags": "[parameters('tags')]"
            },
            {
              "condition": "[parameters('serviceBusNamespacePrivateEndpointEnabled')]",
              "type": "Microsoft.Network/privateDnsZones/virtualNetworkLinks",
              "apiVersion": "2020-06-01",
              "name": "[format('{0}/{1}', format('privatelink.{0}', if(equals(toLower(environment().name), 'azureusgovernment'), 'servicebus.usgovcloudapi.net', 'servicebus.windows.net')), format('link_to_{0}', toLower(parameters('name'))))]",
              "location": "global",
              "properties": {
                "registrationEnabled": false,
                "virtualNetwork": {
                  "id": "[resourceId('Microsoft.Network/virtualNetworks', parameters('name'))]"
                }
              },
              "dependsOn": [
                "[resourceId('Microsoft.Network/privateDnsZones', format('privatelink.{0}', if(equals(toLower(environment().name), 'azureusgovernment'), 'servicebus.usgovcloudapi.net', 'servicebus.windows.net')))]",
                "[resourceId('Microsoft.Network/virtualNetworks', parameters('name'))]"
              ]
            },
            {
              "condition": "[parameters('acrPrivateEndpointEnabled')]",
              "type": "Microsoft.Network/privateDnsZones/virtualNetworkLinks",
              "apiVersion": "2020-06-01",
              "name": "[format('{0}/{1}', format('privatelink.{0}', if(equals(toLower(environment().name), 'azureusgovernment'), 'azurecr.us', 'azurecr.io')), format('link_to_{0}', toLower(parameters('name'))))]",
              "location": "global",
              "properties": {
                "registrationEnabled": false,
                "virtualNetwork": {
                  "id": "[resourceId('Microsoft.Network/virtualNetworks', parameters('name'))]"
                }
              },
              "dependsOn": [
                "[resourceId('Microsoft.Network/privateDnsZones', format('privatelink.{0}', if(equals(toLower(environment().name), 'azureusgovernment'), 'azurecr.us', 'azurecr.io')))]",
                "[resourceId('Microsoft.Network/virtualNetworks', parameters('name'))]"
              ]
            },
            {
              "condition": "[parameters('serviceBusNamespacePrivateEndpointEnabled')]",
              "type": "Microsoft.Network/privateEndpoints",
              "apiVersion": "2021-08-01",
              "name": "[parameters('serviceBusNamespacePrivateEndpointName')]",
              "location": "[parameters('location')]",
              "tags": "[parameters('tags')]",
              "properties": {
                "privateLinkServiceConnections": [
                  {
                    "name": "[parameters('serviceBusNamespacePrivateEndpointName')]",
                    "properties": {
                      "privateLinkServiceId": "[parameters('serviceBusNamespaceId')]",
                      "groupIds": [
                        "namespace"
                      ]
                    }
                  }
                ],
                "subnet": {
                  "id": "[format('{0}/subnets/{1}', resourceId('Microsoft.Network/virtualNetworks', parameters('name')), parameters('privateLinkServiceSubnetName'))]"
                }
              },
              "dependsOn": [
                "[resourceId('Microsoft.Network/virtualNetworks', parameters('name'))]"
              ]
            },
            {
              "condition": "[parameters('serviceBusNamespacePrivateEndpointEnabled')]",
              "type": "Microsoft.Network/privateEndpoints/privateDnsZoneGroups",
              "apiVersion": "2021-08-01",
              "name": "[format('{0}/{1}', parameters('serviceBusNamespacePrivateEndpointName'), 'PrivateDnsZoneGroupName')]",
              "properties": {
                "privateDnsZoneConfigs": [
                  {
                    "name": "dnsConfig",
                    "properties": {
                      "privateDnsZoneId": "[resourceId('Microsoft.Network/privateDnsZones', format('privatelink.{0}', if(equals(toLower(environment().name), 'azureusgovernment'), 'servicebus.usgovcloudapi.net', 'servicebus.windows.net')))]"
                    }
                  }
                ]
              },
              "dependsOn": [
                "[resourceId('Microsoft.Network/privateEndpoints', parameters('serviceBusNamespacePrivateEndpointName'))]",
                "[resourceId('Microsoft.Network/privateDnsZones', format('privatelink.{0}', if(equals(toLower(environment().name), 'azureusgovernment'), 'servicebus.usgovcloudapi.net', 'servicebus.windows.net')))]"
              ]
            },
            {
              "condition": "[parameters('acrPrivateEndpointEnabled')]",
              "type": "Microsoft.Network/privateEndpoints",
              "apiVersion": "2022-09-01",
              "name": "[parameters('acrPrivateEndpointName')]",
              "location": "[parameters('location')]",
              "tags": "[parameters('tags')]",
              "properties": {
                "privateLinkServiceConnections": [
                  {
                    "name": "[parameters('acrPrivateEndpointName')]",
                    "properties": {
                      "privateLinkServiceId": "[parameters('acrId')]",
                      "groupIds": [
                        "registry"
                      ]
                    }
                  }
                ],
                "subnet": {
                  "id": "[format('{0}/subnets/{1}', resourceId('Microsoft.Network/virtualNetworks', parameters('name')), parameters('privateLinkServiceSubnetName'))]"
                }
              },
              "dependsOn": [
                "[resourceId('Microsoft.Network/virtualNetworks', parameters('name'))]"
              ]
            },
            {
              "condition": "[parameters('acrPrivateEndpointEnabled')]",
              "type": "Microsoft.Network/privateEndpoints/privateDnsZoneGroups",
              "apiVersion": "2022-09-01",
              "name": "[format('{0}/{1}', parameters('acrPrivateEndpointName'), 'acrPrivateDnsZoneGroup')]",
              "properties": {
                "privateDnsZoneConfigs": [
                  {
                    "name": "dnsConfig",
                    "properties": {
                      "privateDnsZoneId": "[resourceId('Microsoft.Network/privateDnsZones', format('privatelink.{0}', if(equals(toLower(environment().name), 'azureusgovernment'), 'azurecr.us', 'azurecr.io')))]"
                    }
                  }
                ]
              },
              "dependsOn": [
                "[resourceId('Microsoft.Network/privateDnsZones', format('privatelink.{0}', if(equals(toLower(environment().name), 'azureusgovernment'), 'azurecr.us', 'azurecr.io')))]",
                "[resourceId('Microsoft.Network/privateEndpoints', parameters('acrPrivateEndpointName'))]"
              ]
            },
            {
              "type": "Microsoft.Insights/diagnosticSettings",
              "apiVersion": "2021-05-01-preview",
              "scope": "[format('Microsoft.Network/virtualNetworks/{0}', parameters('name'))]",
              "name": "[variables('diagnosticSettingsName')]",
              "properties": {
                "workspaceId": "[parameters('workspaceId')]",
                "logs": "[variables('vnetLogs')]",
                "metrics": "[variables('vnetMetrics')]"
              },
              "dependsOn": [
                "[resourceId('Microsoft.Network/virtualNetworks', parameters('name'))]"
              ]
            }
          ],
          "outputs": {
            "id": {
              "type": "string",
              "value": "[resourceId('Microsoft.Network/virtualNetworks', parameters('name'))]"
            },
            "name": {
              "type": "string",
              "value": "[parameters('name')]"
            },
            "infrastructureSubnetId": {
              "type": "string",
              "value": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('name'), parameters('infrastructureSubnetName'))]"
            },
            "privateLinkServiceSubnetId": {
              "type": "string",
              "value": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('name'), parameters('privateLinkServiceSubnetName'))]"
            }
          }
        }
      },
      "dependsOn": [
        "[resourceId('Microsoft.Resources/deployments', 'containerRegistry')]",
        "[resourceId('Microsoft.Resources/deployments', 'namespace')]",
        "[resourceId('Microsoft.Resources/deployments', 'workspace')]"
      ]
    },
    {
      "type": "Microsoft.Resources/deployments",
      "apiVersion": "2022-09-01",
      "name": "environment",
      "properties": {
        "expressionEvaluationOptions": {
          "scope": "inner"
        },
        "mode": "Incremental",
        "parameters": {
          "name": {
            "value": "[parameters('containerAppEnvironmentName')]"
          },
          "location": {
            "value": "[parameters('location')]"
          },
          "tags": {
            "value": "[parameters('tags')]"
          },
          "internal": {
            "value": "[parameters('internal')]"
          },
          "dockerBridgeCidr": {
            "value": "[parameters('dockerBridgeCidr')]"
          },
          "platformReservedCidr": {
            "value": "[parameters('platformReservedCidr')]"
          },
          "platformReservedDnsIP": {
            "value": "[parameters('platformReservedDnsIP')]"
          },
          "zoneRedundant": {
            "value": "[parameters('zoneRedundant')]"
          },
          "workspaceName": {
            "value": "[parameters('logAnalyticsWorkspaceName')]"
          },
          "infrastructureSubnetId": {
            "value": "[reference(resourceId('Microsoft.Resources/deployments', 'network'), '2022-09-01').outputs.infrastructureSubnetId.value]"
          }
        },
        "template": {
          "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
          "contentVersion": "1.0.0.0",
          "metadata": {
            "_generator": {
              "name": "bicep",
              "version": "0.18.4.5664",
              "templateHash": "14449268650626830847"
            }
          },
          "parameters": {
            "name": {
              "type": "string",
              "metadata": {
                "description": "Specifies the name of the Azure Container Apps Environment."
              }
            },
            "location": {
              "type": "string",
              "defaultValue": "[resourceGroup().location]",
              "metadata": {
                "description": "Specifies the location."
              }
            },
            "tags": {
              "type": "object",
              "metadata": {
                "description": "Specifies the resource tags."
              }
            },
            "internal": {
              "type": "bool",
              "defaultValue": false,
              "metadata": {
                "description": "Specifies whether the environment only has an internal load balancer. These environments do not have a public static IP resource. They must provide infrastructureSubnetId if enabling this property"
              }
            },
            "dockerBridgeCidr": {
              "type": "string",
              "metadata": {
                "description": "Specifies the IP range in CIDR notation assigned to the Docker bridge, network. Must not overlap with any other provided IP ranges."
              }
            },
            "platformReservedCidr": {
              "type": "string",
              "metadata": {
                "description": "Specifies the IP range in CIDR notation that can be reserved for environment infrastructure IP addresses. Must not overlap with any other provided IP ranges."
              }
            },
            "platformReservedDnsIP": {
              "type": "string",
              "metadata": {
                "description": "Specifies an IP address from the IP range defined by platformReservedCidr that will be reserved for the internal DNS server."
              }
            },
            "zoneRedundant": {
              "type": "bool",
              "defaultValue": true,
              "metadata": {
                "description": "Specifies whether the Azure Container Apps environment should be zone-redundant."
              }
            },
            "infrastructureSubnetId": {
              "type": "string",
              "metadata": {
                "description": "Specifies the resource id of the infrastructure subnet."
              }
            },
            "workspaceName": {
              "type": "string",
              "metadata": {
                "description": "Specifies the name of the Log Analytics workspace."
              }
            },
            "daprAIInstrumentationKey": {
              "type": "string",
              "defaultValue": "",
              "metadata": {
                "description": "Specifies the Azure Monitor instrumentation key used by Dapr to export Service to Service communication telemetry."
              }
            },
            "daprAIConnectionString": {
              "type": "string",
              "defaultValue": "",
              "metadata": {
                "description": "Specifies the configuration of Dapr component."
              }
            },
            "certificatePassword": {
              "type": "securestring",
              "defaultValue": "",
              "metadata": {
                "description": "Specifies the certificate password."
              }
            },
            "certificateValue": {
              "type": "string",
              "defaultValue": "",
              "metadata": {
                "description": "Specifies the PFX or PEM certificate value."
              }
            },
            "dnsSuffix": {
              "type": "string",
              "defaultValue": "",
              "metadata": {
                "description": "Specifies the DNS suffix for the environment domain."
              }
            },
            "workloadProfiles": {
              "type": "array",
              "defaultValue": [],
              "metadata": {
                "description": "Specifies workload profiles configured for the Managed Environment."
              }
            }
          },
          "resources": [
            {
              "type": "Microsoft.App/managedEnvironments",
              "apiVersion": "2023-04-01-preview",
              "name": "[parameters('name')]",
              "location": "[parameters('location')]",
              "tags": "[parameters('tags')]",
              "properties": {
                "customDomainConfiguration": "[if(and(and(empty(parameters('certificatePassword')), empty(parameters('certificateValue'))), empty(parameters('dnsSuffix'))), null(), createObject('certificatePassword', parameters('certificatePassword'), 'certificateValue', parameters('certificateValue'), 'dnsSuffix', parameters('dnsSuffix')))]",
                "daprAIInstrumentationKey": "[parameters('daprAIInstrumentationKey')]",
                "daprAIConnectionString": "[parameters('daprAIConnectionString')]",
                "vnetConfiguration": {
                  "internal": "[parameters('internal')]",
                  "infrastructureSubnetId": "[parameters('infrastructureSubnetId')]",
                  "dockerBridgeCidr": "[parameters('dockerBridgeCidr')]",
                  "platformReservedCidr": "[parameters('platformReservedCidr')]",
                  "platformReservedDnsIP": "[parameters('platformReservedDnsIP')]"
                },
                "appLogsConfiguration": {
                  "destination": "log-analytics",
                  "logAnalyticsConfiguration": {
                    "customerId": "[reference(resourceId('Microsoft.OperationalInsights/workspaces', parameters('workspaceName')), '2021-12-01-preview').customerId]",
                    "sharedKey": "[listKeys(resourceId('Microsoft.OperationalInsights/workspaces', parameters('workspaceName')), '2021-12-01-preview').primarySharedKey]"
                  }
                },
                "zoneRedundant": "[parameters('zoneRedundant')]",
                "workloadProfiles": "[parameters('workloadProfiles')]"
              }
            }
          ],
          "outputs": {
            "id": {
              "type": "string",
              "value": "[resourceId('Microsoft.App/managedEnvironments', parameters('name'))]"
            },
            "name": {
              "type": "string",
              "value": "[parameters('name')]"
            },
            "daprConfiguration": {
              "type": "object",
              "value": "[reference(resourceId('Microsoft.App/managedEnvironments', parameters('name')), '2023-04-01-preview').daprConfiguration]"
            },
            "kedaConfiguration": {
              "type": "object",
              "value": "[reference(resourceId('Microsoft.App/managedEnvironments', parameters('name')), '2023-04-01-preview').kedaConfiguration]"
            },
            "appLogsConfiguration": {
              "type": "object",
              "value": "[reference(resourceId('Microsoft.App/managedEnvironments', parameters('name')), '2023-04-01-preview').appLogsConfiguration]"
            }
          }
        }
      },
      "dependsOn": [
        "[resourceId('Microsoft.Resources/deployments', 'network')]"
      ]
    },
    {
      "type": "Microsoft.Resources/deployments",
      "apiVersion": "2022-09-01",
      "name": "managedIdentity",
      "properties": {
        "expressionEvaluationOptions": {
          "scope": "inner"
        },
        "mode": "Incremental",
        "parameters": {
          "name": {
            "value": "[parameters('managedIdentityName')]"
          },
          "location": {
            "value": "[parameters('location')]"
          },
          "serviceBusNamespace": {
            "value": "[reference(resourceId('Microsoft.Resources/deployments', 'namespace'), '2022-09-01').outputs.name.value]"
          },
          "acrName": {
            "value": "[reference(resourceId('Microsoft.Resources/deployments', 'containerRegistry'), '2022-09-01').outputs.name.value]"
          },
          "tags": {
            "value": "[parameters('tags')]"
          }
        },
        "template": {
          "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
          "contentVersion": "1.0.0.0",
          "metadata": {
            "_generator": {
              "name": "bicep",
              "version": "0.18.4.5664",
              "templateHash": "7072514701931445872"
            }
          },
          "parameters": {
            "name": {
              "type": "string",
              "metadata": {
                "description": "Specifies the name of the user-defined managed identity."
              }
            },
            "serviceBusNamespace": {
              "type": "string",
              "metadata": {
                "description": "Specifies the name of the Service Bus namespace."
              }
            },
            "acrName": {
              "type": "string",
              "metadata": {
                "description": "Specifies the name of the Azure Container Registry"
              }
            },
            "location": {
              "type": "string",
              "defaultValue": "[resourceGroup().location]",
              "metadata": {
                "description": "Specifies the location."
              }
            },
            "tags": {
              "type": "object",
              "metadata": {
                "description": "Specifies the resource tags."
              }
            }
          },
          "variables": {
            "serviceBusDataOwnerRoleDefinitionId": "[resourceId('Microsoft.Authorization/roleDefinitions', '090c5cfd-751d-490a-894a-3ce6f1109419')]",
            "acrPullRoleDefinitionId": "[resourceId('Microsoft.Authorization/roleDefinitions', '7f951dda-4ed3-4680-a7ca-43fe172d538d')]"
          },
          "resources": [
            {
              "type": "Microsoft.ManagedIdentity/userAssignedIdentities",
              "apiVersion": "2023-01-31",
              "name": "[parameters('name')]",
              "location": "[parameters('location')]",
              "tags": "[parameters('tags')]"
            },
            {
              "type": "Microsoft.Authorization/roleAssignments",
              "apiVersion": "2022-04-01",
              "scope": "[format('Microsoft.ServiceBus/namespaces/{0}', parameters('serviceBusNamespace'))]",
              "name": "[guid(resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', parameters('name')), resourceId('Microsoft.ServiceBus/namespaces', parameters('serviceBusNamespace')), variables('serviceBusDataOwnerRoleDefinitionId'))]",
              "properties": {
                "roleDefinitionId": "[variables('serviceBusDataOwnerRoleDefinitionId')]",
                "principalId": "[reference(resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', parameters('name')), '2023-01-31').principalId]",
                "principalType": "ServicePrincipal"
              },
              "dependsOn": [
                "[resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', parameters('name'))]"
              ]
            },
            {
              "type": "Microsoft.Authorization/roleAssignments",
              "apiVersion": "2022-04-01",
              "scope": "[format('Microsoft.ContainerRegistry/registries/{0}', parameters('acrName'))]",
              "name": "[guid(resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', parameters('name')), resourceId('Microsoft.ContainerRegistry/registries', parameters('acrName')), variables('acrPullRoleDefinitionId'))]",
              "properties": {
                "roleDefinitionId": "[variables('acrPullRoleDefinitionId')]",
                "principalId": "[reference(resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', parameters('name')), '2023-01-31').principalId]",
                "principalType": "ServicePrincipal"
              },
              "dependsOn": [
                "[resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', parameters('name'))]"
              ]
            }
          ],
          "outputs": {
            "id": {
              "type": "string",
              "value": "[resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', parameters('name'))]"
            },
            "name": {
              "type": "string",
              "value": "[parameters('name')]"
            },
            "clientId": {
              "type": "string",
              "value": "[reference(resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', parameters('name')), '2023-01-31').clientId]"
            },
            "principalId": {
              "type": "string",
              "value": "[reference(resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', parameters('name')), '2023-01-31').principalId]"
            }
          }
        }
      },
      "dependsOn": [
        "[resourceId('Microsoft.Resources/deployments', 'containerRegistry')]",
        "[resourceId('Microsoft.Resources/deployments', 'namespace')]"
      ]
    },
    {
      "type": "Microsoft.Resources/deployments",
      "apiVersion": "2022-09-01",
      "name": "containerRegistry",
      "properties": {
        "expressionEvaluationOptions": {
          "scope": "inner"
        },
        "mode": "Incremental",
        "parameters": {
          "name": {
            "value": "[parameters('acrName')]"
          },
          "sku": {
            "value": "[parameters('acrSkuName')]"
          },
          "adminUserEnabled": {
            "value": "[parameters('acrAdminUserEnabled')]"
          },
          "workspaceId": {
            "value": "[reference(resourceId('Microsoft.Resources/deployments', 'workspace'), '2022-09-01').outputs.id.value]"
          },
          "retentionInDays": {
            "value": "[parameters('logAnalyticsRetentionInDays')]"
          },
          "location": {
            "value": "[parameters('location')]"
          },
          "tags": {
            "value": "[parameters('tags')]"
          }
        },
        "template": {
          "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
          "contentVersion": "1.0.0.0",
          "metadata": {
            "_generator": {
              "name": "bicep",
              "version": "0.18.4.5664",
              "templateHash": "13018784895517120517"
            }
          },
          "parameters": {
            "name": {
              "type": "string",
              "defaultValue": "[format('acr{0}', uniqueString(resourceGroup().id))]",
              "maxLength": 50,
              "minLength": 5,
              "metadata": {
                "description": "Name of your Azure Container Registry"
              }
            },
            "adminUserEnabled": {
              "type": "bool",
              "defaultValue": false,
              "metadata": {
                "description": "Enable admin user that have push / pull permission to the registry."
              }
            },
            "sku": {
              "type": "string",
              "defaultValue": "Premium",
              "allowedValues": [
                "Basic",
                "Standard",
                "Premium"
              ],
              "metadata": {
                "description": "Tier of your Azure Container Registry."
              }
            },
            "workspaceId": {
              "type": "string",
              "metadata": {
                "description": "Specifies the resource id of the Log Analytics workspace."
              }
            },
            "retentionInDays": {
              "type": "int",
              "defaultValue": 60,
              "metadata": {
                "description": "Specifies the workspace data retention in days."
              }
            },
            "location": {
              "type": "string",
              "defaultValue": "[resourceGroup().location]",
              "metadata": {
                "description": "Specifies the location."
              }
            },
            "tags": {
              "type": "object",
              "metadata": {
                "description": "Specifies the resource tags."
              }
            }
          },
          "variables": {
            "copy": [
              {
                "name": "logs",
                "count": "[length(variables('logCategories'))]",
                "input": {
                  "category": "[variables('logCategories')[copyIndex('logs')]]",
                  "enabled": true,
                  "retentionPolicy": {
                    "enabled": true,
                    "days": "[parameters('retentionInDays')]"
                  }
                }
              },
              {
                "name": "metrics",
                "count": "[length(variables('metricCategories'))]",
                "input": {
                  "category": "[variables('metricCategories')[copyIndex('metrics')]]",
                  "enabled": true,
                  "retentionPolicy": {
                    "enabled": true,
                    "days": "[parameters('retentionInDays')]"
                  }
                }
              }
            ],
            "diagnosticSettingsName": "diagnosticSettings",
            "logCategories": [
              "ContainerRegistryRepositoryEvents",
              "ContainerRegistryLoginEvents"
            ],
            "metricCategories": [
              "AllMetrics"
            ]
          },
          "resources": [
            {
              "type": "Microsoft.ContainerRegistry/registries",
              "apiVersion": "2021-12-01-preview",
              "name": "[parameters('name')]",
              "location": "[parameters('location')]",
              "tags": "[parameters('tags')]",
              "sku": {
                "name": "[parameters('sku')]"
              },
              "properties": {
                "adminUserEnabled": "[parameters('adminUserEnabled')]"
              }
            },
            {
              "type": "Microsoft.Insights/diagnosticSettings",
              "apiVersion": "2021-05-01-preview",
              "scope": "[format('Microsoft.ContainerRegistry/registries/{0}', parameters('name'))]",
              "name": "[variables('diagnosticSettingsName')]",
              "properties": {
                "workspaceId": "[parameters('workspaceId')]",
                "logs": "[variables('logs')]",
                "metrics": "[variables('metrics')]"
              },
              "dependsOn": [
                "[resourceId('Microsoft.ContainerRegistry/registries', parameters('name'))]"
              ]
            }
          ],
          "outputs": {
            "id": {
              "type": "string",
              "value": "[resourceId('Microsoft.ContainerRegistry/registries', parameters('name'))]"
            },
            "name": {
              "type": "string",
              "value": "[parameters('name')]"
            }
          }
        }
      },
      "dependsOn": [
        "[resourceId('Microsoft.Resources/deployments', 'workspace')]"
      ]
    }
  ]
}