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