Deploying Existing Solutions - Azure/AzureTestDrive GitHub Wiki
One more way to use an existing template for a Test Drive is to use it as a linked template.
In order to do it, you need to complete the following tasks:
- Make sure your template has all the access information in the template output. If you template don't have this information, you need to add outputs into your template.
- You need to create a new main template which calls your original template with appropriate parameters, pick access information from the original template output, and return it back to Test Drive.
- Finally, you need to create a Test Drive deployment package which includes both the original and the new main template.
Let's see an example.
Now let's look to the following virtual machine template:
https://github.com/Azure/AzureTestDrive/raw/master/samples/winvm-linked/template.json
This template creates a Public IP Address with an associated DNS name label, but it doesn't return a result, for if you want to use this template in the Test Drive, you need to define template outputs as shown below, otherwise a user will not now what is the host name of the virtual name.
"outputs": {
"hostName": {
"type": "string",
"value": "[reference(variables('pubIpId')).dnsSettings.fqdn]"
}
}
Now we can create a new main template.
This template gets Administrator user name and password from the Test Drive:
"parameters": {
"adminName": {
"type": "string",
"metadata": {
"type": "username",
"description": "Admin user name."
}
},
"adminPassword": {
"type": "securestring",
"metadata": {
"type": "password",
"description": "Admin password."
}
},
...
}
Then generates random DNS name label and storage account name:
"variables": {
"domainNameLabel": "[concat('contosovm',uniquestring(resourceGroup().id))]",
"storageAccountName": "[concat('contosodisk',uniquestring(resourceGroup().id))]"
}
Instantiates the original template:
"resources": [
{
"apiVersion": "2015-01-01",
"name": "linkedTemplate",
"type": "Microsoft.Resources/deployments",
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[concat(parameters('baseUri'),'template.json')]",
"contentVersion": "1.0.0.0"
},
"parameters": {
"vmName": { "value": "w2k12" },
"domainNameLabel": { "value": "[variables('domainNameLabel')]" },
"storageAccountName": { "value": "[variables('storageAccountName')]" },
"adminName": { "value": "[parameters('adminName')]" },
"adminPassword": { "value": "[parameters('adminPassword')]" },
"location": { "value": "[resourceGroup().location]" },
"vmSize": { "value": "Standard_D2_V2" }
}
}
}
]
And, finally, returns host name, user name and password back to Test Drive. Please note, this template picks host name from the linked template output:
"outputs": {
"Host Name": {
"type": "string",
"value": "[reference(resourceId('Microsoft.Resources/deployments','linkedTemplate')).outputs.hostName.value]"
},
"User Name": {
"type": "string",
"value": "[parameters('adminName')]"
},
"Password": {
"type": "string",
"value": "[parameters('adminPassword')]"
}
}
Full example:
https://github.com/Azure/AzureTestDrive/raw/master/samples/winvm-linked/main-template.json
The final thing, you need to create Test Drive template package which include both templates.
| package.zip | Test Drive blob container |
|---|---|
| main-template.json | https://<...>.blob.core.windows.net/<...>/main-template.json |
| template.json | https://<...>.blob.core.windows.net/<...>/template.json |
Inside your template, you can use [Base Uri] (https://github.com/Azure/AzureTestDrive/wiki/Deployment-Templates#baseuri) parameter to construct a Uri of any file from your Test Drive deployment package. The example bellow shows how to construct a Uri of the linked template:
"templateLink": {
"uri": "[concat(parameters('baseUri'),'template.json')]",
"contentVersion": "1.0.0.0"
}
See also: