Debian Codegraph @

mysql/azuremysql/main.tf

raw
1 terraform {
2 required_version = "~>0.12"
3 }
4
5 # See documentation for more info: https://www.terraform.io/docs/providers/azurerm/auth/azure_cli.html
6 provider "azurerm" {
7 version = "~> 1.22"
8 }
9
10 provider "random" {
11 version = "~> 2.1"
12 }
13
14 # Run Azure CLI command "az account list-locations" to see list of all locations.
15 variable "location" {
16 description = "The Azure Region in which all resources in this example should be created."
17 }
18
19 # See documentation for more info: https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-overview
20 variable "resourcegroup" {
21 description = "The Azure Resource Group Name within your Subscription in which this resource will be created."
22 }
23
24 resource "random_string" "db_password" {
25 keepers = {
26 region = var.location
27 }
28
29 special = false
30 length = 20
31 }
32
33 resource "random_id" "serverid" {
34 keepers = {
35 region = var.location
36 }
37
38 byte_length = 2
39 }
40
41 resource "azurerm_resource_group" "mysqlrg" {
42 name = var.resourcegroup
43 location = var.location
44 }
45
46 resource "azurerm_mysql_server" "mysqlserver" {
47 name = format("go-cdk-test-%v", random_id.serverid.dec)
48 location = azurerm_resource_group.mysqlrg.location
49 resource_group_name = azurerm_resource_group.mysqlrg.name
50
51 sku {
52 name = "B_Gen5_2"
53 capacity = 2
54 tier = "Basic"
55 family = "Gen5"
56 }
57
58 storage_profile {
59 storage_mb = 5120
60 backup_retention_days = 7
61 geo_redundant_backup = "Disabled"
62 }
63
64 administrator_login = "gocloudadmin"
65 administrator_login_password = random_string.db_password.result
66 version = "5.7"
67 ssl_enforcement = "Enabled"
68 }
69
70 # See documentation for more info: https://www.terraform.io/docs/providers/azurerm/r/sql_firewall_rule.html
71 resource "azurerm_mysql_firewall_rule" "addrule" {
72 name = "ClientIPAddress"
73 resource_group_name = azurerm_resource_group.mysqlrg.name
74 server_name = azurerm_mysql_server.mysqlserver.name
75 start_ip_address = "0.0.0.0"
76 end_ip_address = "255.255.255.255"
77 }
78
79 resource "azurerm_mysql_database" "mysqldb" {
80 name = "testdb"
81 resource_group_name = azurerm_resource_group.mysqlrg.name
82 server_name = azurerm_mysql_server.mysqlserver.name
83 charset = "utf8"
84 collation = "utf8_unicode_ci"
85 }
86
87 output "username" {
88 value = "${azurerm_mysql_server.mysqlserver.administrator_login}@${azurerm_mysql_server.mysqlserver.name}"
89 description = "The MySQL username to connect with."
90 }
91
92 output "password" {
93 value = random_string.db_password.result
94 sensitive = true
95 description = "The MySQL instance password for the user."
96 }
97
98 output "servername" {
99 value = azurerm_mysql_server.mysqlserver.fqdn
100 description = "The host name of the Azure Database for MySQL instance."
101 }
102
103 output "database" {
104 value = "testdb"
105 description = "The databasename of the Azure Database for MySQL instance."
106 }
107