Azure Database MySQL Flexible Server
This page shows how to write Terraform and Azure Resource Manager for Database MySQL Flexible Server and write them securely.
azurerm_mysql_flexible_server (Terraform)
The MySQL Flexible Server in Database can be configured in Terraform with the resource name azurerm_mysql_flexible_server. The following sections describe how to use the resource and its parameters.
Example Usage from GitHub
An example could not be found in GitHub.
Parameters
The following arguments are supported:
name- (Required) The name which should be used for this MySQL Flexible Server. Changing this forces a new MySQL Flexible Server to be created.resource_group_name- (Required) The name of the Resource Group where the MySQL Flexible Server should exist. Changing this forces a new MySQL Flexible Server to be created.location- (Required) The Azure Region where the MySQL Flexible Server should exist. Changing this forces a new MySQL Flexible Server to be created.administrator_login- (Optional) The Administrator Login for the MySQL Flexible Server. Required whencreate_modeisDefault. Changing this forces a new MySQL Flexible Server to be created.administrator_password- (Optional) The Password associated with theadministrator_loginfor the MySQL Flexible Server. Required whencreate_modeisDefault.backup_retention_days- (Optional) The backup retention days for the MySQL Flexible Server. Possible values are between7and35days. Defaults to7.create_mode- (Optional)The creation mode which can be used to restore or replicate existing servers. Possible values areDefault,PointInTimeRestore,GeoRestore, andReplica. Changing this forces a new MySQL Flexible Server to be created.
NOTE: Creating a
GeoRestoreserver requires the source server withgeo_redundant_backup_enabledenabled.
NOTE: The best practise is that it has to wait greater than 10 minutes to create the
GeoRestoreserver once the source server is created.
delegated_subnet_id- (Optional) The ID of the virtual network subnet to create the MySQL Flexible Server. Changing this forces a new MySQL Flexible Server to be created.geo_redundant_backup_enabled- (Optional) Should geo redundant backup enabled? Defaults tofalse. Changing this forces a new MySQL Flexible Server to be created.high_availability- (Optional) Ahigh_availabilityblock as defined below.maintenance_window- (Optional) Amaintenance_windowblock as defined below.point_in_time_restore_time_in_utc- (Optional) The point in time to restore fromcreation_source_server_idwhencreate_modeisPointInTimeRestore. Changing this forces a new MySQL Flexible Server to be created.private_dns_zone_id- (Optional) The ID of the private dns zone to create the MySQL Flexible Server. Changing this forces a new MySQL Flexible Server to be created.
NOTE: The
private_dns_zone_idis required when setting adelegated_subnet_id. Theazurerm_private_dns_zoneshould end with suffix.mysql.database.azure.com.
replication_role- The replication role. Possible value isNone.
NOTE: The
replication_rolecannot be set while creating and only can be updated fromReplicatoNone.
sku_name- (Optional) The SKU Name for the MySQL Flexible Server.source_server_id- (Optional)The resource ID of the source MySQL Flexible Server to be restored. Required whencreate_modeisPointInTimeRestore,GeoRestore, andReplica. Changing this forces a new MySQL Flexible Server to be created.storage- (Optional) Astorageblock as defined below.version- (Optional) The version of the MySQL Flexible Server to use. Possible values are5.7, and8.0.21. Changing this forces a new MySQL Flexible Server to be created.zone- (Optional) The availability zone information of the MySQL Flexible Server. Possible values are1,2and3.tags- (Optional) A mapping of tags which should be assigned to the MySQL Flexible Server.
A high_availability block supports the following:
mode- (Required) The high availability mode for the MySQL Flexible Server. Possibles values areSameZoneandZoneRedundant.
NOTE:
storage.0.auto_grow_enabledmust be enabled whenhigh_availabilityis enabled. To change thehigh_availabilityfor a MySQL Flexible Server created withhigh_availabilitydisabled during creation, the resource has to be recreated.
standby_availability_zone- (Optional) The availability zone of the standby Flexible Server. Possible values are1,2and3.
NOTE: The
standby_availability_zonewill be omitted when mode isSameZone, for thestandby_availability_zonewill be the same aszone.
A maintenance_window block supports the following:
day_of_week- (Optional) The day of week for maintenance window. Defaults to0.start_hour- (Optional) The day of week for maintenance window. Defaults to0.start_minute- (Optional) The start minute for maintenance window. Defaults to0.
A storage block supports the following:
auto_grow_enabled- (Optional) Should Storage Auto Grow be enabled? Defaults totrue.iops- (Optional) The storage IOPS for the MySQL Flexible Server. Possible values are between360and20000.size_gb- (Optional) The max storage allowed for the MySQL Flexible Server. Possible values are between20and16384.
In addition to the Arguments listed above - the following Attributes are exported:
id- The ID of the MySQL Flexible Server.fqdn- The fully qualified domain name of the MySQL Flexible Server.public_network_access_enabled- Is the public network access enabled?replica_capacity- The maximum number of replicas that a primary MySQL Flexible Server can have.
Explanation in Terraform Registry
Manages a MySQL Flexible 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_mysql_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_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/flexibleServers (Azure Resource Manager)
The flexibleServers in Microsoft.DBforMySQL can be configured in Azure Resource Manager with the resource name Microsoft.DBforMySQL/flexibleServers. The following sections describe how to use the resource and its parameters.
Example Usage from GitHub
An example could not be found in GitHub.
Parameters
apiVersionrequired - stringlocationrequired - stringThe geo-location where the resource lives
namerequired - stringThe name of the server.
propertiesrequiredadministratorLoginoptional - stringThe administrator's login name of a server. Can only be specified when the server is being created (and is required for creation).
administratorLoginPasswordoptional - stringThe password of the administrator login (required for server creation).
availabilityZoneoptional - stringavailability Zone information of the server.
backupoptionalbackupRetentionDaysoptional - integerBackup retention days for the server.
geoRedundantBackupoptional - stringWhether or not geo redundant backup is enabled.
createModeoptional - stringThe mode to create a new MySQL server.
highAvailabilityoptionalmodeoptional - stringHigh availability mode for a server.
standbyAvailabilityZoneoptional - stringAvailability zone of the standby server.
maintenanceWindowoptionalcustomWindowoptional - stringindicates whether custom window is enabled or disabled
dayOfWeekoptional - integerday of week for maintenance window
startHouroptional - integerstart hour for maintenance window
startMinuteoptional - integerstart minute for maintenance window
networkoptionaldelegatedSubnetResourceIdoptional - stringDelegated subnet resource id used to setup vnet for a server.
privateDnsZoneResourceIdoptional - stringPrivate DNS zone resource id.
replicationRoleoptional - stringThe replication role.
restorePointInTimeoptional - stringRestore point creation time (ISO8601 format), specifying the time to restore from.
sourceServerResourceIdoptional - stringThe source MySQL server id.
storageoptionalautoGrowoptional - stringEnable Storage Auto Grow or not.
iopsoptional - integerStorage IOPS for a server.
storageSizeGBoptional - integerMax storage size allowed for a server.
versionoptional - stringServer version.
skuoptionalnamerequired - stringThe name of the sku, e.g. Standard_D32s_v3.
tierrequired - stringThe tier of the particular SKU, e.g. GeneralPurpose.
tagsoptional - stringResource tags.
typerequired - string