diff --git a/quickstart/101-vm-cluster-linux/main.tf b/quickstart/101-vm-cluster-linux/main.tf index d86a1944..4acef897 100644 --- a/quickstart/101-vm-cluster-linux/main.tf +++ b/quickstart/101-vm-cluster-linux/main.tf @@ -65,16 +65,6 @@ resource "azurerm_network_interface" "test" { } } -resource "azurerm_managed_disk" "test" { - count = 2 - name = "datadisk_existing_${count.index}" - location = azurerm_resource_group.rg.location - resource_group_name = azurerm_resource_group.rg.name - storage_account_type = "Standard_LRS" - create_option = "Empty" - disk_size_gb = "1023" -} - resource "azurerm_availability_set" "avset" { name = "avset" location = azurerm_resource_group.rg.location @@ -88,13 +78,27 @@ resource "random_pet" "azurerm_linux_virtual_machine_name" { prefix = "vm" } +resource "random_password" "password" { + count = var.password == null ? 1 : 0 + length = 20 + special = true + min_numeric = 1 + min_upper = 1 + min_lower = 1 + min_special = 1 +} + +locals { + password = try(random_password.password[0].result, var.password) +} + resource "azurerm_linux_virtual_machine" "test" { count = 2 name = "${random_pet.azurerm_linux_virtual_machine_name.id}${count.index}" location = azurerm_resource_group.rg.location availability_set_id = azurerm_availability_set.avset.id resource_group_name = azurerm_resource_group.rg.name - network_interface_ids = [element(azurerm_network_interface.test.*.id, count.index)] + network_interface_ids = [azurerm_network_interface.test[count.index].id] size = "Standard_DS1_v2" # Uncomment this line to delete the OS disk automatically when deleting the VM @@ -117,7 +121,25 @@ resource "azurerm_linux_virtual_machine" "test" { } computer_name = "hostname" - admin_username = "testadmin" - admin_password = "Password1234!" + admin_username = var.user_name + admin_password = local.password disable_password_authentication = false +} + +resource "azurerm_managed_disk" "test" { + count = 2 + name = "datadisk_existing_${count.index}" + location = azurerm_resource_group.rg.location + resource_group_name = azurerm_resource_group.rg.name + storage_account_type = "Standard_LRS" + create_option = "Empty" + disk_size_gb = "1023" +} + +resource "azurerm_virtual_machine_data_disk_attachment" "test" { + count = 2 + managed_disk_id = azurerm_managed_disk.test[count.index].id + virtual_machine_id = azurerm_linux_virtual_machine.test[count.index].id + lun = "10" + caching = "ReadWrite" } \ No newline at end of file diff --git a/quickstart/101-vm-cluster-linux/outputs.tf b/quickstart/101-vm-cluster-linux/outputs.tf index ebd79188..ef67ce10 100644 --- a/quickstart/101-vm-cluster-linux/outputs.tf +++ b/quickstart/101-vm-cluster-linux/outputs.tf @@ -2,14 +2,19 @@ output "resource_group_name" { value = azurerm_resource_group.rg.name } -output "azurerm_virtual_network_name" { +output "virtual_network_name" { value = azurerm_virtual_network.test.name } -output "azurerm_subnet_name" { +output "subnet_name" { value = azurerm_subnet.test.name } -output "azurerm_linux_virtual_machine_names2" { - value = [for s in azurerm_linux_virtual_machine.test : s.name[*]] +output "linux_virtual_machine_names" { + value = [for s in azurerm_linux_virtual_machine.test : s.name[*]] +} + +output "linux_virtual_machine_password" { + sensitive = true + value = local.password } \ No newline at end of file diff --git a/quickstart/101-vm-cluster-linux/readme.md b/quickstart/101-vm-cluster-linux/readme.md index d75db11e..4ad966db 100644 --- a/quickstart/101-vm-cluster-linux/readme.md +++ b/quickstart/101-vm-cluster-linux/readme.md @@ -14,6 +14,7 @@ This template deploys a Linux VM cluster on Azure. - [azurerm_network_interface](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_interface) - [azurerm_managed_disk](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/managed_disk) - [azurerm_availability_set](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/availability_set) +- [random_password](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/password) - [azurerm_linux_virtual_machine](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/linux_virtual_machine) ## Variables @@ -22,6 +23,8 @@ This template deploys a Linux VM cluster on Azure. |-|-|-| | `resource_group_name_prefix` | Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription. | rg | | `resource_group_location` | Location of the resource group. | eastus | +| `user_name` | The username for the local account that will be created on the new VM. | | +| `password` | The password for the local account that will be created on the new VM. | | ## Example diff --git a/quickstart/101-vm-cluster-linux/variables.tf b/quickstart/101-vm-cluster-linux/variables.tf index 22a8f6a5..e8eb8b6f 100644 --- a/quickstart/101-vm-cluster-linux/variables.tf +++ b/quickstart/101-vm-cluster-linux/variables.tf @@ -8,4 +8,17 @@ variable "resource_group_name_prefix" { type = string description = "Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription." default = "rg" -} \ No newline at end of file +} + +variable "user_name" { + type = string + description = "The username for the local account that will be created on the new vm." + default = "exampleuser" +} + +variable "password" { + type = string + description = "The password for the local account that will be created on the new vm." + sensitive = true + default = null +}