The following forum(s) are migrating to a new home on Microsoft Q&A (Preview): Azure DevTest Labs!

Ask new questions on Microsoft Q&A (Preview).
Interact with existing posts until December 13, 2019, after which content will be closed to all new and existing posts.

Learn More

 none
Using 'Environment' name as a variable in lab Template? RRS feed

  • Question

  • Hi,

    I have a DevTest lab working with an Azure Template to create an environment with multiple VMs. As part of that I'm creating a VM with an external DNS name. Currently I'm using a prefix followed by a random string which is OK, but I'd prefer to tie the external DNS name into the name of the environment so that the URL used to access the environment has a reference to the environment name in it.

    So my question is, is this possible? and if so, what is the syntax of the template code that would allow me to put the environment name into a template variable?

    Thanks,

    Mark.

    Thursday, December 6, 2018 10:06 AM

All replies

  • Hi Mark,

    To answer your question - yes this is possible. In order to achieve this you would need to introduce a new parameter in your ARM template. While populating this parameter from Dev Test Lab, populate it with the same value as the Environment name. Then use it to populate the domainNameLabel. Please find the code snippets below:

    azuredeploy.json

    {
      "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json",
      "contentVersion": "1.0.0.0",
      "parameters": {
        "vmssName": {
          "type": "string",
          "metadata": {
            "description": "DNS name used for public IP addresses and as base for naming other resources. Must be globally unique and 3 to 61 characters long."
          },
          "minLength": 3,
          "maxLength": 61
        }
      },
      "variables": {
        "longNamingInfix": "[toLower(parameters('vmssName'))]"
      },
      "resources": [
        {
          "type": "Microsoft.Network/publicIPAddresses",
          "name": "[variables('publicIPAddressName')]",
          "location": "[variables('location')]",
          "apiVersion": "2016-03-30",
          "tags": {
            "displayName": "PublicIP"
          },
          "properties": {
            "publicIPAllocationMethod": "Dynamic",
            "dnsSettings": {
              "domainNameLabel": "[variables('longNamingInfix')]"
            }
          }
        }
      ]
    }
    

    azuredeploy.parameters.json

    {
      "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
      "contentVersion": "1.0.0.0",
      "parameters": {
        "vmssName": {
          "value": null
        }
      }
    }

    Below is a snippet of how it would look like in your Dev test lab. 


    Tuesday, December 11, 2018 12:11 PM
    Moderator
  • That's not what I asked though is it - I'm perfectly aware how to create another parameter and use that, but that's a really poor user experience - The user has already entered the envornment name, how can I grab that directly?
    Tuesday, December 11, 2018 1:03 PM
  • Unfortunately there is no way to grab the environment name directly and populate another variable with that as of now. Feel free to post this idea in Azure DevTest Labs Feedback Forum
    Tuesday, December 11, 2018 8:39 PM
    Moderator