зеркало из https://github.com/Azure/terraform.git
Merge pull request #80 from neil-yechenwei/examplemysqlfsdb
Add example for MySQL Flexible Server Database
This commit is contained in:
Коммит
742b875490
|
@ -0,0 +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 = "mysqlfsRG-${random_pet.rg-name.id}"
|
||||
location = var.location
|
||||
}
|
||||
|
||||
// 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]
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
// Manages the MySQL Flexible Server Database
|
||||
resource "azurerm_mysql_flexible_database" "default" {
|
||||
name = "mysqlfsdb_${random_string.name.result}"
|
||||
resource_group_name = azurerm_resource_group.default.name
|
||||
server_name = azurerm_mysql_flexible_server.default.name
|
||||
charset = "utf8"
|
||||
collation = "utf8_unicode_ci"
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
output "resource_group_name" {
|
||||
value = azurerm_resource_group.default.name
|
||||
}
|
||||
|
||||
output "azurerm_mysql_flexible_server" {
|
||||
value = azurerm_mysql_flexible_server.default.name
|
||||
}
|
||||
|
||||
output "mysql_flexible_server_database_name" {
|
||||
value = azurerm_mysql_flexible_database.default.name
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
terraform {
|
||||
required_version = ">=1.0"
|
||||
|
||||
required_providers {
|
||||
azurerm = {
|
||||
source = "hashicorp/azurerm"
|
||||
version = "~>3.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "azurerm" {
|
||||
features {}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
# Azure MySQL Flexible Server Database
|
||||
|
||||
This template deploys an [Azure MySQL Flexible Server Database](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/mysql_flexible_database).
|
||||
|
||||
## 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)
|
||||
|
||||
## Variables
|
||||
|
||||
| Name | Description |
|
||||
|-|-|
|
||||
| `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
|
||||
|
||||
To see how to run this example, see [Create an Azure MySQL Flexible Server Database using Terraform](https://docs.microsoft.com/azure/developer/terraform/deploy-mysql-flexible-server-database).
|
|
@ -0,0 +1,11 @@
|
|||
variable "name_prefix" {
|
||||
type = string
|
||||
default = "tftest"
|
||||
description = "Prefix of the resource name."
|
||||
}
|
||||
|
||||
variable "location" {
|
||||
type = string
|
||||
default = "eastus"
|
||||
description = "Location of the resource."
|
||||
}
|
|
@ -32,6 +32,7 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope
|
|||
- [Azure virtual machine scale set with jumpbox](./201-vmss-jumpbox)
|
||||
- [Azure virtual machine scale set with jumpbox from Packer custom image](./201-vmss-packer-jumpbox)
|
||||
- [Azure PostgreSQL Flexible Server Database](./201-postgresql-fs-db)
|
||||
- [Azure MySQL Flexible Server Database](./201-mysql-fs-db)
|
||||
|
||||
#### Advanced
|
||||
- [Azure Service Fabric](./301-service-fabric/)
|
||||
|
|
Загрузка…
Ссылка в новой задаче