Skip to content

Commit ce71f7e

Browse files
yupwei68root
andauthored
Add variable delete_data_disks_on_termination (#170)
* update * update * update * update * update * update Co-authored-by: root <root@ubuntu-wyp.4smfdm3ngeyufpdz0muw5zebpc.bx.internal.cloudapp.net>
1 parent 97dc8ac commit ce71f7e

File tree

4 files changed

+45
-36
lines changed

4 files changed

+45
-36
lines changed

README.md

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -182,24 +182,25 @@ data "azurerm_key_vault_certificate" "example" {
182182
}
183183
184184
module "linuxservers" {
185-
source = "Azure/compute/azurerm"
186-
resource_group_name = azurerm_resource_group.example.name
187-
vm_hostname = "mylinuxvm"
188-
nb_public_ip = 0
189-
remote_port = "22"
190-
nb_instances = 2
191-
vm_os_publisher = "Canonical"
192-
vm_os_offer = "UbuntuServer"
193-
vm_os_sku = "18.04-LTS"
194-
vnet_subnet_id = module.network.vnet_subnets[0]
195-
boot_diagnostics = true
196-
delete_os_disk_on_termination = true
197-
nb_data_disk = 2
198-
data_disk_size_gb = 64
199-
data_sa_type = "Premium_LRS"
200-
enable_ssh_key = true
201-
ssh_key_values = ["ssh-rsa AAAAB3NzaC1yc2EAAAAD..."]
202-
vm_size = "Standard_D4s_v3"
185+
source = "Azure/compute/azurerm"
186+
resource_group_name = azurerm_resource_group.example.name
187+
vm_hostname = "mylinuxvm"
188+
nb_public_ip = 0
189+
remote_port = "22"
190+
nb_instances = 2
191+
vm_os_publisher = "Canonical"
192+
vm_os_offer = "UbuntuServer"
193+
vm_os_sku = "18.04-LTS"
194+
vnet_subnet_id = module.network.vnet_subnets[0]
195+
boot_diagnostics = true
196+
delete_os_disk_on_termination = true
197+
nb_data_disk = 2
198+
data_disk_size_gb = 64
199+
data_sa_type = "Premium_LRS"
200+
enable_ssh_key = true
201+
ssh_key_values = ["ssh-rsa AAAAB3NzaC1yc2EAAAAD..."]
202+
vm_size = "Standard_D4s_v3"
203+
delete_data_disks_on_termination = true
203204
204205
tags = {
205206
environment = "dev"

main.tf

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@ resource "azurerm_storage_account" "vm-sa" {
3030
}
3131

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

4243
dynamic identity {
4344
for_each = length(var.identity_ids) == 0 && var.identity_type == "SystemAssigned" ? [var.identity_type] : []

test/fixture/main.tf

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,17 @@ module "debianservers" {
104104
}
105105

106106
module "debianservers2" {
107-
source = "../../"
108-
vm_hostname = "${random_id.ip_dns.hex}-d2"
109-
resource_group_name = azurerm_resource_group.test.name
110-
location = var.location_alt
111-
admin_username = var.admin_username
112-
vm_os_simple = var.vm_os_simple_2
113-
vnet_subnet_id = azurerm_subnet.subnet2.id
114-
enable_ssh_key = true
115-
ssh_key = ""
116-
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="]
107+
source = "../../"
108+
vm_hostname = "${random_id.ip_dns.hex}-d2"
109+
resource_group_name = azurerm_resource_group.test.name
110+
location = var.location_alt
111+
admin_username = var.admin_username
112+
vm_os_simple = var.vm_os_simple_2
113+
vnet_subnet_id = azurerm_subnet.subnet2.id
114+
enable_ssh_key = true
115+
delete_data_disks_on_termination = true
116+
ssh_key = ""
117+
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="]
117118

118119
depends_on = [azurerm_resource_group.test]
119120
}

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ variable "delete_os_disk_on_termination" {
160160
default = false
161161
}
162162

163+
variable "delete_data_disks_on_termination" {
164+
type = bool
165+
description = "Delete data disks when machine is terminated."
166+
default = false
167+
}
168+
163169
variable "data_sa_type" {
164170
description = "Data Disk Storage Account type."
165171
type = string

0 commit comments

Comments
 (0)