Launch DB Using Terraform Provider

This walkthrough explains how to launch database services and manage the lifecycle of database services using the Terraform provider.

For users who prefer other interfaces, MariaDB Cloud offers the following alternatives:

This walkthrough demonstrates a service configuration that is suitable for a quick test. A more customized configuration should be selected for performance testing or for alignment to the needs of production workloads.

For a list of operating systems that are officially supported for Terraform, see "HashiCorp Terraform Documentation: Supported Operating Systems".

For a list of operating systems that have binaries available for Terraform, see "HashiCorp Terraform Documentation: Install Terraform".

Dependencies

  • This procedure requires Terraform to be installed. For information about how to install Terraform, see HashiCorp Terraform Documentation: Install Terraform.

  • The examples in this procedure also use jq, a JSON parsing utility. jq is available for Linux, macOS, and MS Windows. Install jq , then proceed.

  • The examples in this procedure also use curl, a data transfer utility. curl is available for Linux, macOS, and MS Windows. Install curl, then proceed.

  • The examples in this procedure also use wget, a file download utility. GNU Wget is available for Linux, macOS, and MS Windows. Install wget, then proceed.

  • The examples in this procedure also use exported environment variables that are compatible with Bourne-like shells (such as sh, bash, and zsh).

Launch a Service

1

Generate API Key

  1. Go to the Generate API Key page.

  2. Fill out a name for the API key.

  3. Click the "Create" button.

  4. Click the copy button to copy the API key.

  5. Store the API key somewhere safe as it is shown only once during the creation. The MariaDB Cloud platform does not store it anywhere.

2

Create Terraform Project Directory

Create a directory for your Terraform project and change to the directory:

3

Create main.tf

In the Terraform project directory, create a main.tf file that contains the following:

4

Create outputs.tf

In the Terraform project directory, create an outputs.tf file that contains the output values used to display metadata about the MariaDB Cloud service:

5

Create variables.tf

In the Terraform project directory, create a variables.tf file that contains the input variables used to configure the MariaDB Cloud service:

The variables are configured in the next step.

6

Configure Service in a .tfvars File

A .tfvars file can be used to configure the service using the input variables.

For example:

The input variables should be customized for your own needs:

The following steps assume that the file is called skysql-nr-quickstart.tfvars.

7

Run terraform init

Initialize the Terraform project directory and download the Terraform provider from the Terraform Registry by executing the terraform init command:

If you need to download the provider manually, see "Manually Install Provider from Binary Distribution".

8

Run terraform plan

Create a Terraform execution plan by executing the terraform plan command and specifying the path to the .tfvars file:

9

Run terraform apply

Execute the Terraform execution plan and create the MariaDB Cloud service by executing the terraform apply command and specifying the path to the .tfvars file:

Terraform prints the plan from the previous step again and prompts the user to confirm that the plan should be applied:

Then Terraform creates the objects and prints status messages:

Then Terraform prints the outputs.

10

Obtain Connection Credentials

Obtain the connection credentials for the new MariaDB Cloud service by executing the following commands:

  1. Obtain the connection command from the terraform.tfstate file:

  2. Obtain the user password from the terraform.tfstate file:

11

Connect

Connect to the MariaDB Cloud service by executing the connection command from the previous step:

When prompted, type the password and press Enter to connect:

12

Run terraform destroy

Delete the service by executing the terraform destroy command and specifying the path to the .tfvars file:

Terraform prints the plan to delete the service and prompts the user to confirm that the plan should be applied:

If deletion protection is enabled for the resources, the operation raises an error:

If deletion protection is not enabled for the resources, Terraform deletes the resources and prints status messages:

Manually Install Provider from Binary Distribution

The MariaDB Cloud New Release Terraform provider can be downloaded from the GitHub releases page as a binary distribution and manually installed.

Manually Install Provider on Linux

With Linux, manually install the provider on the target system by performing the following steps in the same Bash terminal:

  1. Set some environment variables to configure your provider version, OS, and architecture:

    For TF_PROVIDER_ARCH, the following architectures are supported on Linux:

    • 386

    • amd64

    • arm

    • arm64

  2. Download the provider from GitHub using wget:

  3. Create a Terraform plugin directory:

  4. Move the provider's binary distribution to the Terraform plugin directory:

  5. Verify that the provider's binary distribution is present in the Terraform plugin directory:

Manually Install Provider on macOS

With macOS, manually install the provider on the target system by performing the following steps in the same macOS Terminal:

  1. If Homebrew is not installed, install it:

  2. Install wget using Homebrew:

  3. Set some environment variables to configure your provider version, OS, and architecture:

    For TF_PROVIDER_ARCH, the following architectures are supported on macOS:

    • amd64

    • arm64

  4. Download the provider from GitHub using wget:

  5. Create a Terraform plugin directory:

  6. Move the provider's binary distribution to the Terraform plugin directory:

  7. Verify that the provider's binary distribution is present in the Terraform plugin directory:

Resources

Last updated

Was this helpful?