This commit is contained in:
Lili Deng 2024-05-18 19:24:01 +08:00 коммит произвёл LiliDeng
Родитель 9bf9d585e0
Коммит 4c1cca097e
3 изменённых файлов: 1 добавлений и 700 удалений

Просмотреть файл

@ -15,20 +15,4 @@ To achieve this, follow these steps:
Make sure you have the Bicep CLI installed. You can install it `here <https://learn.microsoft.com/en-us/azure/azure-resource-manager/bicep/bicep-cli>`__. Put bicepconfig.json in the same directory as the Bicep template.
3. **Enable Bicep Generated ARM Template**: Set use_bicep to true in the runbook.
.. code:: yaml
platform:
- type: azure
...
azure:
...
use_bicep: true
requirement:
...
azure:
...
location: "<one or multiple locations, split by comma>"
These steps allow you to leverage the benefits of Bicep for defining Azure infrastructure while still utilizing the Azure Python SDK for deployment.

Просмотреть файл

@ -1,677 +0,0 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vhd_storage_name": {
"type": "string",
"metadata": {
"description": "storage name for copied vhds"
}
},
"location": {
"type": "string",
"metadata": {
"description": "location"
}
},
"nodes": {
"type": "array",
"metadata": {
"description": "all nodes"
}
},
"admin_username": {
"type": "string",
"metadata": {
"description": "user name"
}
},
"admin_password": {
"type": "string",
"metadata": {
"description": "password"
}
},
"admin_key_data": {
"type": "string",
"metadata": {
"description": "public key data"
}
},
"shared_resource_group_name": {
"type": "string",
"metadata": {
"description": "the name of shared resource group"
}
},
"subnet_count": {
"type": "int",
"defaultValue": 1,
"metadata": {
"description": "created subnet count"
}
},
"availability_options": {
"type": "object",
"metadata": {
"description": "options for availability sets, zones, and VMSS"
}
},
"virtual_network_resource_group": {
"type": "string",
"metadata": {
"description": "the name of vnet resource group"
}
},
"virtual_network_name": {
"type": "string",
"metadata": {
"description": "the name of vnet"
}
},
"subnet_prefix": {
"type": "string",
"metadata": {
"description": "the prefix of the subnets"
}
},
"vm_tags": {
"type": "object",
"metadata": {
"description": "tags of virtual machine"
}
},
"data_disks": {
"type": "array",
"metadata": {
"description": "data disk array."
}
},
"is_ultradisk": {
"type": "bool",
"defaultValue": false,
"metadata": {
"description": "whether to use ultra disk"
}
}
},
"variables": {
"vnet_id": "[resourceId('Microsoft.Network/virtualNetworks/', parameters('virtual_network_name'))]",
"node_count": "[length(parameters('nodes'))]",
"availability_set_name": "lisa-availabilitySet",
"existing_subnet_ref": "[if(not(empty(parameters('virtual_network_resource_group'))), resourceId(parameters('virtual_network_resource_group'), 'Microsoft.Network/virtualNetworks/subnets', parameters('virtual_network_name'), parameters('subnet_prefix')), '')]",
"availability_set_tags": "[parameters('availability_options')['availability_set_tags']]",
"availability_set_properties": "[parameters('availability_options')['availability_set_properties']]",
"availability_zones": "[parameters('availability_options')['availability_zones']]",
"availability_type": "[parameters('availability_options')['availability_type']]",
"use_availability_sets": "[equals(parameters('availability_options')['availability_type'], 'availability_set')]",
"use_availability_zones": "[equals(parameters('availability_options')['availability_type'], 'availability_zone')]"
},
"resources": [
{
"apiVersion": "2019-07-01",
"type": "Microsoft.Compute/availabilitySets",
"condition": "[variables('use_availability_sets')]",
"name": "[variables('availability_set_name')]",
"location": "[parameters('location')]",
"tags": "[variables('availability_set_tags')]",
"sku": {
"name": "Aligned"
},
"properties": "[variables('availability_set_properties')]"
},
{
"apiVersion": "2020-05-01",
"type": "Microsoft.Network/publicIPAddresses",
"location": "[parameters('location')]",
"name": "[concat(parameters('nodes')[copyIndex('publicIpCopy')]['name'],'-public-ip')]",
"copy": {
"name": "publicIpCopy",
"count": "[variables('node_count')]"
},
"properties": {
"publicIPAllocationMethod": "[if(parameters('is_ultradisk'), 'Static', 'Dynamic')]"
},
"sku": {
"name": "[if(parameters('is_ultradisk'), 'Standard', 'Basic')]"
},
"zones": "[if(variables('use_availability_zones'), variables('availability_zones'), json('null'))]"
},
{
"condition": "[empty(parameters('virtual_network_resource_group'))]",
"apiVersion": "2020-05-01",
"type": "Microsoft.Network/virtualNetworks",
"name": "[parameters('virtual_network_name')]",
"location": "[parameters('location')]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"10.0.0.0/16"
]
},
"copy": [
{
"name": "subnets",
"count": "[parameters('subnet_count')]",
"input": {
"name": "[concat(parameters('subnet_prefix'), copyIndex('subnets'))]",
"properties": {
"addressPrefix": "[concat('10.0.', copyIndex('subnets'), '.0/24')]"
}
}
}
]
}
},
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2019-10-01",
"copy": {
"name": "nicCopy",
"count": "[variables('node_count')]"
},
"name": "[concat(parameters('nodes')[copyIndex('nicCopy')]['name'],'-nics')]",
"dependsOn": [
"[resourceId('Microsoft.Network/publicIPAddresses/', concat(parameters('nodes')[copyIndex('nicCopy')]['name'],'-public-ip'))]",
"[variables('vnet_id')]"
],
"properties": {
"expressionEvaluationOptions": {
"scope": "inner"
},
"parameters": {
"vmName": {
"value": "[parameters('nodes')[copyIndex('nicCopy')]['name']]"
},
"nic_count": {
"value": "[parameters('nodes')[copyIndex('nicCopy')]['nic_count']]"
},
"location": {
"value": "[parameters('location')]"
},
"vnet_id": {
"value": "[variables('vnet_id')]"
},
"subnet_prefix": {
"value": "[parameters('subnet_prefix')]"
},
"existing_subnet_ref": {
"value": "[variables('existing_subnet_ref')]"
},
"enable_sriov": {
"value": "[parameters('nodes')[copyIndex('nicCopy')]['enable_sriov']]"
},
"availability_zones": {
"value": "[variables('availability_zones')]"
}
},
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vmName": {
"type": "string"
},
"nic_count": {
"type": "int"
},
"location": {
"type": "string"
},
"vnet_id": {
"type": "string"
},
"subnet_prefix": {
"type": "string"
},
"existing_subnet_ref": {
"type": "string"
},
"enable_sriov": {
"type": "bool"
},
"availability_zones": {
"type": "array"
}
},
"resources": [
{
"apiVersion": "2020-05-01",
"type": "Microsoft.Network/networkInterfaces",
"copy": {
"name": "internalNicCopy",
"count": "[parameters('nic_count')]"
},
"name": "[concat(parameters('vmName'), '-nic-', copyIndex('internalNicCopy'))]",
"location": "[parameters('location')]",
"properties": {
"ipConfigurations": [
{
"name": "IPv4Config",
"properties": {
"privateIPAddressVersion": "IPv4",
"publicIPAddress": "[if(equals(0, copyIndex('internalNicCopy')), network.getPublicIpAddress(parameters('vmName')), json('null'))]",
"subnet": {
"id": "[if(not(empty(parameters('existing_subnet_ref'))), parameters('existing_subnet_ref'), concat(parameters('vnet_id'),'/subnets/', concat(parameters('subnet_prefix'), copyIndex('internalNicCopy'))))]"
},
"privateIPAllocationMethod": "Dynamic"
}
}
],
"enableAcceleratedNetworking": "[parameters('enable_sriov')]"
}
}
],
"functions": [
{
"namespace": "network",
"members": {
"getPublicIpAddress": {
"parameters": [
{
"name": "vmName",
"type": "string"
}
],
"output": {
"type": "object",
"value": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses/', concat(parameters('vmName'),'-public-ip'))]"
}
}
}
}
}
]
}
}
},
{
"apiVersion": "2019-03-01",
"type": "Microsoft.Compute/images",
"copy": {
"name": "imageCopy",
"count": "[variables('node_count')]"
},
"condition": "[and(not(empty(parameters('nodes')[copyIndex('imageCopy')]['vhd'])), not(empty(parameters('nodes')[copyIndex('imageCopy')]['vhd']['vhd_path'])), empty(parameters('nodes')[copyIndex('imageCopy')]['vhd']['vmgs_path']))]",
"name": "[concat(parameters('nodes')[copyIndex('imageCopy')]['name'], '-image')]",
"location": "[parameters('location')]",
"properties": {
"storageProfile": {
"osDisk": {
"osType": "Linux",
"osState": "Generalized",
"blobUri": "[parameters('nodes')[copyIndex('imageCopy')]['vhd']['vhd_path']]",
"storageAccountType": "Standard_LRS"
}
},
"hyperVGeneration": "[concat('V', parameters('nodes')[copyIndex('imageCopy')]['hyperv_generation'])]"
}
},
{
"type": "Microsoft.Compute/disks",
"apiVersion": "2021-04-01",
"name": "[concat(parameters('nodes')[copyIndex('diskCopy')]['name'], '-disk')]",
"location": "[parameters('location')]",
"condition": "[and(not(empty(parameters('nodes')[copyIndex('diskCopy')]['vhd'])), not(empty(parameters('nodes')[copyIndex('diskCopy')]['vhd']['vmgs_path'])))]",
"copy": {
"name": "diskCopy",
"count": "[variables('node_count')]"
},
"sku": {
"name": "Standard_LRS"
},
"properties": {
"osType": "Linux",
"hyperVGeneration": "[concat('V', parameters('nodes')[copyIndex('diskCopy')]['hyperv_generation'])]",
"securityProfile": {
"securityType": "ConfidentialVM_VMGuestStateOnlyEncryptedWithPlatformKey"
},
"creationData": {
"createOption": "ImportSecure",
"storageAccountId": "[resourceId(parameters('shared_resource_group_name'), 'Microsoft.Storage/storageAccounts', parameters('vhd_storage_name'))]",
"securityDataUri": "[parameters('nodes')[copyIndex('diskCopy')]['vhd']['vmgs_path']]",
"sourceUri": "[parameters('nodes')[copyIndex('diskCopy')]['vhd']['vhd_path']]"
}
},
"zones": "[if(variables('use_availability_zones'), variables('availability_zones'), json('null'))]"
},
{
"name": "[concat(parameters('nodes')[div(copyIndex(), length(parameters('data_disks')))]['name'], '-data-disk-', mod(copyIndex(), length(parameters('data_disks'))))]",
"type": "Microsoft.Compute/disks",
"apiVersion": "2022-03-02",
"location": "[parameters('location')]",
"condition": "[equals(parameters('data_disks')[mod(copyIndex(), length(parameters('data_disks')))].type, 'UltraSSD_LRS')]",
"properties": {
"diskSizeGB": "[parameters('data_disks')[mod(copyIndex(), length(parameters('data_disks')))].size]",
"creationData": {
"createOption": "[parameters('data_disks')[mod(copyIndex(), length(parameters('data_disks')))].create_option]"
},
"diskIOPSReadWrite": "[parameters('data_disks')[mod(copyIndex(), length(parameters('data_disks')))].iops]",
"diskMBpsReadWrite": "[parameters('data_disks')[mod(copyIndex(), length(parameters('data_disks')))].throughput]"
},
"sku": {
"name": "[parameters('data_disks')[mod(copyIndex(), length(parameters('data_disks')))].type]"
},
"copy": {
"name": "ultraDisks",
"count": "[mul(length(parameters('data_disks')), variables('node_count'))]"
},
"zones": "[if(variables('use_availability_zones'), variables('availability_zones'), json('null'))]"
},
{
"apiVersion": "2023-09-01",
"type": "Microsoft.Compute/virtualMachines",
"copy": {
"name": "vmCopy",
"count": "[variables('node_count')]"
},
"name": "[parameters('nodes')[copyIndex('vmCopy')]['name']]",
"location": "[parameters('nodes')[copyIndex('vmCopy')]['location']]",
"tags": "[parameters('vm_tags')]",
"plan": "[parameters('nodes')[copyIndex('vmCopy')]['purchase_plan']]",
"dependsOn": [
"ultraDisks",
"[resourceId('Microsoft.Compute/availabilitySets', variables('availability_set_name'))]",
"[if(and(not(empty(parameters('nodes')[copyIndex('vmCopy')]['vhd'])),not(empty(parameters('nodes')[copyIndex('vmCopy')]['vhd']['vmgs_path']))), concat(parameters('nodes')[copyIndex('vmCopy')]['name'], '-disk'), resourceId('Microsoft.Compute/images',concat(parameters('nodes')[copyIndex('vmCopy')]['name'],'-image')))]",
"[concat(parameters('nodes')[copyIndex('vmCopy')]['name'],'-nics')]"
],
"properties": {
"availabilitySet": "[if(variables('use_availability_sets'), json(concat('{\"id\": \"',resourceId('Microsoft.Compute/availabilitySets',variables('availability_set_name')),'\"}')), json('null'))]",
"hardwareProfile": {
"vmSize": "[parameters('nodes')[copyIndex('vmCopy')]['vm_size']]"
},
"osProfile": "[if(and(not(empty(parameters('nodes')[copyIndex('vmCopy')]['vhd'])),not(empty(parameters('nodes')[copyIndex('vmCopy')]['vhd']['vmgs_path']))), json('null'), lisa.getOsProfile( parameters('nodes')[copyIndex('vmCopy')]['short_name'], parameters('admin_username'), not(empty(parameters('admin_password'))), parameters('admin_password'), and(not(empty(parameters('admin_key_data'))), parameters('nodes')[copyIndex('vmCopy')]['is_linux']), lisa.getLinuxConfiguration(concat('/home/', parameters('admin_username'), '/.ssh/authorized_keys'), parameters('admin_key_data'), empty(parameters('admin_password'))) ))]",
"storageProfile": {
"imageReference": "[if(and(not(empty(parameters('nodes')[copyIndex('vmCopy')]['vhd'])),not(empty(parameters('nodes')[copyIndex('vmCopy')]['vhd']['vmgs_path']))), json('null'), if(and(not(empty(parameters('nodes')[copyIndex('vmCopy')]['vhd'])),not(empty(parameters('nodes')[copyIndex('vmCopy')]['vhd']['vhd_path']))), lisa.getOsDiskVhd(parameters('nodes')[copyIndex('vmCopy')]['name']), if(not(empty(parameters('nodes')[copyIndex('vmCopy')]['shared_gallery'])), lisa.getOsDiskSharedGallery(parameters('nodes')[copyIndex('vmCopy')]['shared_gallery']), lisa.getOsDiskMarketplace(parameters('nodes')[copyIndex('vmCopy')]))))]",
"osDisk": "[if(and(not(empty(parameters('nodes')[copyIndex('vmCopy')]['vhd'])),not(empty(parameters('nodes')[copyIndex('vmCopy')]['vhd']['vmgs_path']))), lisa.getOsDisk(concat(parameters('nodes')[copyIndex('vmCopy')]['name'], '-disk')), if(equals(parameters('nodes')[copyIndex('vmCopy')]['os_disk_type'], 'Ephemeral'), lisa.getEphemeralOSImage(parameters('nodes')[copyIndex('vmCopy')]), lisa.getOSImage(parameters('nodes')[copyIndex('vmCopy')])) )]",
"diskControllerType": "[if(equals(parameters('nodes')[copyIndex('vmCopy')]['disk_controller_type'], 'SCSI'), json('null'), parameters('nodes')[copyIndex('vmCopy')]['disk_controller_type'])]",
"copy": [
{
"name": "dataDisks",
"count": "[length(parameters('data_disks'))]",
"input": "[if(equals(parameters('data_disks')[copyIndex('dataDisks')].type, 'UltraSSD_LRS'), lisa.getAttachDisk(parameters('data_disks')[copyIndex('dataDisks')],concat(parameters('nodes')[copyIndex('vmCopy')]['name'], '-data-disk-', copyIndex('dataDisks')),copyIndex('dataDisks')), lisa.getCreateDisk(parameters('data_disks')[copyIndex('dataDisks')],concat(parameters('nodes')[copyIndex('vmCopy')]['name'], '-data-disk-', copyIndex('dataDisks')),copyIndex('dataDisks')))]"
}
]
},
"networkProfile": {
"copy": [
{
"name": "networkInterfaces",
"count": "[parameters('nodes')[copyIndex('vmCopy')]['nic_count']]",
"input": {
"id": "[resourceId('Microsoft.Network/networkInterfaces', concat(parameters('nodes')[copyIndex('vmCopy')]['name'], '-nic-', copyIndex('networkInterfaces')))]",
"properties": {
"primary": "[if(equals(copyIndex('networkInterfaces'),0), json('true'), json('false'))]"
}
}
}
]
},
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": true
}
},
"additionalCapabilities": "[if(equals(parameters('nodes')[copyIndex('vmCopy')]['data_disk_type'], 'UltraSSD_LRS'), json('{\"ultraSSDEnabled\": true}'), json('null'))]",
"securityProfile": "[if(empty(parameters('nodes')[copyIndex('vmCopy')]['security_profile']), json('null'), lisa.getSecurityProfile(parameters('nodes')[copyIndex('vmCopy')]['security_profile']))]"
},
"zones": "[if(variables('use_availability_zones'), variables('availability_zones'), json('null'))]"
}
],
"functions": [
{
"namespace": "lisa",
"members": {
"getOsDiskMarketplace": {
"parameters": [
{
"name": "node",
"type": "object"
}
],
"output": {
"type": "object",
"value": {
"publisher": "[parameters('node')['marketplace']['publisher']]",
"offer": "[parameters('node')['marketplace']['offer']]",
"sku": "[parameters('node')['marketplace']['sku']]",
"version": "[parameters('node')['marketplace']['version']]"
}
}
},
"getOsDiskSharedGallery": {
"parameters": [
{
"name": "node",
"type": "object"
}
],
"output": {
"type": "object",
"value": {
"id": "[resourceId(parameters('node')['subscription_id'], if(empty(parameters('node')['resource_group_name']), 'None', parameters('node')['resource_group_name']), 'Microsoft.Compute/galleries/images/versions', parameters('node')['image_gallery'], parameters('node')['image_definition'], parameters('node')['image_version'])]"
}
}
},
"getOsDiskVhd": {
"parameters": [
{
"name": "vmName",
"type": "string"
}
],
"output": {
"type": "object",
"value": {
"id": "[resourceId('Microsoft.Compute/images', concat(parameters('vmName'), '-image'))]"
}
}
},
"getLinuxConfiguration": {
"parameters": [
{
"name": "keyPath",
"type": "string"
},
{
"name": "publicKeyData",
"type": "string"
},
{
"name": "disable_password_authentication",
"type": "bool"
}
],
"output": {
"type": "object",
"value": {
"disablePasswordAuthentication": "[parameters('disable_password_authentication')]",
"ssh": {
"publicKeys": [
{
"path": "[parameters('keyPath')]",
"keyData": "[parameters('publicKeyData')]"
}
]
},
"provisionVMAgent": true
}
}
},
"getOSProfile": {
"parameters": [
{
"name": "computername",
"type": "string"
},
{
"name": "admin_username",
"type": "string"
},
{
"name": "has_password",
"type": "bool"
},
{
"name": "admin_password",
"type": "string"
},
{
"name": "has_linux_configuration",
"type": "bool"
},
{
"name": "linux_configuration",
"type": "object"
}
],
"output": {
"type": "object",
"value": {
"computername": "[parameters('computername')]",
"adminUsername": "[parameters('admin_username')]",
"adminPassword": "[if(parameters('has_password'), parameters('admin_password'), json('null'))]",
"linuxConfiguration": "[if(parameters('has_linux_configuration'), parameters('linux_configuration'), json('null'))]"
}
}
},
"getSecurityProfile": {
"parameters": [
{
"name": "security_profile",
"type": "object"
}
],
"output": {
"type": "object",
"value": {
"uefiSettings": {
"secureBootEnabled": "[parameters('security_profile')['secure_boot']]",
"vTpmEnabled": "true"
},
"securityType": "[parameters('security_profile')['security_type']]"
}
}
},
"getOSImage": {
"parameters": [
{
"name": "node",
"type": "object"
}
],
"output": {
"type": "object",
"value": {
"name": "[concat(parameters('node')['name'], '-osDisk')]",
"managedDisk": {
"storageAccountType": "[parameters('node')['os_disk_type']]",
"securityProfile": "[if(or(empty(parameters('node')['security_profile']), not(equals(parameters('node')['security_profile']['security_type'], 'ConfidentialVM'))), json('null'), json(concat('{\"securityEncryptionType\": \"', parameters('node')['security_profile']['encryption_type'], '\"', if(empty(parameters('node')['security_profile']['disk_encryption_set_id']), '', concat(', \"diskEncryptionSet\": {\"id\": \"', parameters('node')['security_profile']['disk_encryption_set_id'], '\"}')), '}')))]"
},
"caching": "[if(equals(parameters('node')['os_disk_type'], 'Ephemeral'), 'ReadOnly', 'ReadWrite')]",
"createOption": "FromImage",
"diskSizeGB": "[parameters('node')['osdisk_size_in_gb']]"
}
}
},
"getEphemeralOSImage": {
"parameters": [
{
"name": "node",
"type": "object"
}
],
"output": {
"type": "object",
"value": {
"name": "[concat(parameters('node')['name'], '-osDisk')]",
"diffDiskSettings": {
"option": "local",
"placement": "CacheDisk"
},
"caching": "ReadOnly",
"createOption": "FromImage",
"diskSizeGB": "[parameters('node')['osdisk_size_in_gb']]"
}
}
},
"getOSDisk": {
"parameters": [
{
"name": "diskName",
"type": "string"
}
],
"output": {
"type": "object",
"value": {
"createOption": "Attach",
"osType": "Linux",
"managedDisk": {
"id": "[resourceId('Microsoft.Compute/disks', parameters('diskName'))]"
}
}
}
},
"getCreateDisk": {
"parameters": [
{
"name": "disk",
"type": "object"
},
{
"name": "diskName",
"type": "string"
},
{
"name": "index",
"type": "int"
}
],
"output": {
"type": "object",
"value": {
"name": "[parameters('diskName')]",
"createOption": "[parameters('disk').create_option]",
"caching": "[parameters('disk').caching_type]",
"diskSizeGB": "[parameters('disk').size]",
"lun": "[parameters('index')]",
"managedDisk": {
"storageAccountType": "[parameters('disk').type]"
}
}
}
},
"getAttachDisk": {
"parameters": [
{
"name": "disk",
"type": "object"
},
{
"name": "diskName",
"type": "string"
},
{
"name": "index",
"type": "int"
}
],
"output": {
"type": "object",
"value": {
"lun": "[parameters('index')]",
"createOption": "attach",
"caching": "[parameters('disk').caching_type]",
"managedDisk": {
"id": "[resourceId('Microsoft.Compute/disks', parameters('diskName'))]"
}
}
}
}
}
}
]
}

Просмотреть файл

@ -310,8 +310,6 @@ class AzurePlatformSchema:
wait_delete: bool = False
# the AzCopy path can be specified if use this tool to copy blob
azcopy_path: str = field(default="")
# use bicep to deploy, it's a new way to deploy azure resources
use_bicep: bool = True
def __post_init__(self, *args: Any, **kwargs: Any) -> None:
strip_strs(
@ -976,11 +974,7 @@ class AzurePlatform(Platform):
def _load_template(self) -> Any:
if self._arm_template is None:
template_file_name = (
"arm_template.json"
if not self._azure_runbook.use_bicep
else "autogen_arm_template.json"
)
template_file_name = "autogen_arm_template.json"
template_file_path = Path(__file__).parent / template_file_name
with open(template_file_path, "r") as f:
self._arm_template = json.load(f)