Prerequisite: Mysql or MariaDB must be configured before.
terraform {
required_providers {
mysql = {
source = “terraform-providers/mysql”
}
}
required_version = “>= 0.13”
}
provider “mysql” {
endpoint = “172.17.0.51:3306”
username = Mysql_User
password = Mysql_Password
}
# Create a Database
resource “mysql_database” “app” {
name = “my_awesome_app”
}
Use terraform init command to initialize the provider.
Check the changes using the terraform plan command.
Terraform plan
To apply those changes use terraform apply command.
terraform apply
To check the changes
mysql -uroot -p
MariaDB [(none)]> show databases;
+——————–+
| Database |
+——————–+
| information_schema |
| my_awesome_app |
| mysql |
| performance_schema |
+——————–+
Task by Trainer:
Task 3:
Create a database called Class.