Azure / azure-quickstart-templates

Azure Quickstart Templates
https://aka.ms/azqst
MIT License
13.96k stars 16.09k forks source link

Templates with VMs called "MyWindowsVM" not deploying #2894

Closed tomhollander closed 3 years ago

tomhollander commented 7 years ago

Many of the templates include a VM named "MyWindowsVM" (e.g. 201-vm-custom-script-windows) When deploying through the Portal, the following error is displayed upon deploying:

Value 'MyWindowsVM' used in property 'name' of resource 'MyWindowsVM' (microsoft.compute/virtualmachines) is invalid. You may need to edit the template to fix this issue.The resource name 'MyWindowsVM' or a part of the name is a trademarked or reserved word. (Code: ClientSideValidationError)

The template can be deployed if you change the name not to include "Windows".

MCKLMT commented 7 years ago

The fix has been merged. May you close your issue?

Giaco9 commented 7 years ago

Hi everyone, also in this template there is the same problem. The resource type Microsoft.DevTestLab/labs/providers/roleAssignments has name: [concat(parameters('labName'), '/Microsoft.Authorization/', parameters('roleAssignmentGuid'))]. The result is something like: nameLab/Microsoft.Authorization/385d337e-9eaa-42c6-820f-e8413012ae38.

My Additional attempts were:

My main problem is: deploy a template inside a resource group that defines a devtest lab with:

This is my last attempt:

{
  "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "principalId": {
      "type": "string",
      "metadata": {
        "description": "The Object ID of the user, group, or service principal for the role."
      }
    },
    "LabName": {
      "type": "string",
      "metadata": {
        "description": "The name of the new lab instance to be created."
      }
    },
    "labVmShutDownTime": {
      "type": "string",
      "minLength": 4,
      "maxLength": 5,
      "metadata": {
        "description": "The time (relative to timeZoneId) at which the Lab VMs will be automatically shutdown (E.g. 17:30, 20:00, 09:00)."
      }
    },
    "timeZoneId": {
      "type": "string",
      "minLength": 3,
      "metadata": {
        "description": "The Windows time zone id associated with labVmShutDownTime (E.g. UTC, Pacific Standard Time, Central Europe Standard Time)."
      }
    },
     "maxAllowedVmsPerUser": {
      "type": "int",
      "minValue": 0,
      "metadata": {
        "description": "The maximum number of VMs allowed per user."
      }
    },
    "maxAllowedVmsPerLab": {
      "type": "int",
      "minValue": 0,
      "metadata": {
        "description": "The maximum number of VMs allowed per lab."
      }
    },
    "allowedVmSizes": {
      "type": "string",ì
      "minLength": 3,
      "metadata": {
        "description": "A comma-separated list of VM sizes that are allowed in the lab."
      }
    },
    "roleAssignmentGuid": {
      "type": "string",ì
      "metadata": {
        "description": "Guid to use as the name for the role assignment."
      }
    }
  },
  "variables": {
    "devTestLabUserRoleId": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Authorization/roleDefinitions/76283e04-6283-4c54-8f91-bcf1374a3c64')]",
    "fullDevTestLabUserRoleName": "[concat(parameters('labName'), '/Microsoft.Authorization/', parameters('roleAssignmentGuid'))]",
    "roleScope": "[concat('/subscriptions/', subscription().subscriptionId, '/resourceGroups/', resourceGroup().name, '/providers/Microsoft.DevTestLab/labs/', parameters('labName'))]"
  },
  "resources": [
    {
      "apiVersion": "2016-05-15",
      "type": "Microsoft.DevTestLab/labs",
      "name": "[trim(parameters('LabName'))]",
      "location": "[resourceGroup().location]",
      "resources": [
        {
          "apiVersion": "2016-05-15",
          "name": "LabVmsShutdown",
          "type": "schedules",
          "dependsOn": [
            "[resourceId('Microsoft.DevTestLab/labs', parameters('LabName'))]"
          ],
          "properties": {
            "status": "enabled",
            "taskType": "LabVmsShutdownTask",
            "timeZoneId": "[string(parameters('timeZoneId'))]",
            "dailyRecurrence": {
              "time": "[string(parameters('labVmShutDownTime'))]"
            }
          }
        },
        {
          "apiVersion": "2016-05-15",
          "name": "default/MaxVmsAllowedPerUser",
          "type": "policySets/policies",
          "dependsOn": [
            "[resourceId('Microsoft.DevTestLab/labs', parameters('LabName'))]"
          ],
          "properties": {
            "description": "",
            "factName": "UserOwnedLabVmCount",
            "threshold": "[string(parameters('maxAllowedVmsPerUser'))]",
            "evaluatorType": "MaxValuePolicy",
            "status": "enabled"
          }
        },
        {
          "apiVersion": "2016-05-15",
          "name": "default/MaxVmsAllowedPerLab",
          "type": "policySets/policies",
          "dependsOn": [
            "[resourceId('Microsoft.DevTestLab/labs', parameters('LabName'))]"
          ],
          "properties": {
            "description": "",
            "factName": "LabVmCount",
            "threshold": "[string(parameters('maxAllowedVmsPerLab'))]",
            "evaluatorType": "MaxValuePolicy",
            "status": "enabled"
          }
        },
        {
          "apiVersion": "2016-05-15",
          "name": "default/AllowedVmSizesInLab",
          "type": "policySets/policies",
          "dependsOn": [
            "[resourceId('Microsoft.DevTestLab/labs', parameters('LabName'))]"
          ],
          "properties": {
            "description": "",
            "factName": "LabVmSize",
            "threshold": "[concat('[', trim(parameters('allowedVmSizes')), ']')]",
            "evaluatorType": "AllowedValuesPolicy",
            "status": "enabled"
          }
        }
      ]
    },
    {
      "apiVersion": "2016-07-01",
      "type": "Microsoft.DevTestLab/labs/providers/roleAssignments",
      "name": "[variables('fullDevTestLabUserRoleName')]",
      "properties": {
        "roleDefinitionId": "[variables('devTestLabUserRoleId')]",
        "principalId": "[parameters('principalId')]",
        "scope": "[variables('roleScope')]"
      },
      "dependsOn": [
        "[resourceId('Microsoft.DevTestLab/labs', parameters('labName'))]"
      ]
    }
  ],
  "outputs": {
    "labId": {
      "type": "string",
      "value": "[resourceId('Microsoft.DevTestLab/labs', parameters('LabName'))]"
    }
  }
}

My starting points were these 2 repositories:

Thank you!

EMaher commented 7 years ago

@Giaco9 I tried out the template itself and was able to successfully deploy and create a new lab with some parameters I chose. One thing to watch out for is the roleAssignmentGuid needs to be different every time you deploy. Role Assignment definition resources are not updatable so you will get an error if you try to re-deploy with the same roleAssignmentGuid (and thus the same role assignment name).