I am trying to create VMs for both cluster and single node deployments.
resource "azurerm_virtual_machine" "app" {
name = "${var.name_prefix}-${format("%02d", count.index+1)}"
location = "${var.location}"
resource_group_name = "${azurerm_resource_group.resourcegroup.name}"
availability_set_id = "${azurerm_availability_set.avset.id}"
network_interface_ids = ["${element(azurerm_network_interface.networkinterface-app.*.id, count.index+1)}"]
vm_size = "${var.vm_size}"
count = "${var.app_nodes}"
The setup works well for the cluster node deployments with availability_set_id
configured but fails as in single node I don't have a need to configure availability_set_id
.
I am using Terraform v0.11.2
and * provider.azurerm: version = "~> 1.0"
as versions of terraform and azurerm provider currently.
Can anyone help me how to use a conditional in this case to handle both scenarios?
I think you need to wrap it in a module and then have two resources and use count = "${var.somecond ? 1 : 0}"
do determine which one is active.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With