Terraform File:

 terraform {

  required_providers {

    mysql = {

      source = “terraform-providers/mysql”

    }

  }

  required_version = “>= 0.13”

}

provider “mysql” {

  endpoint = “172.17.0.51:3306”

  username = “root”

  password = “redhat”

}

resource “mysql_user” “jdoe” {

  user               = “jdoe”

  host               = “localhost”

  plaintext_password = “password”

}

Check the changes using the terraform plan command.

Terraform plan 

To apply those changes use the terraform apply command.

terraform apply

Login using user we just created

Mysql -u joed -p

Task By Trainer:

Task 4:

  • Create a MySQL user called harry and set its password as potter.
  • Grant all permission to harry on mydb database. Create database mydb if not present.