MariaDB SkySQL DBaaS API Terraform Provider

Overview

The MariaDB SkySQL DBaaS API Terraform Provider allows database services in MariaDB SkySQL to be managed using Terraform:

  • It allows SkySQL services to be configured using Terraform's declarative language

  • It automatically provisions new SkySQL services when the Terraform configuration is applied

  • It automatically tears down SkySQL services when the Terraform configuration is destroyed

Terraform is an open source infrastructure-as-code (IaC) utility.

The MariaDB SkySQL DBaaS API Terraform Provider is a Technical Preview. Software in Tech Preview should not be used for production workloads.

Alternatively, SkySQL services can be managed interactively using your web browser and the SkySQL Portal.

Use Cases

The MariaDB SkySQL DBaaS API Terraform Provider supports use cases that require managing database services in MariaDB SkySQL using Terraform:

  • Add MariaDB SkySQL to existing Terraform-managed infrastructure

  • Build new Terraform-managed infrastructure that includes MariaDB SkySQL

  • Replace another database platform with MariaDB SkySQL in existing Terraform-managed infrastructure

Compatibility

  • The MariaDB SkySQL DBaaS API Terraform provider requires Terraform 0.13.x or later

Installation

Terraform automatically installs the Terraform provider from the Terraform registry when configured to use the provider.

Authentication and Authorization

The MariaDB SkySQL DBaaS API requires authentication and authorization.

To authenticate and authorize with the API, perform the following procedure:

  1. Sign up for SkySQL

  2. Obtain a SkySQL API key

  3. Configure Terraform to use the API key.

    The Terraform provider reads the SkySQL API key from the TF_SKYSQL_API_KEY environment variable.

    Configure your API key by setting the environment variable:

    $ export TF_SKYSQL_API_KEY='YOUR_SKYSQL_API_KEY'
    

Walkthrough

The walkthrough below shows how to configure the SkySQL Terraform provider and how to apply the configuration.

Multiple components must be configured to create a service with the Terraform provider. For details on Terraform's configuration details, see "Terraform Language Documentation".

Step 1: Configure the skysql Provider

The skysql provider is Terraform's interface with the MariaDB SkySQL DBaaS API.

Terraform must be configured to require the skysql provider. Terraform automatically installs the provider from the Terraform registry.

In a Terraform configuration file, configure Terraform to use the skysql provider:

provider "skysql" { }

Step 2: Configure the skysql_service Resource

The skysql_service resource is used to define a SkySQL service to be provisioned by Terraform.

When provisioning a new SkySQL service, a skysql_service resource must be configured in a Terraform configuration file.

In a Terraform configuration file, create a Single Node Transactions service in AWS:

resource "skysql_service" "wat" {
  release_version = "MariaDB Enterprise Server 10.6.4-1"
  topology        = "Single Node Transactions"
  size            = "Sky-2x8"
  tx_storage      = "100"
  name            = "doc-test-tx-single"
  region          = "us-east-2"
  cloud_provider  = "AWS"
  replicas        = "0"
  volume_iops     = "100"
  tier            = "Foundation"
}

Step 3: Configure the skysql_credentials Data Source

The skysql_credentials data source is used to retrieve the default database credentials of a SkySQL service.

When provisioning a new SkySQL service, the skysql_credentials data source should get the service ID from the skysql_service resource.

In a Terraform configuration file, configure Terraform to retrieve the default database credentials:

data "skysql_credentials" "wat" {
  id = skysql_service.wat.id
}

Step 4: Integrate the skysql_service Resource into Configuration

If you have an existing Terraform configuration, the skysql_service resource must be integrated into that configuration.

Step 5: Initialize Terraform Working Directory

The Terraform working directory must be initialized.

Use the terraform init_ command to initialize the Terraform working directory:

$ terraform init

Step 6: Check Terraform Plan

Before applying the Terraform configuration, the Terraform execution plan can optionally be previewed.

Use the terraform plan_ command to preview the Terraform execution plan:

$ terraform plan

Step 7: Start Services

The Terraform execution plan can be applied. When it is applied, Terraform starts the SkySQL services and creates the other infrastructure defined in the configuration.

Use the terraform apply_ command to apply the Terraform execution plan:

$ terraform apply

Step 8: Tear Down

The Terraform infrastructure can be destroyed. When it is destroyed, Terraform deletes the SkySQL services and the other infrastructure defined in the configuration.

Use the terraform destroy_ command to destroy the Terraform infrastructure:

$ terraform destroy