github.com/darmach/terratest@v0.34.8-0.20210517103231-80931f95e3ff/examples/azure/terraform-azure-mysqldb-example/main.tf (about) 1 # --------------------------------------------------------------------------------------------------------------------- 2 # DEPLOY AN AZURE MySQL Database 3 # This is an example of how to deploy an Azure Mysql database. 4 # See test/terraform_azure_example_test.go for how to write automated tests for this code. 5 # --------------------------------------------------------------------------------------------------------------------- 6 7 8 # --------------------------------------------------------------------------------------------------------------------- 9 # CONFIGURE OUR AZURE CONNECTION 10 # --------------------------------------------------------------------------------------------------------------------- 11 12 provider "azurerm" { 13 version = "~>2.29.0" 14 features {} 15 } 16 17 # --------------------------------------------------------------------------------------------------------------------- 18 # DEPLOY A RESOURCE GROUP 19 # --------------------------------------------------------------------------------------------------------------------- 20 21 resource "azurerm_resource_group" "mysql_rg" { 22 name = "terratest-mysql-${var.postfix}" 23 location = var.location 24 } 25 26 # --------------------------------------------------------------------------------------------------------------------- 27 # DEPLOY AZURE MySQL SERVER 28 # --------------------------------------------------------------------------------------------------------------------- 29 30 # Random password is used as an example to simplify the deployment and improve the security of the database. 31 # This is not as a production recommendation as the password is stored in the Terraform state file. 32 resource "random_password" "password" { 33 length = 16 34 override_special = "_%@" 35 min_upper = "1" 36 min_lower = "1" 37 min_numeric = "1" 38 min_special = "1" 39 } 40 41 resource "azurerm_mysql_server" "mysqlserver" { 42 name = "mysqlserver-${var.postfix}" 43 location = azurerm_resource_group.mysql_rg.location 44 resource_group_name = azurerm_resource_group.mysql_rg.name 45 46 administrator_login = var.mysqlserver_admin_login 47 administrator_login_password = random_password.password.result 48 49 sku_name = var.mysqlserver_sku_name 50 storage_mb = var.mysqlserver_storage_mb 51 version = "5.7" 52 53 auto_grow_enabled = true 54 geo_redundant_backup_enabled = false 55 infrastructure_encryption_enabled = true 56 backup_retention_days = 7 57 public_network_access_enabled = false 58 ssl_enforcement_enabled = true 59 ssl_minimal_tls_version_enforced = "TLS1_2" 60 } 61 62 # --------------------------------------------------------------------------------------------------------------------- 63 # DEPLOY AZURE MySQL DATABASE 64 # --------------------------------------------------------------------------------------------------------------------- 65 66 resource "azurerm_mysql_database" "mysqldb" { 67 name = "mysqldb-${var.postfix}" 68 resource_group_name = azurerm_resource_group.mysql_rg.name 69 server_name = azurerm_mysql_server.mysqlserver.name 70 charset = var.mysqldb_charset 71 collation = var.mysqldb_collation 72 }