My terraform code is below which deploys certain number of resources based on variable rdsh_count
.
I need this resource to deploy conditionally only if variable deploy
is set to true
, normally I would use count keyword but it’s not going to work here since this resource already have it. How this can be accomplished?
resource "azapi_resource_action" "stop-vm" {
count = var.rdsh_count
type = "Microsoft.Compute/virtualMachines@2024-03-01"
resource_id = azurerm_windows_virtual_machine.avd_vm.*.id[count.index]
action = "deallocate"
response_export_values = ["*"]
depends_on = [
azurerm_virtual_machine_extension.boot_strap
]
}
resource “azapi_resource_action” “stop-vm” {
count = var.enabled ? var.rdsh_count: 0
type = “Microsoft.Compute/virtualMachines@2024-03-01”
resource_id = azurerm_windows_virtual_machine.avd_vm..id[count.index]
action = “deallocate”
response_export_values = [““]
depends_on = [
azurerm_virtual_machine_extension.boot_strap
]
}