» azurerm_mysql_database

Manages a MySQL Database within a MySQL Server

» Example Usage

provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "example" {
  name     = "example-resources"
  location = "West Europe"
}

resource "azurerm_mysql_server" "example" {
  name                = "example-mysqlserver"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name

  administrator_login          = "mysqladminun"
  administrator_login_password = "H@Sh1CoR3!"

  sku_name   = "B_Gen5_2"
  storage_mb = 5120
  version    = "5.7"

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

resource "azurerm_mysql_database" "example" {
  name                = "exampledb"
  resource_group_name = azurerm_resource_group.example.name
  server_name         = azurerm_mysql_server.example.name
  charset             = "utf8"
  collation           = "utf8_unicode_ci"
}

» Argument Reference

The following arguments are supported:

  • name - (Required) Specifies the name of the MySQL Database, which needs to be a valid MySQL identifier. Changing this forces a new resource to be created.

  • server_name - (Required) Specifies the name of the MySQL Server. Changing this forces a new resource to be created.

  • resource_group_name - (Required) The name of the resource group in which the MySQL Server exists. Changing this forces a new resource to be created.

  • charset - (Required) Specifies the Charset for the MySQL Database, which needs to be a valid MySQL Charset. Changing this forces a new resource to be created.

  • collation - (Required) Specifies the Collation for the MySQL Database, which needs to be a valid MySQL Collation. Changing this forces a new resource to be created.

» Attributes Reference

The following attributes are exported:

  • id - The ID of the MySQL Database.

» Timeouts

The timeouts block allows you to specify timeouts for certain actions:

  • create - (Defaults to 60 minutes) Used when creating the MySQL Database.
  • update - (Defaults to 60 minutes) Used when updating the MySQL Database.
  • read - (Defaults to 5 minutes) Used when retrieving the MySQL Database.
  • delete - (Defaults to 60 minutes) Used when deleting the MySQL Database.

» Import

MySQL Database's can be imported using the resource id, e.g.

terraform import azurerm_mysql_database.database1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.DBforMySQL/servers/server1/databases/database1