test/azure: specify resource names as parameters

Prior this commit the resource names were generated in the deployment
template, so the Go code actually didn't know them. This commit generates
all names in the Go code, so they can be used in the future commits.
This commit is contained in:
Ondřej Budai 2020-07-03 15:05:50 +02:00
parent add2ad98e0
commit 57b1788c9d
3 changed files with 60 additions and 47 deletions

View file

@ -219,24 +219,24 @@ func WithBootedImageInAzure(creds *azureCredentials, imageName, testId, publicKe
// Azure requires a lot of names - for a virtual machine, a virtual network,
// a virtual interface and so on and so forth.
// In the Go code, it's just need to know the public IP address name,
// the tag name and the deployment name. Let's set these here to names
// based on the test id.
// The rest of the names are set from the test id inside the deployment
// template because they're irrelevant to the Go code.
// Let's create all of them here from the test id.
deploymentName := testId
tag := "tag-" + testId
publicIPAddressName := "address-" + testId
imagePath := fmt.Sprintf("https://%s.blob.core.windows.net/%s/%s", creds.StorageAccount, creds.ContainerName, imageName)
parameters := deploymentParameters{
Location: newDeploymentParameter(creds.Location),
TestId: newDeploymentParameter(testId),
Tag: newDeploymentParameter(tag),
PublicIPAddressName: newDeploymentParameter(publicIPAddressName),
ImagePath: newDeploymentParameter(imagePath),
AdminUsername: newDeploymentParameter("redhat"),
AdminPublicKey: newDeploymentParameter(publicKey),
NetworkInterfaceName: newDeploymentParameter("iface-" + testId),
NetworkSecurityGroupName: newDeploymentParameter("nsg-" + testId),
VirtualNetworkName: newDeploymentParameter("vnet-" + testId),
PublicIPAddressName: newDeploymentParameter("ip-" + testId),
VirtualMachineName: newDeploymentParameter("vm-" + testId),
DiskName: newDeploymentParameter("disk-" + testId),
ImageName: newDeploymentParameter("image-" + testId),
Tag: newDeploymentParameter(tag),
Location: newDeploymentParameter(creds.Location),
ImagePath: newDeploymentParameter(imagePath),
AdminUsername: newDeploymentParameter("redhat"),
AdminPublicKey: newDeploymentParameter(publicKey),
}
deploymentsClient := resources.NewDeploymentsClient(creds.SubscriptionID)
@ -319,7 +319,7 @@ func WithBootedImageInAzure(creds *azureCredentials, imageName, testId, publicKe
publicIPAddressClient := network.NewPublicIPAddressesClient(creds.SubscriptionID)
publicIPAddressClient.Authorizer = authorizer
publicIPAddress, err := publicIPAddressClient.Get(context.Background(), creds.ResourceGroup, publicIPAddressName, "")
publicIPAddress, err := publicIPAddressClient.Get(context.Background(), creds.ResourceGroup, parameters.PublicIPAddressName.Value, "")
if err != nil {
return fmt.Errorf("cannot get the ip address details: %v", err)
}

View file

@ -33,20 +33,25 @@ func loadDeploymentTemplate() (interface{}, error) {
// struct for encoding a deployment parameter
type deploymentParameter struct {
Value interface{} `json:"value"`
Value string `json:"value"`
}
func newDeploymentParameter(value interface{}) deploymentParameter {
func newDeploymentParameter(value string) deploymentParameter {
return deploymentParameter{Value: value}
}
// struct for encoding deployment parameters
type deploymentParameters struct {
Location deploymentParameter `json:"location"`
TestId deploymentParameter `json:"testId"`
Tag deploymentParameter `json:"tag"`
PublicIPAddressName deploymentParameter `json:"publicIPAddressName"`
ImagePath deploymentParameter `json:"imagePath"`
AdminUsername deploymentParameter `json:"adminUsername"`
AdminPublicKey deploymentParameter `json:"adminPublicKey"`
NetworkInterfaceName deploymentParameter `json:"networkInterfaceName"`
NetworkSecurityGroupName deploymentParameter `json:"networkSecurityGroupName"`
VirtualNetworkName deploymentParameter `json:"virtualNetworkName"`
PublicIPAddressName deploymentParameter `json:"publicIPAddressName"`
VirtualMachineName deploymentParameter `json:"virtualMachineName"`
DiskName deploymentParameter `json:"diskName"`
ImageName deploymentParameter `json:"imageName"`
Tag deploymentParameter `json:"tag"`
Location deploymentParameter `json:"location"`
ImagePath deploymentParameter `json:"imagePath"`
AdminUsername deploymentParameter `json:"adminUsername"`
AdminPublicKey deploymentParameter `json:"adminPublicKey"`
}

View file

@ -2,12 +2,27 @@
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"testId": {
"networkInterfaceName": {
"type": "string"
},
"networkSecurityGroupName": {
"type": "string"
},
"virtualNetworkName": {
"type": "string"
},
"publicIPAddressName": {
"type": "string"
},
"virtualMachineName": {
"type": "string"
},
"diskName": {
"type": "string"
},
"imageName": {
"type": "string"
},
"tag": {
"type": "string"
},
@ -25,26 +40,19 @@
}
},
"variables": {
"subnetRef": "[concat(variables('vnetId'), '/subnets/default')]",
"networkInterfaceName": "[concat('iface-', parameters('testId'))]",
"networkSecurityGroupName": "[concat('nsg-', parameters('testId'))]",
"virtualNetworkName": "[concat('vnet-', parameters('testId'))]",
"publicIPAddressName": "[concat('ip-', parameters('testId'))]",
"virtualMachineName": "[concat('vm-', parameters('testId'))]",
"diskName": "[concat('disk-', parameters('testId'))]",
"imageName": "[concat('image-', parameters('testId'))]",
"nsgId": "[resourceId(resourceGroup().name, 'Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName'))]",
"vnetId": "[resourceId(resourceGroup().name,'Microsoft.Network/virtualNetworks', variables('virtualNetworkName'))]"
"nsgId": "[resourceId(resourceGroup().name, 'Microsoft.Network/networkSecurityGroups', parameters('networkSecurityGroupName'))]",
"vnetId": "[resourceId(resourceGroup().name,'Microsoft.Network/virtualNetworks', parameters('virtualNetworkName'))]",
"subnetRef": "[concat(variables('vnetId'), '/subnets/default')]"
},
"resources": [
{
"name": "[variables('networkInterfaceName')]",
"name": "[parameters('networkInterfaceName')]",
"type": "Microsoft.Network/networkInterfaces",
"apiVersion": "2019-07-01",
"location": "[parameters('location')]",
"dependsOn": [
"[concat('Microsoft.Network/networkSecurityGroups/', variables('networkSecurityGroupName'))]",
"[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]",
"[concat('Microsoft.Network/networkSecurityGroups/', parameters('networkSecurityGroupName'))]",
"[concat('Microsoft.Network/virtualNetworks/', parameters('virtualNetworkName'))]",
"[concat('Microsoft.Network/publicIpAddresses/', parameters('publicIPAddressName'))]"
],
"properties": {
@ -71,7 +79,7 @@
}
},
{
"name": "[variables('networkSecurityGroupName')]",
"name": "[parameters('networkSecurityGroupName')]",
"type": "Microsoft.Network/networkSecurityGroups",
"apiVersion": "2019-02-01",
"location": "[parameters('location')]",
@ -97,7 +105,7 @@
}
},
{
"name": "[variables('virtualNetworkName')]",
"name": "[parameters('virtualNetworkName')]",
"type": "Microsoft.Network/virtualNetworks",
"apiVersion": "2019-09-01",
"location": "[parameters('location')]",
@ -136,7 +144,7 @@
}
},
{
"name": "[variables('imageName')]",
"name": "[parameters('imageName')]",
"type": "Microsoft.Compute/images",
"apiVersion": "2019-07-01",
"location": "[parameters('location')]",
@ -155,13 +163,13 @@
}
},
{
"name": "[variables('virtualMachineName')]",
"name": "[parameters('virtualMachineName')]",
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2019-07-01",
"location": "[parameters('location')]",
"dependsOn": [
"[concat('Microsoft.Network/networkInterfaces/', variables('networkInterfaceName'))]",
"[concat('Microsoft.Compute/images/', variables('imageName'))]"
"[concat('Microsoft.Network/networkInterfaces/', parameters('networkInterfaceName'))]",
"[concat('Microsoft.Compute/images/', parameters('imageName'))]"
],
"properties": {
"hardwareProfile": {
@ -169,26 +177,26 @@
},
"storageProfile": {
"imageReference": {
"id": "[resourceId(resourceGroup().name, 'Microsoft.Compute/images', variables('imageName'))]"
"id": "[resourceId(resourceGroup().name, 'Microsoft.Compute/images', parameters('imageName'))]"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "[variables('diskName')]",
"name": "[parameters('diskName')]",
"createOption": "FromImage"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', variables('networkInterfaceName'))]"
"id": "[resourceId('Microsoft.Network/networkInterfaces', parameters('networkInterfaceName'))]"
}
]
},
"osProfile": {
"computerName": "[variables('virtualMachineName')]",
"computerName": "[parameters('virtualMachineName')]",
"adminUsername": "[parameters('adminUsername')]",
"linuxConfiguration": {
"disablePasswordAuthentication": true,