Deploy MariaDB using Amazon RDS (Relational Database Service)

You can deploy MariaDB on Amazon RDS using Terraform.

Before you begin

For this section you will need a computer which has Terraform and the AWS CLI installed.

Any computer which has the required tools installed can be used for this section. The computer can be your desktop or laptop computer or a virtual machine with the required tools.

You will need an AWS account to complete this Learning Path. Create an account if you don’t have one.

Before you begin you will also need:

  • An AWS access key ID and secret access key

Acquire AWS Access Credentials

Terraform requires AWS authentication to create AWS resources. You can generate access keys (access key ID and secret access key) to perform authentication. Terraform uses the access keys to make calls to AWS using the AWS CLI.

To generate and configure the Access key ID and Secret access key, follow the AWS Credentials install guide .

Deploy MariaDB RDS instances

RDS is a relational database service provided by AWS.

The AWS documentation covering Creating and connecting to a MariaDB DB instance might also be helpful for you.

To deploy an RDS instance of MariaDB you can use Terraform files.

  1. Use a text editor to add the contents below to a new file named main.tf.
    

        
        
            provider "aws" {
  region = "us-east-2"
}

resource "aws_db_parameter_group" "default" {
  name   = "mariadb"
  family = "mariadb10.6"
}

resource "aws_db_instance" "Testing_mariadb" {
  identifier           = "mariadbdatabase"
  allocated_storage    = 10
  db_name              = "mydb"
  engine               = "mariadb"
  engine_version       = "10.6.10"
  instance_class       = "db.m6g.large"
  parameter_group_name = "mariadb"
  skip_final_snapshot  = true
  username             = var.username
  password             = var.password
  availability_zone    = "us-east-2a"
  publicly_accessible  = true
  deletion_protection  = false

  tags = {
    name = "TEST MariaDB"
  }
}
        
    
  1. Use a text editor to add the contents below to a new file named credential.tf.
    

        
        
            variable "username" {
  default = "admin"
}

variable "password" {
  default = "Armtest1" #we_can_choose_any_password, except special_characters.
}
        
    
Note

The password length should be atleast 8 characters.

This file is used for configuring your password.

To run RDS instances based on AWS Graviton processors you need to elect either M6g or R6g as the instance type.

The main.tf file selects db.m6g.large as the instance type.

Terraform commands

Use the same sequence of Terraform commands as the previous topics: init, plan, and apply.

  1. Initialize Terraform:
    

        
        
            terraform init
        
    
  1. Create a Terraform execution plan (optional):
    

        
        
            terraform plan
        
    
  1. Apply a Terraform execution plan:
    

        
        
            terraform apply
        
    
Note

Creating the RDS database may take a few minutes.

Wait for the deployment and then go to the AWS console.

Verify RDS

In the AWS console, go to RDS » Databases, and check if the RDS instance is running.

Image Alt Text:mariadb1

Connect to RDS

Make sure that the instance is correctly associated with a security group and VPC.

To connect to the RDS instance, find the endpoint. To find the Endpoint, go to RDS »Dashboard » {{YOUR_RDS_INSTANCE}}.

Image Alt Text:mariadb2

Using the Endpoint and the user and password mentioned in the credential.tf file you can connect using mariadb

    

        
        
            mariadb -h {{Endpoint}} -u {{user}} -p {{password}}
        
    
Note

Replace {{Endpoint}}, {{user}} and {{password}} with your values.

Run mariadb to connect. The output is similar to:

    

        
        mariadb -h {{Endpoint}} -u admin -pArmtest
__output__Welcome to the MariaDB monitor.  Commands end with ; or \g.
__output__Your MariaDB connection id is 6
__output__Server version: 10.6.12-MariaDB-0ubuntu0.22.04.1 Ubuntu 22.04
__output__
__output__Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
__output__
__output__Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
__output__
__output__MariaDB [(none)]>

        
    

For more information about accessing RDS refer to Connecting to an Amazon RDS DB instance .

Create Database and Table

You can use the instructions from the previous topic to access the Database and create a table .

Clean up resources

Run terraform destroy to delete all resources created.

    

        
        
            terraform destroy
        
    
Back
Next