The Yalkut Yosef 285/32 states that the obligation to affix a mezuzah on a balcony depends on two specific criteria. If the balcony has a roof and a minimum area of two meters by two meters, it is mandatory to place a mezuzah on the door leading to it.
However, Rav Yitzchak Yosef clarifies that if the balcony has an area greater than four square meters, but one of its sides is less than two meters long (for example, one meter in width and five meters in length), then there is no obligation to place a mezuzah.
Nevertheless, for those who wish to install a mezuzah on a balcony that does not meet these two conditions out of piety, it is allowed. However, one should refrain from reciting the blessing (berakhah) when doing so.
The mezuzah should be placed on the right side when exiting the apartment towards the balcony.
Regarding courtyards or terraces located on the ground floor, which provide access to the house from the public domain, the mezuzah should be placed on the opposite side, that is, on the right side when entering the house, and in this case, the blessing (berakhah) should be recited.