File tree Expand file tree Collapse file tree 5 files changed +277
-0
lines changed Expand file tree Collapse file tree 5 files changed +277
-0
lines changed Original file line number Diff line number Diff line change
1
+ formatter : markdown document
2
+ output :
3
+ file : " README.md"
4
+ settings :
5
+ anchor : false
Original file line number Diff line number Diff line change
1
+ # Azure DB for MySQL
2
+
3
+ ## Introduction
4
+
5
+ This module manages resources for Azure DB for MySQL.
6
+
7
+ ## Usage
8
+
9
+ Instantiate the module by calling it from Terraform like this:
10
+
11
+ ``` hcl
12
+ module "azure-mysql" {
13
+ source = "dodevops/mysql/azure"
14
+ version = "<version>"
15
+ }
16
+ ```
17
+
18
+ <!-- BEGIN_TF_DOCS -->
19
+ ## Requirements
20
+
21
+ No requirements.
22
+
23
+ ## Providers
24
+
25
+ The following providers are used by this module:
26
+
27
+ - azurerm
28
+
29
+ ## Modules
30
+
31
+ No modules.
32
+
33
+ ## Resources
34
+
35
+ The following resources are used by this module:
36
+
37
+ - [ azurerm_mysql_database.db] ( https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/mysql_database ) (resource)
38
+ - [ azurerm_mysql_server.server] ( https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/mysql_server ) (resource)
39
+
40
+ ## Required Inputs
41
+
42
+ The following input variables are required:
43
+
44
+ ### admin\_ password
45
+
46
+ Description: Admin password
47
+
48
+ Type: ` string `
49
+
50
+ ### database\_ suffixes
51
+
52
+ Description: List of suffixes for databases to be created
53
+
54
+ Type: ` list(string) `
55
+
56
+ ### location
57
+
58
+ Description: The azure location used for azure
59
+
60
+ Type: ` string `
61
+
62
+ ### project
63
+
64
+ Description: Three letter project key
65
+
66
+ Type: ` string `
67
+
68
+ ### resource\_ group
69
+
70
+ Description: Azure Resource Group to use
71
+
72
+ Type: ` string `
73
+
74
+ ### stage
75
+
76
+ Description: Stage for this ressource group
77
+
78
+ Type: ` string `
79
+
80
+ ## Optional Inputs
81
+
82
+ The following input variables are optional (have default values):
83
+
84
+ ### admin\_ login
85
+
86
+ Description: Admin login
87
+
88
+ Type: ` string `
89
+
90
+ Default: ` "mysqladmin" `
91
+
92
+ ### backup\_ retention\_ days
93
+
94
+ Description: Number of days to keep backups
95
+
96
+ Type: ` number `
97
+
98
+ Default: ` 7 `
99
+
100
+ ### database\_ host\_ sku
101
+
102
+ Description: n/a
103
+
104
+ Type: ` string `
105
+
106
+ Default: ` "GP_Gen5_1" `
107
+
108
+ ### database\_ storage
109
+
110
+ Description: n/a
111
+
112
+ Type: ` string `
113
+
114
+ Default: ` "5120" `
115
+
116
+ ### database\_ version
117
+
118
+ Description: Database version to use
119
+
120
+ Type: ` string `
121
+
122
+ Default: ` "8.0" `
123
+
124
+ ### suffix
125
+
126
+ Description: Naming suffix to allow multiple instances of this module
127
+
128
+ Type: ` string `
129
+
130
+ Default: ` "" `
131
+
132
+ ## Outputs
133
+
134
+ The following outputs are exported:
135
+
136
+ ### admin\_ login
137
+
138
+ Description: n/a
139
+
140
+ ### admin\_ password
141
+
142
+ Description: n/a
143
+
144
+ ### databases
145
+
146
+ Description: n/a
147
+
148
+ ### server\_ fqdn
149
+
150
+ Description: FQDN of the database service
151
+ <!-- END_TF_DOCS -->
152
+
153
+ ## Development
154
+
155
+ Use [ terraform-docs] ( https://terraform-docs.io/ ) to generate the API documentation by running
156
+
157
+ terraform fmt .
158
+ terraform-docs .
Original file line number Diff line number Diff line change
1
+ resource "azurerm_mysql_server" "server" {
2
+ name = " ${ var . project } ${ var . stage } dbsrv"
3
+ location = var. location
4
+ resource_group_name = var. resource_group
5
+
6
+ administrator_login = var. admin_login
7
+ administrator_login_password = var. admin_password
8
+
9
+ sku_name = var. database_host_sku
10
+ storage_mb = var. database_storage
11
+ version = var. database_version
12
+
13
+ auto_grow_enabled = true
14
+ backup_retention_days = var. backup_retention_days
15
+ geo_redundant_backup_enabled = false
16
+ infrastructure_encryption_enabled = true
17
+ public_network_access_enabled = false
18
+ ssl_enforcement_enabled = true
19
+ }
20
+
21
+ resource "azurerm_mysql_database" "db" {
22
+ for_each = toset (var. database_suffixes )
23
+ name = " ${ var . project } ${ var . stage } db${ var . database_suffixes [each . value ]} "
24
+ resource_group_name = var. resource_group
25
+ server_name = azurerm_mysql_server. server . name
26
+ charset = " utf8"
27
+ collation = " utf8_unicode_ci"
28
+ }
Original file line number Diff line number Diff line change
1
+ output "server_fqdn" {
2
+ description = " FQDN of the database service"
3
+ value = azurerm_mysql_server. server . fqdn
4
+ }
5
+
6
+ output "admin_login" {
7
+ value = var. admin_login
8
+ }
9
+
10
+ output "admin_password" {
11
+ value = var. admin_password
12
+ }
13
+
14
+ output "databases" {
15
+ value = length (azurerm_mysql_database. db ) > 0 ? {
16
+ for index , suffix in var . database_suffixes : suffix => azurerm_mysql_database . db [suffix ]. name
17
+ } : {}
18
+ }
Original file line number Diff line number Diff line change
1
+ variable "location" {
2
+ type = string
3
+ description = " The azure location used for azure"
4
+ }
5
+
6
+ variable "project" {
7
+ type = string
8
+ description = " Three letter project key"
9
+ }
10
+
11
+ variable "stage" {
12
+ type = string
13
+ description = " Stage for this ressource group"
14
+ }
15
+
16
+ variable "resource_group" {
17
+ type = string
18
+ description = " Azure Resource Group to use"
19
+ }
20
+
21
+ variable "database_suffixes" {
22
+ type = list (string )
23
+ description = " List of suffixes for databases to be created"
24
+ }
25
+
26
+ variable "database_version" {
27
+ type = string
28
+ description = " Database version to use"
29
+ default = " 8.0"
30
+ }
31
+
32
+ variable "suffix" {
33
+ type = string
34
+ description = " Naming suffix to allow multiple instances of this module"
35
+ default = " "
36
+ }
37
+
38
+ variable "backup_retention_days" {
39
+ type = number
40
+ description = " Number of days to keep backups"
41
+ default = 7
42
+ validation {
43
+ condition = var. backup_retention_days >= 7 && var. backup_retention_days <= 35
44
+ error_message = " Backup retention days has to be between 7 and 35 including"
45
+ }
46
+ }
47
+
48
+
49
+ variable "admin_login" {
50
+ type = string
51
+ description = " Admin login"
52
+ default = " mysqladmin"
53
+ }
54
+
55
+ variable "admin_password" {
56
+ type = string
57
+ description = " Admin password"
58
+ }
59
+
60
+ variable "database_host_sku" {
61
+ type = string
62
+ default = " GP_Gen5_1"
63
+ }
64
+
65
+ variable "database_storage" {
66
+ type = string
67
+ default = " 5120"
68
+ }
You can’t perform that action at this time.
0 commit comments