Skip to content

Commit

Permalink
Add variable delete_data_disks_on_termination (#170)
Browse files Browse the repository at this point in the history
* update

* update

* update

* update

* update

* update

Co-authored-by: root <root@ubuntu-wyp.4smfdm3ngeyufpdz0muw5zebpc.bx.internal.cloudapp.net>
  • Loading branch information
yupwei68 and root authored May 24, 2021
1 parent 97dc8ac commit ce71f7e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 36 deletions.
37 changes: 19 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,24 +182,25 @@ data "azurerm_key_vault_certificate" "example" {
}
module "linuxservers" {
source = "Azure/compute/azurerm"
resource_group_name = azurerm_resource_group.example.name
vm_hostname = "mylinuxvm"
nb_public_ip = 0
remote_port = "22"
nb_instances = 2
vm_os_publisher = "Canonical"
vm_os_offer = "UbuntuServer"
vm_os_sku = "18.04-LTS"
vnet_subnet_id = module.network.vnet_subnets[0]
boot_diagnostics = true
delete_os_disk_on_termination = true
nb_data_disk = 2
data_disk_size_gb = 64
data_sa_type = "Premium_LRS"
enable_ssh_key = true
ssh_key_values = ["ssh-rsa AAAAB3NzaC1yc2EAAAAD..."]
vm_size = "Standard_D4s_v3"
source = "Azure/compute/azurerm"
resource_group_name = azurerm_resource_group.example.name
vm_hostname = "mylinuxvm"
nb_public_ip = 0
remote_port = "22"
nb_instances = 2
vm_os_publisher = "Canonical"
vm_os_offer = "UbuntuServer"
vm_os_sku = "18.04-LTS"
vnet_subnet_id = module.network.vnet_subnets[0]
boot_diagnostics = true
delete_os_disk_on_termination = true
nb_data_disk = 2
data_disk_size_gb = 64
data_sa_type = "Premium_LRS"
enable_ssh_key = true
ssh_key_values = ["ssh-rsa AAAAB3NzaC1yc2EAAAAD..."]
vm_size = "Standard_D4s_v3"
delete_data_disks_on_termination = true
tags = {
environment = "dev"
Expand Down
17 changes: 9 additions & 8 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ resource "azurerm_storage_account" "vm-sa" {
}

resource "azurerm_virtual_machine" "vm-linux" {
count = ! contains(tolist([var.vm_os_simple, var.vm_os_offer]), "WindowsServer") && ! var.is_windows_image ? var.nb_instances : 0
name = "${var.vm_hostname}-vmLinux-${count.index}"
resource_group_name = data.azurerm_resource_group.vm.name
location = coalesce(var.location, data.azurerm_resource_group.vm.location)
availability_set_id = azurerm_availability_set.vm.id
vm_size = var.vm_size
network_interface_ids = [element(azurerm_network_interface.vm.*.id, count.index)]
delete_os_disk_on_termination = var.delete_os_disk_on_termination
count = ! contains(tolist([var.vm_os_simple, var.vm_os_offer]), "WindowsServer") && ! var.is_windows_image ? var.nb_instances : 0
name = "${var.vm_hostname}-vmLinux-${count.index}"
resource_group_name = data.azurerm_resource_group.vm.name
location = coalesce(var.location, data.azurerm_resource_group.vm.location)
availability_set_id = azurerm_availability_set.vm.id
vm_size = var.vm_size
network_interface_ids = [element(azurerm_network_interface.vm.*.id, count.index)]
delete_os_disk_on_termination = var.delete_os_disk_on_termination
delete_data_disks_on_termination = var.delete_data_disks_on_termination

dynamic identity {
for_each = length(var.identity_ids) == 0 && var.identity_type == "SystemAssigned" ? [var.identity_type] : []
Expand Down
21 changes: 11 additions & 10 deletions test/fixture/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,17 @@ module "debianservers" {
}

module "debianservers2" {
source = "../../"
vm_hostname = "${random_id.ip_dns.hex}-d2"
resource_group_name = azurerm_resource_group.test.name
location = var.location_alt
admin_username = var.admin_username
vm_os_simple = var.vm_os_simple_2
vnet_subnet_id = azurerm_subnet.subnet2.id
enable_ssh_key = true
ssh_key = ""
ssh_key_values = ["ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC8GIRF1Snlg9NKCmM74RHXqRGMXyui088+ntQqkQkFIL/BrlgP3CzOgHQmJ+3f0Up/+9UY9vX7AmT7WxVTyqBHT/Aes3VmU3wLO5/MMV/HRrT4z2QV/80futhxjk2unNdWGvbFcR6Y3I44EJFmr8GMbyXRtr0ibuv8BlTYx/K6AXSJ3V+kBqXMOF1QRvVoX9fJKPKjMsebe0cB1IYlm9KLqtciMy+aFOEsSNfrw5cNVsQfK3BgOUKAHsLfBiR7imA2ca+hh005GEtcVJvpvFzcM+bZggUpdqQwIzk1Kv/tROiJiGS0NnyzoxIZYeM3z/mQ5qnglp+174XGCG66EAnVdf5kbaI0Iu7FpAmVhJ92N+MNKoP6vT8cMkYYZf3RaiMMnzjswK/VLbb5ks6Qe9qEPXW1IBtkaaF7+0PCWbPr86I0G2bOa2tFyOHm046Z9sRlkaOO95hmer6Y6MUbMpfeprmjR87u6MVOPglnARfV3UI9i6wOUhVVIi6Wb424HWU="]
source = "../../"
vm_hostname = "${random_id.ip_dns.hex}-d2"
resource_group_name = azurerm_resource_group.test.name
location = var.location_alt
admin_username = var.admin_username
vm_os_simple = var.vm_os_simple_2
vnet_subnet_id = azurerm_subnet.subnet2.id
enable_ssh_key = true
delete_data_disks_on_termination = true
ssh_key = ""
ssh_key_values = ["ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC8GIRF1Snlg9NKCmM74RHXqRGMXyui088+ntQqkQkFIL/BrlgP3CzOgHQmJ+3f0Up/+9UY9vX7AmT7WxVTyqBHT/Aes3VmU3wLO5/MMV/HRrT4z2QV/80futhxjk2unNdWGvbFcR6Y3I44EJFmr8GMbyXRtr0ibuv8BlTYx/K6AXSJ3V+kBqXMOF1QRvVoX9fJKPKjMsebe0cB1IYlm9KLqtciMy+aFOEsSNfrw5cNVsQfK3BgOUKAHsLfBiR7imA2ca+hh005GEtcVJvpvFzcM+bZggUpdqQwIzk1Kv/tROiJiGS0NnyzoxIZYeM3z/mQ5qnglp+174XGCG66EAnVdf5kbaI0Iu7FpAmVhJ92N+MNKoP6vT8cMkYYZf3RaiMMnzjswK/VLbb5ks6Qe9qEPXW1IBtkaaF7+0PCWbPr86I0G2bOa2tFyOHm046Z9sRlkaOO95hmer6Y6MUbMpfeprmjR87u6MVOPglnARfV3UI9i6wOUhVVIi6Wb424HWU="]

depends_on = [azurerm_resource_group.test]
}
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ variable "delete_os_disk_on_termination" {
default = false
}

variable "delete_data_disks_on_termination" {
type = bool
description = "Delete data disks when machine is terminated."
default = false
}

variable "data_sa_type" {
description = "Data Disk Storage Account type."
type = string
Expand Down

0 comments on commit ce71f7e

Please sign in to comment.