Azure Database MySQL Server
This page shows how to write Terraform and Azure Resource Manager for Database MySQL Server and write them securely.
azurerm_mysql_server (Terraform)
The MySQL Server in Database can be configured in Terraform with the resource name azurerm_mysql_server
. The following sections describe 10 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "azurerm_mysql_server" "basic_2core" {
name = "example-mariadb-server"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
administrator_login = "fake"
resource "azurerm_mysql_server" "webappdb" {
name = "webappdb-csye7125"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
administrator_login = "csye7125"
resource "azurerm_mysql_server" "webapp_db" {
name = var.webapp_db
location = var.location
resource_group_name = var.resource_group_name
sku_name = var.sku_name
resource "azurerm_mysql_server" "basic_2core" {
name = "example-mariadb-server"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
administrator_login = "fake"
resource "azurerm_mysql_server" "webapp_db" {
name = var.webapp_db
location = var.location
resource_group_name = var.resource_group_name
sku_name = var.sku_name
resource "azurerm_mysql_server" "vth" {
name = "vth-mysqlserver"
location = azurerm_resource_group.vth-myrg.location
resource_group_name = azurerm_resource_group.vth-myrg.name
administrator_login = "mysqladminun"
resource "azurerm_mysql_server" "mysql" {
name = var.name
location = var.region
resource_group_name = var.resource_group
administrator_login = "mysqladmin"
resource "azurerm_mysql_server" "database" {
name = "example-mysqlserver"
location = azurerm_resource_group.resource.location
resource_group_name = azurerm_resource_group.resource.name
administrator_login = "admin"
resource "azurerm_mysql_server" "mysql_chan_sample" {
name = "mysql-chan-sample"
location = "koreacentral"
resource_group_name = var.rgname
administrator_login = "mysqladminun"
resource "azurerm_mysql_server" "example" {
name = "mysql-terraformserver-1"
location = "East US"
resource_group_name = "186-d22b27-deploy-a-mariadb-database-with-terrafor"
sku {
Security Best Practices for azurerm_mysql_server
There are 4 settings in azurerm_mysql_server that should be taken care of for security reasons. The following section explain an overview and example code.
Ensure to disable public access to database
It is better to disable public access to the database to avoid unwilling communications with unknown services if not required.
Ensure to configure the most modern TLS policies available
It is better to use the latest TLS version for database connections.
Ensure to enable SSL enforcement
It is better to enable SSL enforcement to ensure secure transfer and mitigate the risks of compromising the communication data.
Ensure to enable threat detection on Mysql database
It is better to enable threat detection on Mysql's feature to help prevent compromise by alerting on threat detections.
Parameters
-
administrator_login
optional computed - string -
administrator_login_password
optional - string -
auto_grow_enabled
optional computed - bool -
backup_retention_days
optional computed - number -
create_mode
optional - string -
creation_source_server_id
optional - string -
fqdn
optional computed - string -
geo_redundant_backup_enabled
optional computed - bool -
id
optional computed - string -
infrastructure_encryption_enabled
optional - bool -
location
required - string -
name
required - string -
public_network_access_enabled
optional - bool -
resource_group_name
required - string -
restore_point_in_time
optional - string -
sku_name
required - string -
ssl_enforcement
optional computed - string -
ssl_enforcement_enabled
optional - bool -
ssl_minimal_tls_version_enforced
optional - string -
storage_mb
optional computed - number -
tags
optional - map from string to string -
version
required - string -
identity
list block-
principal_id
optional computed - string -
tenant_id
optional computed - string -
type
required - string
-
-
storage_profile
list block-
auto_grow
optional computed - string -
backup_retention_days
optional computed - number -
geo_redundant_backup
optional computed - string -
storage_mb
optional - number
-
-
threat_detection_policy
list block-
disabled_alerts
optional - set of string -
email_account_admins
optional - bool -
email_addresses
optional - set of string -
enabled
optional - bool -
retention_days
optional - number -
storage_account_access_key
optional - string -
storage_endpoint
optional - string
-
-
timeouts
single block
Explanation in Terraform Registry
Manages a MySQL Server.
Tips: Best Practices for The Other Azure Database Resources
In addition to the azurerm_mariadb_firewall_rule, Azure Database has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.
azurerm_mariadb_firewall_rule
Ensure database firewalls do not permit public access
It is better to restrict IP address ranges that can access the database by firewall rules. If both start_ip_address and end_ip_address are set to 0.0.0.0, it blocks connections from the Internet and accepts connections from all Azure datacenter IP addresses.
azurerm_mariadb_server
Ensure that access to Azure SQL Database is restricted
It is better to disable public access to the database to avoid unwilling communications with unknown services if not required.
azurerm_mssql_database_extended_auditing_policy
Ensure to configure retention periods of database auditing to enough duration
It is better to configure retention periods of database auditing to enough duration. It would be better to set greater than at least 90 days.
azurerm_mssql_server
Ensure to enable auditing on Azure SQL databases
It is better to enable auditing on Azure SQL databases. It helps you maintain regulatory compliance, monitor the activities indicating unexpected incidents or suspected security violations.
azurerm_mssql_server_security_alert_policy
Ensure to configure at least one email address for threat alerts
It is better to configure at least one email address for threat alerts. SQL Server is able to send alerts for threat detection via emails and it could support us to notice the incident on time.
azurerm_mysql_firewall_rule
Ensure database firewalls do not permit public access
It is better to restrict IP address ranges that can access the database by firewall rules. If both start_ip_address and end_ip_address are set to 0.0.0.0, it blocks connections from the Internet and accepts connections from all Azure datacenter IP addresses.
azurerm_postgresql_firewall_rule
Ensure database firewalls do not permit public access
It is better to restrict IP address ranges that can access the database by firewall rules. If both start_ip_address and end_ip_address are set to 0.0.0.0, it blocks connections from the Internet and accepts connections from all Azure datacenter IP addresses.
azurerm_postgresql_server
Ensure to disable public access to database
It is better to disable public access to the database to avoid unwilling communications with unknown services if not required.
azurerm_sql_firewall_rule
Ensure database firewalls do not permit public access
It is better to restrict IP address ranges that can access the database by firewall rules. If both start_ip_address and end_ip_address are set to 0.0.0.0, it blocks connections from the Internet and accepts connections from all Azure datacenter IP addresses.
azurerm_sql_server
Ensure to enable auditing on Azure SQL databases
It is better to enable auditing on Azure SQL databases. It helps you maintain regulatory compliance, monitor the activities indicating unexpected incidents or suspected security violations.
Microsoft.DBforMySQL/servers (Azure Resource Manager)
The servers in Microsoft.DBforMySQL can be configured in Azure Resource Manager with the resource name Microsoft.DBforMySQL/servers
. The following sections describe how to use the resource and its parameters.
Example Usage from GitHub
{
"contentVersion": "1.0.0.0",
"parameters": {
"workbookDisplayName": {
"type": "string",
{
"contentVersion": "1.0.0.0",
"parameters": {
"workbookDisplayName": {
"type": "string",
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"workbookName": {
{
"contentVersion": "1.0.0.0",
"parameters": {
"workbookDisplayName": {
"type": "string",
{
"contentVersion": "1.0.0.0",
"parameters": {
"workbookDisplayName": {
"type": "string",
Frequently asked questions
What is Azure Database MySQL Server?
Azure Database MySQL Server is a resource for Database of Microsoft Azure. Settings can be wrote in Terraform.
Where can I find the example code for the Azure Database MySQL Server?
For Terraform, the gilyas/infracost, MilesYu15/Hybrid-Cloud-Weather-Alert-App and Achira-Apurva-Boran/csye7125-azure-Project source code examples are useful. See the Terraform Example section for further details.
For Azure Resource Manager, the HasanIftakher/Azure-Monitor, tulpy/Azure and gaelor/SentinelAsCode source code examples are useful. See the Azure Resource Manager Example section for further details.