update code
This commit is contained in:
parent
198b9bdd2f
commit
311ed006e3
@ -1,18 +1,105 @@
|
||||
// Generate random value for the Resource Group name
|
||||
resource "random_pet" "rg-name" {
|
||||
prefix = var.name_prefix
|
||||
}
|
||||
|
||||
// Generate random value for the name
|
||||
resource "random_string" "name" {
|
||||
length = 8
|
||||
upper = false
|
||||
lower = true
|
||||
special = false
|
||||
}
|
||||
|
||||
// Generate random value for the login password
|
||||
resource "random_password" "password" {
|
||||
length = 8
|
||||
upper = true
|
||||
lower = true
|
||||
special = true
|
||||
override_special = "_"
|
||||
}
|
||||
|
||||
// Manages the Resource Group where the resource exists
|
||||
resource "azurerm_resource_group" "default" {
|
||||
name = random_pet.rg-name.id
|
||||
name = "mysqlfsRG-${random_pet.rg-name.id}"
|
||||
location = var.location
|
||||
}
|
||||
|
||||
resource "azurerm_mysql_flexible_server" "default" {
|
||||
name = "${var.name_prefix}-server"
|
||||
resource_group_name = azurerm_resource_group.default.name
|
||||
location = azurerm_resource_group.default.location
|
||||
administrator_login = "adminTerraform"
|
||||
administrator_password = "QAZwsx123"
|
||||
sku_name = "B_Standard_B1s"
|
||||
zone = "1"
|
||||
// Manages the Virtual Network
|
||||
resource "azurerm_virtual_network" "default" {
|
||||
name = "vnet-${random_string.name.result}"
|
||||
location = azurerm_resource_group.default.location
|
||||
resource_group_name = azurerm_resource_group.default.name
|
||||
address_space = ["10.0.0.0/16"]
|
||||
}
|
||||
|
||||
// Manages the Subnet
|
||||
resource "azurerm_subnet" "default" {
|
||||
name = "subnet-${random_string.name.result}"
|
||||
resource_group_name = azurerm_resource_group.default.name
|
||||
virtual_network_name = azurerm_virtual_network.default.name
|
||||
address_prefixes = ["10.0.2.0/24"]
|
||||
service_endpoints = ["Microsoft.Storage"]
|
||||
|
||||
delegation {
|
||||
name = "fs"
|
||||
|
||||
service_delegation {
|
||||
name = "Microsoft.DBforMySQL/flexibleServers"
|
||||
|
||||
actions = [
|
||||
"Microsoft.Network/virtualNetworks/subnets/join/action",
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Enables you to manage Private DNS zones within Azure DNS
|
||||
resource "azurerm_private_dns_zone" "default" {
|
||||
name = "${random_string.name.result}.mysql.database.azure.com"
|
||||
resource_group_name = azurerm_resource_group.default.name
|
||||
}
|
||||
|
||||
// Enables you to manage Private DNS zone Virtual Network Links
|
||||
resource "azurerm_private_dns_zone_virtual_network_link" "default" {
|
||||
name = "mysqlfsVnetZone${random_string.name.result}.com"
|
||||
private_dns_zone_name = azurerm_private_dns_zone.default.name
|
||||
virtual_network_id = azurerm_virtual_network.default.id
|
||||
resource_group_name = azurerm_resource_group.default.name
|
||||
}
|
||||
|
||||
// Manages the MySQL Flexible Server
|
||||
resource "azurerm_mysql_flexible_server" "default" {
|
||||
name = "mysqlfs-${random_string.name.result}"
|
||||
resource_group_name = azurerm_resource_group.default.name
|
||||
location = azurerm_resource_group.default.location
|
||||
administrator_login = random_string.name.result
|
||||
administrator_password = random_password.password.result
|
||||
zone = "1"
|
||||
version = "8.0.21"
|
||||
backup_retention_days = 7
|
||||
geo_redundant_backup_enabled = false
|
||||
|
||||
storage {
|
||||
size_gb = 20
|
||||
iops = 360
|
||||
}
|
||||
|
||||
delegated_subnet_id = azurerm_subnet.default.id
|
||||
private_dns_zone_id = azurerm_private_dns_zone.default.id
|
||||
sku_name = "GP_Standard_D2ds_v4"
|
||||
|
||||
high_availability {
|
||||
mode = "ZoneRedundant"
|
||||
standby_availability_zone = "2"
|
||||
}
|
||||
|
||||
maintenance_window {
|
||||
day_of_week = 0
|
||||
start_hour = 8
|
||||
start_minute = 0
|
||||
}
|
||||
|
||||
depends_on = [azurerm_private_dns_zone_virtual_network_link.default]
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
// Manages the MySQL Flexible Server Database
|
||||
resource "azurerm_mysql_flexible_database" "default" {
|
||||
name = "${var.name_prefix}db"
|
||||
name = "mysqlfsdb_${random_string.name.result}"
|
||||
resource_group_name = azurerm_resource_group.default.name
|
||||
server_name = azurerm_mysql_flexible_server.default.name
|
||||
charset = "utf8"
|
||||
|
@ -5,7 +5,13 @@ This template deploys an [Azure MySQL Flexible Server Database](https://registry
|
||||
## Terraform resource types
|
||||
|
||||
- [random_pet](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet)
|
||||
- [random_string](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string)
|
||||
- [random_password](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/password)
|
||||
- [azurerm_resource_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group)
|
||||
- [azurerm_virtual_network](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_network)
|
||||
- [azurerm_subnet](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/subnet)
|
||||
- [azurerm_private_dns_zone](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/private_dns_zone)
|
||||
- [azurerm_private_dns_zone_virtual_network_link](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/private_dns_zone_virtual_network_link)
|
||||
- [azurerm_mysql_flexible_server](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/mysql_flexible_server)
|
||||
- [azurerm_mysql_flexible_database](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/mysql_flexible_database)
|
||||
|
||||
@ -13,7 +19,7 @@ This template deploys an [Azure MySQL Flexible Server Database](https://registry
|
||||
|
||||
| Name | Description |
|
||||
|-|-|
|
||||
| `name_prefix` | (Optional) Prefix of the resource name. Value defaults to: mysqlfs|
|
||||
| `name_prefix` | (Optional) Prefix of the resource name. Value defaults to: tftest|
|
||||
| `location` | (Optional) Azure Region in which to deploy these resources. Value defaults to: eastus |
|
||||
|
||||
## Example
|
||||
|
@ -1,9 +1,11 @@
|
||||
variable "name_prefix" {
|
||||
default = "mysqlfs"
|
||||
type = string
|
||||
default = "tftest"
|
||||
description = "Prefix of the resource name."
|
||||
}
|
||||
|
||||
variable "location" {
|
||||
type = string
|
||||
default = "eastus"
|
||||
description = "Location of the resource."
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user