| 
 | 1 | +<!-- BEGIN_TF_DOCS -->  | 
 | 2 | +# Multiple VM provisioning example  | 
 | 3 | + | 
 | 4 | +This deploys multiple VMs each with different image.  | 
 | 5 | + | 
 | 6 | +```hcl  | 
 | 7 | +terraform {  | 
 | 8 | +  required_version = "~> 1.5"  | 
 | 9 | +  required_providers {  | 
 | 10 | +    azapi = {  | 
 | 11 | +      source  = "azure/azapi"  | 
 | 12 | +      version = "~> 1.13"  | 
 | 13 | +    }  | 
 | 14 | +    azurerm = {  | 
 | 15 | +      source  = "hashicorp/azurerm"  | 
 | 16 | +      version = "~> 3.74"  | 
 | 17 | +    }  | 
 | 18 | +  }  | 
 | 19 | +}  | 
 | 20 | +
  | 
 | 21 | +provider "azurerm" {  | 
 | 22 | +  features {  | 
 | 23 | +    resource_group {  | 
 | 24 | +      prevent_deletion_if_contains_resources = false  | 
 | 25 | +    }  | 
 | 26 | +  }  | 
 | 27 | +}  | 
 | 28 | +
  | 
 | 29 | +locals {  | 
 | 30 | +  virtual_machines = {  | 
 | 31 | +    vm1 = {  | 
 | 32 | +      is_marketplace_image = true                               # Set to true if the referenced image is from Azure Marketplace.  | 
 | 33 | +      image_name           = "2022-datacenter-azure-edition-01" # Enter the name of the image you would like to use for the VM deployment.  | 
 | 34 | +      logical_network_name = "lnetstatic"                       # Enter the name of the logical network you would like to use for the VM deployment.  | 
 | 35 | +    }  | 
 | 36 | +    vm2 = {  | 
 | 37 | +      is_marketplace_image = true  | 
 | 38 | +      image_name           = "win10-22h2-ent-g2-01"  | 
 | 39 | +      logical_network_name = "lnetstatic"  | 
 | 40 | +    }  | 
 | 41 | +  }  | 
 | 42 | +}  | 
 | 43 | +
  | 
 | 44 | +# This is required for resource modules  | 
 | 45 | +data "azurerm_resource_group" "rg" {  | 
 | 46 | +  name = var.resource_group_name  | 
 | 47 | +}  | 
 | 48 | +
  | 
 | 49 | +data "azapi_resource" "customlocation" {  | 
 | 50 | +  type      = "Microsoft.ExtendedLocation/customLocations@2021-08-15"  | 
 | 51 | +  name      = var.custom_location_name  | 
 | 52 | +  parent_id = data.azurerm_resource_group.rg.id  | 
 | 53 | +}  | 
 | 54 | +
  | 
 | 55 | +data "azapi_resource" "vm_image" {  | 
 | 56 | +  for_each = local.virtual_machines  | 
 | 57 | +
  | 
 | 58 | +  type      = each.value.is_marketplace_image ? "Microsoft.AzureStackHCI/marketplaceGalleryImages@2023-09-01-preview" : "Microsoft.AzureStackHCI/galleryImages@2023-09-01-preview"  | 
 | 59 | +  name      = each.value.image_name  | 
 | 60 | +  parent_id = data.azurerm_resource_group.rg.id  | 
 | 61 | +}  | 
 | 62 | +
  | 
 | 63 | +data "azapi_resource" "logical_network" {  | 
 | 64 | +  for_each = local.virtual_machines  | 
 | 65 | +
  | 
 | 66 | +  type      = "Microsoft.AzureStackHCI/logicalNetworks@2023-09-01-preview"  | 
 | 67 | +  name      = each.value.logical_network_name  | 
 | 68 | +  parent_id = data.azurerm_resource_group.rg.id  | 
 | 69 | +}  | 
 | 70 | +
  | 
 | 71 | +
  | 
 | 72 | +# This is the module call  | 
 | 73 | +# Do not specify location here due to the randomization above.  | 
 | 74 | +# Leaving location as `null` will cause the module to use the resource group location  | 
 | 75 | +# with a data source.  | 
 | 76 | +module "test" {  | 
 | 77 | +  source = "../../"  | 
 | 78 | +  # source             = "Azure/avm-res-azurestackhci-virtualmachineinstance/azurerm"  | 
 | 79 | +  # version            = "~>0.0"  | 
 | 80 | +
  | 
 | 81 | +  for_each = local.virtual_machines  | 
 | 82 | +
  | 
 | 83 | +  enable_telemetry    = var.enable_telemetry  | 
 | 84 | +  resource_group_name = var.resource_group_name  | 
 | 85 | +  location            = data.azurerm_resource_group.rg.location  | 
 | 86 | +  custom_location_id  = data.azapi_resource.customlocation.id  | 
 | 87 | +  name                = each.key  | 
 | 88 | +  image_id            = data.azapi_resource.vm_image[each.key].id  | 
 | 89 | +  logical_network_id  = data.azapi_resource.logical_network[each.key].id  | 
 | 90 | +
  | 
 | 91 | +  admin_username        = var.vm_admin_username  | 
 | 92 | +  admin_password        = var.vm_admin_password  | 
 | 93 | +  v_cpu_count           = var.v_cpu_count  | 
 | 94 | +  memory_mb             = var.memory_mb  | 
 | 95 | +  dynamic_memory        = var.dynamic_memory  | 
 | 96 | +  dynamic_memory_max    = var.dynamic_memory_max  | 
 | 97 | +  dynamic_memory_min    = var.dynamic_memory_min  | 
 | 98 | +  dynamic_memory_buffer = var.dynamic_memory_buffer  | 
 | 99 | +  data_disk_params      = var.data_disk_params  | 
 | 100 | +  private_ip_address    = var.private_ip_address  | 
 | 101 | +  domain_to_join        = var.domain_to_join  | 
 | 102 | +  domain_target_ou      = var.domain_target_ou  | 
 | 103 | +  domain_join_user_name = var.domain_join_user_name  | 
 | 104 | +  domain_join_password  = var.domain_join_password  | 
 | 105 | +
  | 
 | 106 | +
  | 
 | 107 | +  # # Optional block to configure a proxy server for your VM  | 
 | 108 | +  # http_proxy = "http://username:[email protected]:3128"  | 
 | 109 | +  # https_proxy = "https://username:[email protected]:3128"  | 
 | 110 | +  # no_proxy = [  | 
 | 111 | +  #     "localhost",  | 
 | 112 | +  #     "127.0.0.1"  | 
 | 113 | +  # ]  | 
 | 114 | +  # trusted_ca = "-----BEGIN CERTIFICATE-----....-----END CERTIFICATE-----"  | 
 | 115 | +
  | 
 | 116 | +}  | 
 | 117 | +```  | 
 | 118 | + | 
 | 119 | +<!-- markdownlint-disable MD033 -->  | 
 | 120 | +## Requirements  | 
 | 121 | + | 
 | 122 | +The following requirements are needed by this module:  | 
 | 123 | + | 
 | 124 | +- <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) (~> 1.5)  | 
 | 125 | + | 
 | 126 | +- <a name="requirement_azapi"></a> [azapi](#requirement\_azapi) (~> 1.13)  | 
 | 127 | + | 
 | 128 | +- <a name="requirement_azurerm"></a> [azurerm](#requirement\_azurerm) (~> 3.74)  | 
 | 129 | + | 
 | 130 | +## Resources  | 
 | 131 | + | 
 | 132 | +The following resources are used by this module:  | 
 | 133 | + | 
 | 134 | +- [azapi_resource.customlocation](https://registry.terraform.io/providers/azure/azapi/latest/docs/data-sources/resource) (data source)  | 
 | 135 | +- [azapi_resource.logical_network](https://registry.terraform.io/providers/azure/azapi/latest/docs/data-sources/resource) (data source)  | 
 | 136 | +- [azapi_resource.vm_image](https://registry.terraform.io/providers/azure/azapi/latest/docs/data-sources/resource) (data source)  | 
 | 137 | +- [azurerm_resource_group.rg](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/resource_group) (data source)  | 
 | 138 | + | 
 | 139 | +<!-- markdownlint-disable MD013 -->  | 
 | 140 | +## Required Inputs  | 
 | 141 | + | 
 | 142 | +The following input variables are required:  | 
 | 143 | + | 
 | 144 | +### <a name="input_custom_location_name"></a> [custom\_location\_name](#input\_custom\_location\_name)  | 
 | 145 | + | 
 | 146 | +Description: Enter the custom location name of your HCI cluster.  | 
 | 147 | + | 
 | 148 | +Type: `string`  | 
 | 149 | + | 
 | 150 | +### <a name="input_resource_group_name"></a> [resource\_group\_name](#input\_resource\_group\_name)  | 
 | 151 | + | 
 | 152 | +Description: The resource group where the resources will be deployed.  | 
 | 153 | + | 
 | 154 | +Type: `string`  | 
 | 155 | + | 
 | 156 | +### <a name="input_vm_admin_password"></a> [vm\_admin\_password](#input\_vm\_admin\_password)  | 
 | 157 | + | 
 | 158 | +Description: Admin password for the VM  | 
 | 159 | + | 
 | 160 | +Type: `string`  | 
 | 161 | + | 
 | 162 | +## Optional Inputs  | 
 | 163 | + | 
 | 164 | +The following input variables are optional (have default values):  | 
 | 165 | + | 
 | 166 | +### <a name="input_data_disk_params"></a> [data\_disk\_params](#input\_data\_disk\_params)  | 
 | 167 | + | 
 | 168 | +Description: The array description of the dataDisks to attach to the vm. Provide an empty array for no additional disks, or an array following the example below.  | 
 | 169 | + | 
 | 170 | +Type:  | 
 | 171 | + | 
 | 172 | +```hcl  | 
 | 173 | +map(object({  | 
 | 174 | +    name       = string  | 
 | 175 | +    diskSizeGB = number  | 
 | 176 | +    dynamic    = bool  | 
 | 177 | +  }))  | 
 | 178 | +```  | 
 | 179 | + | 
 | 180 | +Default: `{}`  | 
 | 181 | + | 
 | 182 | +### <a name="input_domain_join_password"></a> [domain\_join\_password](#input\_domain\_join\_password)  | 
 | 183 | + | 
 | 184 | +Description: Optional Password of User with permissions to join the domain. - Required if 'domain\_to\_join' is specified.  | 
 | 185 | + | 
 | 186 | +Type: `string`  | 
 | 187 | + | 
 | 188 | +Default: `null`  | 
 | 189 | + | 
 | 190 | +### <a name="input_domain_join_user_name"></a> [domain\_join\_user\_name](#input\_domain\_join\_user\_name)  | 
 | 191 | + | 
 | 192 | +Description: Optional User Name with permissions to join the domain. example: domain-joiner - Required if 'domain\_to\_join' is specified.  | 
 | 193 | + | 
 | 194 | +Type: `string`  | 
 | 195 | + | 
 | 196 | +Default: `""`  | 
 | 197 | + | 
 | 198 | +### <a name="input_domain_target_ou"></a> [domain\_target\_ou](#input\_domain\_target\_ou)  | 
 | 199 | + | 
 | 200 | +Description: Optional domain organizational unit to join. example: ou=computers,dc=contoso,dc=com - Required if 'domain\_to\_join' is specified.  | 
 | 201 | + | 
 | 202 | +Type: `string`  | 
 | 203 | + | 
 | 204 | +Default: `""`  | 
 | 205 | + | 
 | 206 | +### <a name="input_domain_to_join"></a> [domain\_to\_join](#input\_domain\_to\_join)  | 
 | 207 | + | 
 | 208 | +Description: Optional Domain name to join - specify to join the VM to domain. example: contoso.com - If left empty, ou, username and password parameters will not be evaluated in the deployment.  | 
 | 209 | + | 
 | 210 | +Type: `string`  | 
 | 211 | + | 
 | 212 | +Default: `""`  | 
 | 213 | + | 
 | 214 | +### <a name="input_dynamic_memory"></a> [dynamic\_memory](#input\_dynamic\_memory)  | 
 | 215 | + | 
 | 216 | +Description: Enable dynamic memory  | 
 | 217 | + | 
 | 218 | +Type: `bool`  | 
 | 219 | + | 
 | 220 | +Default: `true`  | 
 | 221 | + | 
 | 222 | +### <a name="input_dynamic_memory_buffer"></a> [dynamic\_memory\_buffer](#input\_dynamic\_memory\_buffer)  | 
 | 223 | + | 
 | 224 | +Description: Buffer memory in MB when dynamic memory is enabled  | 
 | 225 | + | 
 | 226 | +Type: `number`  | 
 | 227 | + | 
 | 228 | +Default: `20`  | 
 | 229 | + | 
 | 230 | +### <a name="input_dynamic_memory_max"></a> [dynamic\_memory\_max](#input\_dynamic\_memory\_max)  | 
 | 231 | + | 
 | 232 | +Description: Maximum memory in MB when dynamic memory is enabled  | 
 | 233 | + | 
 | 234 | +Type: `number`  | 
 | 235 | + | 
 | 236 | +Default: `8192`  | 
 | 237 | + | 
 | 238 | +### <a name="input_dynamic_memory_min"></a> [dynamic\_memory\_min](#input\_dynamic\_memory\_min)  | 
 | 239 | + | 
 | 240 | +Description: Minimum memory in MB when dynamic memory is enabled  | 
 | 241 | + | 
 | 242 | +Type: `number`  | 
 | 243 | + | 
 | 244 | +Default: `512`  | 
 | 245 | + | 
 | 246 | +### <a name="input_enable_telemetry"></a> [enable\_telemetry](#input\_enable\_telemetry)  | 
 | 247 | + | 
 | 248 | +Description: This variable controls whether or not telemetry is enabled for the module.    | 
 | 249 | +For more information see <https://aka.ms/avm/telemetryinfo>.    | 
 | 250 | +If it is set to false, then no telemetry will be collected.  | 
 | 251 | + | 
 | 252 | +Type: `bool`  | 
 | 253 | + | 
 | 254 | +Default: `true`  | 
 | 255 | + | 
 | 256 | +### <a name="input_memory_mb"></a> [memory\_mb](#input\_memory\_mb)  | 
 | 257 | + | 
 | 258 | +Description: Memory in MB  | 
 | 259 | + | 
 | 260 | +Type: `number`  | 
 | 261 | + | 
 | 262 | +Default: `8192`  | 
 | 263 | + | 
 | 264 | +### <a name="input_private_ip_address"></a> [private\_ip\_address](#input\_private\_ip\_address)  | 
 | 265 | + | 
 | 266 | +Description: The private IP address of the NIC  | 
 | 267 | + | 
 | 268 | +Type: `string`  | 
 | 269 | + | 
 | 270 | +Default: `""`  | 
 | 271 | + | 
 | 272 | +### <a name="input_v_cpu_count"></a> [v\_cpu\_count](#input\_v\_cpu\_count)  | 
 | 273 | + | 
 | 274 | +Description: Number of vCPUs  | 
 | 275 | + | 
 | 276 | +Type: `number`  | 
 | 277 | + | 
 | 278 | +Default: `2`  | 
 | 279 | + | 
 | 280 | +### <a name="input_vm_admin_username"></a> [vm\_admin\_username](#input\_vm\_admin\_username)  | 
 | 281 | + | 
 | 282 | +Description:  The admin username for the VM.  | 
 | 283 | + | 
 | 284 | +Type: `string`  | 
 | 285 | + | 
 | 286 | +Default: `"admin"`  | 
 | 287 | + | 
 | 288 | +## Outputs  | 
 | 289 | + | 
 | 290 | +No outputs.  | 
 | 291 | + | 
 | 292 | +## Modules  | 
 | 293 | + | 
 | 294 | +The following Modules are called:  | 
 | 295 | + | 
 | 296 | +### <a name="module_test"></a> [test](#module\_test)  | 
 | 297 | + | 
 | 298 | +Source: ../../  | 
 | 299 | + | 
 | 300 | +Version:  | 
 | 301 | + | 
 | 302 | +<!-- markdownlint-disable-next-line MD041 -->  | 
 | 303 | +## Data Collection  | 
 | 304 | + | 
 | 305 | +The software may collect information about you and your use of the software and send it to Microsoft. Microsoft may use this information to provide services and improve our products and services. You may turn off the telemetry as described in the repository. There are also some features in the software that may enable you and Microsoft to collect data from users of your applications. If you use these features, you must comply with applicable law, including providing appropriate notices to users of your applications together with a copy of Microsoft’s privacy statement. Our privacy statement is located at <https://go.microsoft.com/fwlink/?LinkID=824704>. You can learn more about data collection and use in the help documentation and our privacy statement. Your use of the software operates as your consent to these practices.  | 
 | 306 | +<!-- END_TF_DOCS -->  | 
0 commit comments