faizzamzuri / terraform-aws-lms

create lms in AWS using Terraform
0 stars 1 forks source link

Deploy cloud native database #10

Closed faizzamzuri closed 1 month ago

faizzamzuri commented 1 month ago

Create database for Moodle in Amazon RDS for MariaDB

attribute value
allocated_storage 10
db_name "mydb"
engine "mysql"
engine_version "8.0"
instance_class "db.t3.micro"
username "foo"
password "foobarbaz"
parameter_group_name "default.mysql8.0"
skip_final_snapshot true

Reference: Terraform Best Practices

rahmancloud commented 1 month ago

@faizzamzuri

  1. Confirm database software used in EC2 instance.
  2. Deploy the RDS instance with console.
    • Stick with suggested values (free-tier, cheapest).
    • Use the simplest configuration (existing VPC, existing subnet, etc.)
  3. Write Terraform based on the deployed RDS.
faizzamzuri commented 1 month ago
  1. Database software --> MariaDB

mariadb

https://docs.bitnami.com/azure/apps/moodle/get-started/find-credentials-link-mariadb/ To identify which database server is used in your stack, run the command below:

test -d /opt/bitnami/mariadb && echo "MariaDB" || echo "MySQL"

output --> MariaDB

faizzamzuri commented 1 month ago
  1. Deploy RDS using console.

Setting as below

attribute value
Database creation method standard
Engine type mariadb
Engine version 10.11.8
templates Free tier
DB instance identifier database1
Master username admin
Credentials management self-managed
Master password Database1!
DB Instance class db.t3.micro
storage gp2, 20GB
connectivity Don’t connect to an EC2 compute resource
Network type ipv4
VPC Default vpc
DB Subnet group default
Public access no
VPC security group (firewall) Create new - MariaDB_SG
Availability Zone No preference
Certificate authority - optional default
Database authentication Password authentication
Estimated Monthly costs DB instance 18.98 USD, Storage 2.76 USD, Total - 21.74 USD

Setting up mariadb using console, and using free tier, but there are still some cost per month.

rahmancloud commented 1 month ago

Delete if not in use. Re-create using Terraform when needed.

faizzamzuri commented 1 month ago
  1. Terraform mariaDB -

resource "aws_db_instance" "database1" { allocated_storage = 20 db_name = "database1" engine = "mariadb" engine_version = "10.11.8" instance_class = "db.t3.micro" username = "admin" password = "Database1!" parameter_group_name = "default.mariadb10.11" skip_final_snapshot = true copy_tags_to_snapshot = true }

rahmancloud commented 1 month ago

Boleh terus paste dalam database.tf di branch database.