Deploy a MySQL Database on Azure With Terraform

In this blog post, we will learn how to create a MySQL database on Microsoft Azure with Terraform.

Before you start, make sure you visit this blog post on how to install Terraform on macOS and Windows with all the necessary tools.


The following Terraform configuration file will create a MySQL database in a new resource group. Please set the password in the code that will allow you to login in.

provider "azurerm" {
  features {}

resource "azurerm_resource_group" "trfdemo2" {
  name     = "trfdemo2resources"
  location = "southeastasia"

resource "azurerm_mysql_server" "trfdemo2" {
  name                = "trfdemo2mysqlserver"
  location            = azurerm_resource_group.trfdemo2.location
  resource_group_name =

  administrator_login          = "mysqladminun"
  administrator_login_password = "set password here"

  sku_name   = "GP_Gen5_2"
  storage_mb = 5120
  version    = "5.7"

  auto_grow_enabled                 = true
  backup_retention_days             = 7
  geo_redundant_backup_enabled      = true
  infrastructure_encryption_enabled = false
  public_network_access_enabled     = false
  ssl_enforcement_enabled           = true
  ssl_minimal_tls_version_enforced  = "TLS1_2"

resource "azurerm_mysql_database" "trfdemo2" {
  name                = "trfdemo2db"
  resource_group_name =
  server_name         =
  charset             = "utf8"
  collation           = "utf8_unicode_ci"

This blog post was first published on our sister site

Leave a comment

Your email address will not be published.