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:
parent
add2ad98e0
commit
57b1788c9d
3 changed files with 60 additions and 47 deletions
|
|
@ -219,24 +219,24 @@ func WithBootedImageInAzure(creds *azureCredentials, imageName, testId, publicKe
|
||||||
|
|
||||||
// Azure requires a lot of names - for a virtual machine, a virtual network,
|
// Azure requires a lot of names - for a virtual machine, a virtual network,
|
||||||
// a virtual interface and so on and so forth.
|
// a virtual interface and so on and so forth.
|
||||||
// In the Go code, it's just need to know the public IP address name,
|
// Let's create all of them here from the test id.
|
||||||
// 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.
|
|
||||||
deploymentName := testId
|
deploymentName := testId
|
||||||
tag := "tag-" + testId
|
tag := "tag-" + testId
|
||||||
publicIPAddressName := "address-" + testId
|
|
||||||
imagePath := fmt.Sprintf("https://%s.blob.core.windows.net/%s/%s", creds.StorageAccount, creds.ContainerName, imageName)
|
imagePath := fmt.Sprintf("https://%s.blob.core.windows.net/%s/%s", creds.StorageAccount, creds.ContainerName, imageName)
|
||||||
|
|
||||||
parameters := deploymentParameters{
|
parameters := deploymentParameters{
|
||||||
Location: newDeploymentParameter(creds.Location),
|
NetworkInterfaceName: newDeploymentParameter("iface-" + testId),
|
||||||
TestId: newDeploymentParameter(testId),
|
NetworkSecurityGroupName: newDeploymentParameter("nsg-" + testId),
|
||||||
Tag: newDeploymentParameter(tag),
|
VirtualNetworkName: newDeploymentParameter("vnet-" + testId),
|
||||||
PublicIPAddressName: newDeploymentParameter(publicIPAddressName),
|
PublicIPAddressName: newDeploymentParameter("ip-" + testId),
|
||||||
ImagePath: newDeploymentParameter(imagePath),
|
VirtualMachineName: newDeploymentParameter("vm-" + testId),
|
||||||
AdminUsername: newDeploymentParameter("redhat"),
|
DiskName: newDeploymentParameter("disk-" + testId),
|
||||||
AdminPublicKey: newDeploymentParameter(publicKey),
|
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)
|
deploymentsClient := resources.NewDeploymentsClient(creds.SubscriptionID)
|
||||||
|
|
@ -319,7 +319,7 @@ func WithBootedImageInAzure(creds *azureCredentials, imageName, testId, publicKe
|
||||||
publicIPAddressClient := network.NewPublicIPAddressesClient(creds.SubscriptionID)
|
publicIPAddressClient := network.NewPublicIPAddressesClient(creds.SubscriptionID)
|
||||||
publicIPAddressClient.Authorizer = authorizer
|
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot get the ip address details: %v", err)
|
return fmt.Errorf("cannot get the ip address details: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,20 +33,25 @@ func loadDeploymentTemplate() (interface{}, error) {
|
||||||
|
|
||||||
// struct for encoding a deployment parameter
|
// struct for encoding a deployment parameter
|
||||||
type deploymentParameter struct {
|
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}
|
return deploymentParameter{Value: value}
|
||||||
}
|
}
|
||||||
|
|
||||||
// struct for encoding deployment parameters
|
// struct for encoding deployment parameters
|
||||||
type deploymentParameters struct {
|
type deploymentParameters struct {
|
||||||
Location deploymentParameter `json:"location"`
|
NetworkInterfaceName deploymentParameter `json:"networkInterfaceName"`
|
||||||
TestId deploymentParameter `json:"testId"`
|
NetworkSecurityGroupName deploymentParameter `json:"networkSecurityGroupName"`
|
||||||
Tag deploymentParameter `json:"tag"`
|
VirtualNetworkName deploymentParameter `json:"virtualNetworkName"`
|
||||||
PublicIPAddressName deploymentParameter `json:"publicIPAddressName"`
|
PublicIPAddressName deploymentParameter `json:"publicIPAddressName"`
|
||||||
ImagePath deploymentParameter `json:"imagePath"`
|
VirtualMachineName deploymentParameter `json:"virtualMachineName"`
|
||||||
AdminUsername deploymentParameter `json:"adminUsername"`
|
DiskName deploymentParameter `json:"diskName"`
|
||||||
AdminPublicKey deploymentParameter `json:"adminPublicKey"`
|
ImageName deploymentParameter `json:"imageName"`
|
||||||
|
Tag deploymentParameter `json:"tag"`
|
||||||
|
Location deploymentParameter `json:"location"`
|
||||||
|
ImagePath deploymentParameter `json:"imagePath"`
|
||||||
|
AdminUsername deploymentParameter `json:"adminUsername"`
|
||||||
|
AdminPublicKey deploymentParameter `json:"adminPublicKey"`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,27 @@
|
||||||
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
|
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
|
||||||
"contentVersion": "1.0.0.0",
|
"contentVersion": "1.0.0.0",
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"testId": {
|
"networkInterfaceName": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"networkSecurityGroupName": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"virtualNetworkName": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"publicIPAddressName": {
|
"publicIPAddressName": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"virtualMachineName": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"diskName": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"imageName": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"tag": {
|
"tag": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
|
@ -25,26 +40,19 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"variables": {
|
"variables": {
|
||||||
"subnetRef": "[concat(variables('vnetId'), '/subnets/default')]",
|
"nsgId": "[resourceId(resourceGroup().name, 'Microsoft.Network/networkSecurityGroups', parameters('networkSecurityGroupName'))]",
|
||||||
"networkInterfaceName": "[concat('iface-', parameters('testId'))]",
|
"vnetId": "[resourceId(resourceGroup().name,'Microsoft.Network/virtualNetworks', parameters('virtualNetworkName'))]",
|
||||||
"networkSecurityGroupName": "[concat('nsg-', parameters('testId'))]",
|
"subnetRef": "[concat(variables('vnetId'), '/subnets/default')]"
|
||||||
"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'))]"
|
|
||||||
},
|
},
|
||||||
"resources": [
|
"resources": [
|
||||||
{
|
{
|
||||||
"name": "[variables('networkInterfaceName')]",
|
"name": "[parameters('networkInterfaceName')]",
|
||||||
"type": "Microsoft.Network/networkInterfaces",
|
"type": "Microsoft.Network/networkInterfaces",
|
||||||
"apiVersion": "2019-07-01",
|
"apiVersion": "2019-07-01",
|
||||||
"location": "[parameters('location')]",
|
"location": "[parameters('location')]",
|
||||||
"dependsOn": [
|
"dependsOn": [
|
||||||
"[concat('Microsoft.Network/networkSecurityGroups/', variables('networkSecurityGroupName'))]",
|
"[concat('Microsoft.Network/networkSecurityGroups/', parameters('networkSecurityGroupName'))]",
|
||||||
"[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]",
|
"[concat('Microsoft.Network/virtualNetworks/', parameters('virtualNetworkName'))]",
|
||||||
"[concat('Microsoft.Network/publicIpAddresses/', parameters('publicIPAddressName'))]"
|
"[concat('Microsoft.Network/publicIpAddresses/', parameters('publicIPAddressName'))]"
|
||||||
],
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
|
|
@ -71,7 +79,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "[variables('networkSecurityGroupName')]",
|
"name": "[parameters('networkSecurityGroupName')]",
|
||||||
"type": "Microsoft.Network/networkSecurityGroups",
|
"type": "Microsoft.Network/networkSecurityGroups",
|
||||||
"apiVersion": "2019-02-01",
|
"apiVersion": "2019-02-01",
|
||||||
"location": "[parameters('location')]",
|
"location": "[parameters('location')]",
|
||||||
|
|
@ -97,7 +105,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "[variables('virtualNetworkName')]",
|
"name": "[parameters('virtualNetworkName')]",
|
||||||
"type": "Microsoft.Network/virtualNetworks",
|
"type": "Microsoft.Network/virtualNetworks",
|
||||||
"apiVersion": "2019-09-01",
|
"apiVersion": "2019-09-01",
|
||||||
"location": "[parameters('location')]",
|
"location": "[parameters('location')]",
|
||||||
|
|
@ -136,7 +144,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "[variables('imageName')]",
|
"name": "[parameters('imageName')]",
|
||||||
"type": "Microsoft.Compute/images",
|
"type": "Microsoft.Compute/images",
|
||||||
"apiVersion": "2019-07-01",
|
"apiVersion": "2019-07-01",
|
||||||
"location": "[parameters('location')]",
|
"location": "[parameters('location')]",
|
||||||
|
|
@ -155,13 +163,13 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "[variables('virtualMachineName')]",
|
"name": "[parameters('virtualMachineName')]",
|
||||||
"type": "Microsoft.Compute/virtualMachines",
|
"type": "Microsoft.Compute/virtualMachines",
|
||||||
"apiVersion": "2019-07-01",
|
"apiVersion": "2019-07-01",
|
||||||
"location": "[parameters('location')]",
|
"location": "[parameters('location')]",
|
||||||
"dependsOn": [
|
"dependsOn": [
|
||||||
"[concat('Microsoft.Network/networkInterfaces/', variables('networkInterfaceName'))]",
|
"[concat('Microsoft.Network/networkInterfaces/', parameters('networkInterfaceName'))]",
|
||||||
"[concat('Microsoft.Compute/images/', variables('imageName'))]"
|
"[concat('Microsoft.Compute/images/', parameters('imageName'))]"
|
||||||
],
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
"hardwareProfile": {
|
"hardwareProfile": {
|
||||||
|
|
@ -169,26 +177,26 @@
|
||||||
},
|
},
|
||||||
"storageProfile": {
|
"storageProfile": {
|
||||||
"imageReference": {
|
"imageReference": {
|
||||||
"id": "[resourceId(resourceGroup().name, 'Microsoft.Compute/images', variables('imageName'))]"
|
"id": "[resourceId(resourceGroup().name, 'Microsoft.Compute/images', parameters('imageName'))]"
|
||||||
},
|
},
|
||||||
"osDisk": {
|
"osDisk": {
|
||||||
"caching": "ReadWrite",
|
"caching": "ReadWrite",
|
||||||
"managedDisk": {
|
"managedDisk": {
|
||||||
"storageAccountType": "Standard_LRS"
|
"storageAccountType": "Standard_LRS"
|
||||||
},
|
},
|
||||||
"name": "[variables('diskName')]",
|
"name": "[parameters('diskName')]",
|
||||||
"createOption": "FromImage"
|
"createOption": "FromImage"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"networkProfile": {
|
"networkProfile": {
|
||||||
"networkInterfaces": [
|
"networkInterfaces": [
|
||||||
{
|
{
|
||||||
"id": "[resourceId('Microsoft.Network/networkInterfaces', variables('networkInterfaceName'))]"
|
"id": "[resourceId('Microsoft.Network/networkInterfaces', parameters('networkInterfaceName'))]"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"osProfile": {
|
"osProfile": {
|
||||||
"computerName": "[variables('virtualMachineName')]",
|
"computerName": "[parameters('virtualMachineName')]",
|
||||||
"adminUsername": "[parameters('adminUsername')]",
|
"adminUsername": "[parameters('adminUsername')]",
|
||||||
"linuxConfiguration": {
|
"linuxConfiguration": {
|
||||||
"disablePasswordAuthentication": true,
|
"disablePasswordAuthentication": true,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue