Get Started with Bitnami Terraform Templates on Oracle Cloud Infrastructure

Introduction

Oracle Cloud Infrastructure offers a collection of cloud services designed to manage applications, services, and databases, in a high-performance cloud computing environment. Its architecture provides the flexibility to scale. In addition to this, Oracle Cloud Infrastructure offers the highly durable storage of public cloud combined with the security, control access, and cost-effectiveness of on-premise infrastructure.

If you’re new to the cloud, the easiest way to get started with Oracle Jump Start Launch is with Bitnami. Bitnami provides pre-packaged application templates for Oracle Jump Start Launch cloud servers, so you can get productive with your new server immediately. Access and launch these images using Terraform, which provides a command-line interface (CLI) to deploy and manage your Oracle Jump Start Launch servers.

This tutorial walks you through the process of using the Terraform Provider plugin and the Terraform CLI to deploy Bitnami MySQL with replication on an Oracle Jump Start Launch server. Find other Terraform Templates for OCI at the GitHub Bitnami repository.

TIP: To learn more about launching servers on Oracle Cloud Infrastructure using Qloudable, refer to this tutorial.

Overview

MySQL has proved to be a fast, reliable, scalable, and easy-to-use open-source relational database system and is one of the most popular databases used by both companies and individuals. MySQL is also used as a component of several renowned applications such as WordPress, Magento, and Redmine. Bitnami offers a ready-to-use MySQL with Replication cluster that allows you to start writing in the master node and has the information synchronized in slaves from the very moment of the deployment.

In this tutorial, you will learn, step by step (using the MySQL Terraform Solution as an example), the complete process of deploying an image and all the required resources on an Oracle Jump Start Launch server using a Terraform template. That way, once the solution has been deployed, you won’t only have the application image running on a server but also the volumes, instances, and network resources needed to operate with a MySQL production-ready cluster.

At the end of this step, you will have installed both the Terraform CLI and the Provider plugin on your local system.

To complete the Bitnami deployment it is necessary to have the Terraform CLI and the Provider plugin installed to work with Oracle Jump Start Launch.

To install the Terraform CLI:

Use Terraform official documentation to download the binary package that corresponds to your operative system. Unzip and move it to the /usr/local/bin/ directory of your local system, in case you are using macOS or Linux.

$ sudo mv terraform /usr/local/bin/

Download and install the latest release of the Oracle Jump Start Launch provider for Terraform from its GitHub repository. Binary packages are available for Linux, OS X and Windows. Unzip it and create a folder named ~/.terraform.d/plugins. Then, move the binary to that folder as shown below (X.Y.Z are placeholders of the latest version of the provider):

At the end of this step, your MySQL Terraform Solution will be associated with your OCI account.

Once you have installed the Bitnami Terraform template on your local system, it is necessary to associate the template to your Oracle Jump Start Launch account. That way, when you deploy the solution using the Terraform CLI, it creates a server on OCI in your tenant and in the selected compartment. Follow these instructions:

IMPORTANT: All the steps must be performed within the mysql directory.

The next steps are to retrieve OCI account parameters and to associate them with the Bitnami MySQL Terraform Solution. Find instructions below.

Retrieving OCI account parameters

Once the bitnami/oci-multi-tier repository is installed on your local system, you need retrieve the values for the following parameters to associate your OCI account with the Bitnami MySQL Terraform Solution.

TF_VAR_tenancy_ocid: OCI tenant ID

TF_VAR_user_ocid: OCI user ID

TF_VAR_fingerprint: PEM key fingerprints

TF_VAR_private_key_path: Path of your private key (*.pem / *.ppk)

TF_VAR_region

TF_VAR_compartment_id: OCI Compartment ID

TF_VAR_ssh_public_key_path and TF_VAR_ssh_private_key_path: Paths to the private and public (*.pub) SSH keys.

Follow these instructions:

To obtain the values for the TF_VAR_tenancy_ocid and the TF_VAR_region parameters, click the “Tenancy” link in the top menu.

In the “Tenancy” screen, find these values in the “Tenancy Information” section:

To obtain the values for both the TF_VAR_user_ocid and the TF_VAR_fingerprint parameters, navigate to the “User Settings” section. On the resulting page, you will find the required values:

To obtain the value for the TF_VAR_compartment_id parameter, navigate to the “Identity -> Compartments” section, and select the compartment OCID where you want to deploy the solution:

You can obtain the values for both the TF_VAR_ssh_public_key_path and the TF_VAR_ssh_private_key_path parameters when creating and uploading the public SSH key to the console. Follow the Oracle official documentation for further information about this.

Associate your OCI account with the Bitnami MySQL Terraform Solution

The last step consists of replacing the values you have obtained for these parameters in the env-vars file:

At the end of this step, your MySQL Terraform Solution will be running on multiple instances on the Oracle Jump Start Launch console.

The next step is to initialize the Terraform working directory, configure, and deploy the MySQL cluster. Follow these instructions:

To start the Terraform CLI and the Provider plugin, execute:

$ terraform init

It will show an output similar to this:

To apply the changes made in the env-vars file, execute this command:

$ source env-vars

Deploy the cluster running this command:

$ terraform apply

You will be prompted to specify the cluster configuration details. Enter the following information when it is displayed:

IMPORTANT: Database and deployment name should include neither dashes nor spaces.

Name of the application database

Name of the deployment

Size of the instance

Number of instances to deploy

Size of the data volume in GBs

NOTE: In case you don’t want to enter the cluster configuration values during the deployment, add them previously to the env-vars file. Find the correspondent variable name for each value in the variables.tf file.

The deployment takes about 10 minutes. Once the deployment has finished, you will see an output similar to this:

As you can see above, this output gives you essential information about your deployment such as the number and name of the nodes or the public IP addresses for each. Another way to retrieve this information is to check each instance in the “Compute -> Instances -> Instance Information” section in the OCI console.

To check the progress of each resource in the OCI console, select your compartment and navigate to the following tabs on the OCI console:

“Compute -> Instances”:

IMPORTANT: Take into account that the public IP address shown in the “Compute -> Instances -> Instance Information” section won’t be available until the entire deployment has finished.

“Networking -> Virtual Cloud Networks”:

“Storage -> Block Volumes”:

Understand the MySQL cluster configuration

The MySQL Terraform Solution deploys multiple virtual machines to replicate the databases from the master node to a configurable number of replicas. Replication in MySQL supports different types of synchronization between master and slaves. Bitnami configures the MySQL cluster using one-way synchronization and asynchronous replication. This means that one server acts as the master, while one or more other servers act as slaves.

That way, it allows you to start writing in the master node and have the information synchronized in slaves from the very moment of the deployment. This topology is illustrated below:

Step 4: Add new nodes to the cluster

At the end of this step, you will have added a new node to the cluster.

Scaling up your cluster is really easy. You just only need to execute the command below and indicate the total number of nodes you want the cluster to have. In this example, we have added just one node to the default three-node cluster, so you will see four nodes in total: one master and three slaves.

$ terraform apply -var nodes_count=TOTAL_NODES

The new deployment will take several minutes to finish. Please don’t take any action during this process.

Once it has finished, you will see an output similar to the image below. Note that the number of resources created is less than those in the first deployment. This is because Terraform reuses the already created resources and adds only the resources required for the new nodes.

Also check the new nodes in the “Compute -> Instances” section in the OCI console:

Step 5: Operate with the cluster

Finding my application password

There are two ways to configure the application password: Either provide a specific password before deployment, or have it generated automatically and retrieve it after deployment.

To set a specific password, add the following line to the env-vars file. Remember that PASSWORD is a placeholder, replace it with the password you want to set to the MySQL database:

app_password = "PASSWORD"

In case you didn’t provide a password before the deployment, it will be randomly generated. This is the password for user root. For security reasons, the application password is not displayed in the output of the deployment. Instead, you can see it labeled as “sensitive”:

To see the application password, execute the following command:

$ terraform output ApplicationPassword

To check the information related to deployment execute the following:

$ terraform output

That way, you will not only obtain the value for the application password, but also the private and public IP addresses of each node. Execute this command any time you need to obtain that information:

Connecting to the MySQL cluster through SSH

Once you have obtained the public IP address and the application password, you are ready to connect to your MySQL cluster. For security reasons, the Bitnami MySQL solution is not configured to accept remote connections. To connect to the cluster, connect to the server through SSH. Follow the steps below:

TIP: Remember that to display the cluster information execute the terraform output command at any time.

To connect to the server through SSH, execute the following command:

$ ssh -i KEYFILE bitnami@NODE-IP

Remember to replace KEYFILE in the previous commands with the path to your private key file (.pem), and NODE-IP with the public IP address or hostname of the node you want to connect.

To connect to the MySQL node, execute the following (in this example, the master node):

$ mysql -u root -p

You will see an output similar to this:

To see the information related to your MySQL database, execute the show databases command:

Opening ports

If you need to access your server remotely using a specific port, you must first open the port. This operation must be executed in each node of the cluster. To do so:

Open the network.tf file and add new content to the “ingress_security_rules” section. Remember to replace PORT with the number of the port you want to allow remote connections. This should look like the code block below:

Execute the following command for each port that you wish to open. Remember to replace the PORT placeholder with the corresponding port number:

$ sudo firewall-cmd --zone=public --permanent --add-port=PORT/tcp

Reload the firewall by running this command:

$ sudo firewall-cmd --reload

Step 6: Delete the cluster

At the end of this step, your MySQL cluster and the associated resources will be deleted.

In case you want to delete the cluster, you only need to execute the destroy command as shown below:

$ terraform destroy

When executing the command above, you will be prompted to re-enter all the values of the cluster you want to delete. At the end of the process, to confirm the action, type “yes” and press the “Enter” key.

Terraform will confirm that all resources have been successfully deleted:

Useful links

To learn more about the topics discussed in this tutorial, see the links below: