Availability Domains

With respect to Availability Domains, we caution against a common pattern, as shown here:

// Get all availability domains for the region
data "oci_identity_availability_domains" "ads" {
compartment_id = "${var.tenancy_ocid}"
}
// Then either use it to get a single AD name based on the index:
resource "oci_core_instance" "nat" {
availability_domain = "${lookup(data.oci_identity_availability_domains.ads.availability_domains[var.nat_instance_ad],"name")}"
...
}
// Or iterate through all the ADs:
resource "oci_core_subnet" "nat" {
count = "${length(data.oci_identity_availability_domains.ads.availability_domains)}"
availability_domain = "${lookup(data.oci_identity_availability_domains.ad.availability_domains[count.index], "name")}"
...
}

The recommendation, then, is to explicitly list the Availability Domain names for the regions in your configuration. To do so, use a variable that you have defined as follows:

The advantage of using this method is that it gives you control over your availability domain usage and prevents unexpected changes over time. However, this approach is problematic when configurations are shared between tenancies and regions, since availability domain names are tenancy- and region-specific.

A convenient alternative is to instead set the ad_list value by using the oci_identity_availability_domains data source. You should do this in the configuration, then pass them into the modules. This effectively centralizes the list of ADs, making it is easy to switch to an explicit list later, should that become necessary: Note that the modules themselves should not use the oci_identity_availability_domains data source.