Again, I am not clear on what you mean by the following as you have not provided broader context with regards to the resource block (or module) that this is feeding into:
On the face of it, and based upon your use of count (presuming it is being used on the resource/module attribute as opposed to within a .tfvars
or similar), then the way you are applying the ternary operator appears correct, but is obviously not working as expected in your situation due to the broader code in the module.
The first thing I would say is that count is a good way to produce multiple identical instances of the same resource, but not so flexible when it comes to producing multiple instances of the resource that may vary based upon different input variables and criteria. Count can also have broader impacts when removing / adding anything except at the last index so typically it is only used if there is no better approach.
Therefore, my first suggestion would be to consider refactoring your code to use the for_each
meta argument. You can still set the defaults in the input variable attributes as you have but would pass in a map-of-objects. Assuming the input variable and defaults are set as follows (Note this is a contrived example based upon what you have provided):
vms = map(object({
size = optional(string, "Standard_EC16as_v5")
os_disk = optional(object({
caching = optional(string, "ReadWrite")
storage_type = optional(string, "Standard_LRS")
size = optional(number,1000)
})
}
})
Then your input variable could be:
vms=[
vm1 = {}, # Uses all default vaules
vm2 = {
os_disk = {
size = 1500 # Uses all default values except this attribute
},
vm3 = {} # Uses all default values.
]
This approach also allows flexibility to alter other attributes in other instances of the same resource in the future.
Another possible (but less flexible and likely more brittle) would be to change the size attribute to be a list: size = list(number)
and then reference the index of that list. Passing in a list of numbers that correspond to the required disk sizes [1000,1500,1000].