Skip to content

Commit 1a74307

Browse files
author
Mark Gray
committed
Quickstart for WebApp with MySQL backend
1 parent a964345 commit 1a74307

File tree

7 files changed

+154
-0
lines changed

7 files changed

+154
-0
lines changed

quickstart/WebAppMySql/main.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
resource "azurerm_resource_group" "webAppMySqlRg" {
2+
name = "${var.rg}"
3+
location = "${var.loc}"
4+
tags = "${var.tags}"
5+
}

quickstart/WebAppMySql/mysql.tf

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
resource "azurerm_mysql_server" "webAppBackend" {
2+
name = "${var.siteName}pgserver"
3+
location = "${azurerm_resource_group.webAppMySqlRg.location}"
4+
resource_group_name = "${azurerm_resource_group.webAppMySqlRg.name}"
5+
tags = "${azurerm_resource_group.webAppMySqlRg.tags}"
6+
7+
administrator_login = "${var.administratorLogin}"
8+
administrator_login_password = "${var.administratorLoginPassword}"
9+
version = "${var.mysqlVersion}"
10+
ssl_enforcement = "Disabled"
11+
sku {
12+
name = "${var.databaseSkuName}"
13+
capacity = "${var.databaseDTU}"
14+
tier = "${var.databaseSkuTier}"
15+
family = "${var.databaseSkuFamily}"
16+
}
17+
storage_profile {
18+
storage_mb = "${var.databaseSkuSizeMB}"
19+
}
20+
}
21+
22+
resource "azurerm_mysql_database" "webAppBackend" {
23+
name = "${var.siteName}database"
24+
resource_group_name = "${azurerm_resource_group.webAppMySqlRg.name}"
25+
26+
server_name = "${azurerm_mysql_server.webAppBackend.name}"
27+
charset = "utf8"
28+
collation = "utf8_unicode_ci"
29+
}

quickstart/WebAppMySql/output.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
output "webAppUrl" {
2+
value = "${azurerm_app_service.webAppFrontend.default_site_hostname}"
3+
}
4+
5+
output "databaseName" {
6+
value = "${azurerm_mysql_database.webAppBackend.name}"
7+
}
8+
9+
output "databaseServerName" {
10+
value = "${azurerm_mysql_server.webAppBackend.fqdn}"
11+
}
12+
13+
output "appServicePlanName" {
14+
value = "${azurerm_app_service_plan.webAppFrontend.name}"
15+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
provider "azurerm" {
2+
version = "~>1.17"
3+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
rg = "mcg623webAppMysql"
2+
loc = "eastus2"
3+
tags = {
4+
type = "sample"
5+
services = "MySql, WebApp, Azure database"
6+
}
7+
8+
administratorLogin = "markg"
9+
siteName = "mcgecd69mysql"
10+
11+
servicePlanTier = "Standard"
12+
servicePlanSize = "S1"
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
variable "rg" {
2+
description = "Azure resource group for all resources."
3+
}
4+
5+
variable "siteName" {
6+
description = "Name of azure web app"
7+
}
8+
9+
variable "tags" {
10+
description = "Azure Tags for all resources."
11+
default = {}
12+
}
13+
14+
15+
variable "administratorLogin" {
16+
description = "Database administrator login name"
17+
}
18+
19+
variable "administratorLoginPassword" {
20+
description = "Database administrator password"
21+
}
22+
23+
variable "databaseDTU" {
24+
description = "Azure database for MySQL pricing tier"
25+
default = 2
26+
}
27+
28+
variable "databaseSkuName" {
29+
description = "Azure database for MySQL sku name"
30+
default = "GP_Gen4_2"
31+
}
32+
33+
variable "databaseSkuFamily" {
34+
description = "Azure database for MySQL sku family"
35+
default = "Gen4"
36+
}
37+
38+
39+
variable "databaseSkuSizeMB" {
40+
description = "Azure database for MySQL Sku Size"
41+
default = 5120
42+
}
43+
44+
variable "databaseSkuTier" {
45+
description = "Azure database for MySQL pricing tier"
46+
default = "GeneralPurpose"
47+
}
48+
49+
variable "mysqlVersion" {
50+
description = "MySQL version"
51+
default = "5.6"
52+
}
53+
54+
variable "loc" {
55+
description = "Location for all resources."
56+
default = "eastus2"
57+
}
58+
59+
variable "servicePlanTier" {
60+
description = "Azure managed application service plan pricing tier"
61+
}
62+
63+
variable "servicePlanSize" {
64+
description = "Azure managed application service plan instance size"
65+
}

quickstart/WebAppMySql/webapp.tf

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
resource "azurerm_app_service_plan" "webAppFrontend" {
2+
name = "${var.siteName}serviceplan"
3+
resource_group_name = "${azurerm_resource_group.webAppMySqlRg.name}"
4+
location = "${azurerm_resource_group.webAppMySqlRg.location}"
5+
tags = "${azurerm_resource_group.webAppMySqlRg.tags}"
6+
7+
sku {
8+
tier = "${var.servicePlanTier}"
9+
size = "${var.servicePlanSize}"
10+
}
11+
}
12+
13+
resource "azurerm_app_service" "webAppFrontend" {
14+
name = "${var.siteName}"
15+
location = "${azurerm_resource_group.webAppMySqlRg.location}"
16+
resource_group_name = "${azurerm_resource_group.webAppMySqlRg.name}"
17+
tags = "${azurerm_resource_group.webAppMySqlRg.tags}"
18+
19+
app_service_plan_id = "${azurerm_app_service_plan.webAppFrontend.id}"
20+
connection_string {
21+
name = "DefaultConnect"
22+
type = "MySql"
23+
value = "Database=${azurerm_mysql_database.webAppBackend.name};Data Source=${azurerm_mysql_server.webAppBackend.fqdn};User Id=${var.administratorLogin}@${azurerm_mysql_server.webAppBackend.name};Password=${var.administratorLoginPassword}"
24+
}
25+
}

0 commit comments

Comments
 (0)