I've tried and successfully created VMSS with os_disk and data_disk together. but i've requirement like when value of "data_disk==0" then i need to skip the creation of Data_disk. I've tried with value 0 but its clearly asking me to set value between(1-32767) . Here is my successful code
provider "azurerm" {
features{}
}
resource "azurerm_resource_group" "vmss" {
name = var.resourcegroup
location = var.location
}
resource "azurerm_windows_virtual_machine_scale_set" "vmss" {
name = var.vmss_name
resource_group_name = azurerm_resource_group.vmss.name
location = azurerm_resource_group.vmss.location
sku = var.vm_sku
instances = var.instancescount
computer_name_prefix = var.computer_name_prefix
admin_password = var.vmpassword
admin_username = var.vmusername
provision_vm_agent = true
overprovision = false
source_image_reference {
publisher = var.publisher
offer = var.offer
sku = var.os_sku
version = var.image_version
}
os_disk {
storage_account_type = var.os_disk_type
caching = "ReadWrite"
disk_size_gb = var.os_disk_size
}
data_disk{
lun = 1
storage_account_type = var.data_disk_type
caching = "ReadWrite"
disk_size_gb = var.data_disk_size
}
winrm_listener {
protocol = "Http"
}
additional_unattend_content{
content = "<AutoLogon><Password><Value>${var.vmpassword}</Value></Password><Enabled>true</Enabled><LogonCount>1</LogonCount><Username>${var.vmusername}</Username></AutoLogon>"
setting = "AutoLogon"
}
# Unattend config is to enable basic auth in WinRM, required for the provisioner stage.
additional_unattend_content {
setting = "FirstLogonCommands"
content = file("./files/FirstLogonCommands.xml")
}
network_interface {
name = "${var.computer_name_prefix}-profile"
primary = true
ip_configuration {
name = "${var.computer_name_prefix}-IPConfig"
primary = true
subnet_id = var.subnet
}
}
}
Can anyone help me to skip the data_disk creation when the value is 0.
Thanks in Advance.
Thanks, Siva