Availability Zone Selections with the SkySQL DBaaS API

Overview

This reference page details how to select availability zones with the SkySQL DBaaS API for SkySQL.

SkySQL is available in regions worldwide on Amazon AWS and Google GCP.

REST Client

A REST client can use the SkySQL DBaaS API to query availability zone selections and choose an availability zone for a new service.

Query Options with REST Client

A REST client can query the SkySQL DBaaS API for the availability zone selections for a specific cloud provider and region.

To see the available availability zones for a cloud provider and region, use curl to call the /provisioning/v1/regions/REGION_NAME/zones API endpoint:

$ curl -sS --location \
   --header "Authorization: Bearer ${SKYSQL_API_KEY}" \
   'https://api.mariadb.com/provisioning/v1/regions/us-central1/zones?provider=gcp' \
   | jq .
[
  {
    "id": "fd09d26d-13d3-4692-bda9-4edba4c28597",
    "name": "us-central1-c",
    "region_name": "us-central1",
    "provider": "gcp"
  },
  {
    "id": "30888136-ee5e-49e8-8f03-dbbd476ae7da",
    "name": "us-central1-a",
    "region_name": "us-central1",
    "provider": "gcp"
  },
  {
    "id": "10d845b4-185e-4e35-965a-1fb8cc19c72c",
    "name": "us-central1-f",
    "region_name": "us-central1",
    "provider": "gcp"
  },
  {
    "id": "01e5309d-24d4-4c67-a662-a2976c9e4277",
    "name": "us-central1-b",
    "region_name": "us-central1",
    "provider": "gcp"
  }
]

For the availability zone that you would like to select, extract the name attribute from the output and provide that value to the /provisioning/v1/services API endpoint as the availability_zone attribute.

Select Option with REST Client

An availability zone is selected during service launch. When using a REST client, select an availability zone by calling the /provisioning/v1/services API endpoint with the availability_zone attribute set.

For example, prepare a request body containing the desired service options in a file called request-service.json:

$ cat > request-service.json <<EOF
{
  "service_type": "transactional",
  "topology": "es-single",
  "provider": "gcp",
  "region": "us-central1",
  "availability_zone": "us-central1-a",
  "architecture": "amd64",
  "size": "sky-2x8",
  "storage": 100,
  "nodes": 1,
  "version": "10.6.11-6-1",
  "name": "skysql-nr-quickstart",
  "ssl_enabled": true
}
EOF

Then use curl to call the /provisioning/v1/services API endpoint to create (launch) a new database service and save the response to the response-service.json file:

$ curl -sS --location --request POST \
   --header "Authorization: Bearer ${SKYSQL_API_KEY}" \
   --header "Accept: application/json" \
   --header "Content-type: application/json" \
   --data '@request-service.json' \
   https://api.mariadb.com/provisioning/v1/services \
   | tee response-service.json | jq .

Upon success, the command will return JSON with details about the new service.

Terraform

Terraform can use the SkySQL Terraform provider to query availability zone selections and choose an availability zone for a new service.

Query Options with Terraform

Terraform can query the SkySQL Terraform provider for the availability zone selections for a specific cloud provider and region using the skysql_availability_zones data source:

data "skysql_availability_zones" "default" {
  region              = var.region
  filter_by_provider  = var.cloud_provider
}

Select Options with Terraform

When using Terraform, select an availability zone using the availability_zone attribute for the skysql_service resource:

# Create a service
resource "skysql_service" "default" {
  service_type        = "transactional"
  topology            = "es-single"
  cloud_provider      = "gcp"
  region              = "us-central1"
  availability_zone   = coalesce(var.availability_zones, data.skysql_availability_zones.default.zones[0].name)
  architecture        = "amd64"
  size                = "sky-2x8"
  storage             = 100
  nodes               = 1
  version             = "10.6.11-6-1"
  name                = "skysql-nr-quickstart"
  ssl_enabled         = true
  deletion_protection = true
  wait_for_creation   = true
  wait_for_deletion   = true
  wait_for_update     = true
  is_active           = true
}

In the above example, the coalesce() function is used to take the first non-null value from the availability_zone variable or the skysql_availability_zones data source.