Edits per Code Review
This commit is contained in:
parent
c7bd6dc586
commit
40ac990971
@ -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"
|
||||
}
|
@ -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
|
||||
}
|
@ -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
|
||||
|
||||
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user