terraform azure mysql gtid_mode "ON" 错误

terraform azure mysql gtid_mode "ON" error

我正在尝试使用 terraform 在 azure 上使用一些默认配置创建 mysql,以下是我的代码。虽然“enforce_gtid_consistency”和“time_zone”正在工作并正在创建,但是“gtid_mode”“ON”不工作我收到以下错误。

resource "azurerm_mysql_server" "main" {
  name                = var.mysql_server_name != "" ? var.mysql_server_name : "mysql-01-${var.instancesuffix}"
  location            = azurerm_resource_group.main.location
  resource_group_name = azurerm_resource_group.main.name

  administrator_login          = var.mysql_administrator_login
  administrator_login_password = data.mykv.mysql.value

  sku_name   = var.mysql_sku_name
  storage_mb = var.mysql_storage_mb
  version    = var.mysql_version

  auto_grow_enabled                 = true
  backup_retention_days             = 7
  geo_redundant_backup_enabled      = false
  infrastructure_encryption_enabled = true
  public_network_access_enabled     = true
  ssl_enforcement_enabled           = true
  ssl_minimal_tls_version_enforced  = "TLS1_2"
  lifecycle {
    ignore_changes = [tags]
  }
  threat_detection_policy {
    disabled_alerts      = []
    email_account_admins = false
    email_addresses      = []
    enabled              = true
    retention_days       = 0
  }

}
resource "azurerm_mysql_configuration" "time_zone" {
  name                = "time_zone"
  resource_group_name = azurerm_resource_group.main.name
  server_name         = azurerm_mysql_server.main.name
  value               = "+00:00"
}
resource "azurerm_mysql_configuration" "enforce_gtid_consistency" {
  name                = "enforce_gtid_consistency"
  resource_group_name = azurerm_resource_group.main.name
  server_name         = azurerm_mysql_server.main.name
  value               = "ON"
}
resource "azurerm_mysql_configuration" "gtid_mode" {
  name                = "gtid_mode"
  resource_group_name = azurerm_resource_group.main.name
  server_name         = azurerm_mysql_server.main.name
  value               = "ON"

}
Error: waiting for creation of Configuration: (Name "gtid_mode" / Server Name "mysql-01" / Resource Group "myrg-01"): Code="InternalServerError" Message="An unexpected error occured while processing the request. Tracking ID: 'h59fr7f-18uo-90db-tb20-5y65d34btb04'"
  on resources.tf line 164, in resource "azurerm_mysql_configuration" "gtid_mode":
 164: resource "azurerm_mysql_configuration" "gtid_mode" {

正如我在评论中提到的,gtid_mode只能按顺序启用,直接打开ON即使设置了[=13]也不起作用=].

因此,作为解决方案,您必须按顺序设置它:

  1. OFF_PERMISSIVE
  2. ON_PERMISSIVE
  3. ON

我测试了您的代码,做了如下一些更改:

main.tf

provider "azurerm"{
    features{}
}
data "azurerm_resource_group" "main"{
    name = "resourcegroup"
}
data "azurerm_key_vault" "kv"{
    name = "ansumantestkv1234"
    resource_group_name = "resourcegroup"
}
data "azurerm_key_vault_secret" "name" {
  name = "mysqlpassword"
  key_vault_id = data.azurerm_key_vault.kv.id
}
resource "azurerm_mysql_server" "main" {
  name                = var.mysql_server_name
  location            = data.azurerm_resource_group.main.location
  resource_group_name = data.azurerm_resource_group.main.name

  administrator_login          = var.mysql_administrator_login
  administrator_login_password = data.azurerm_key_vault_secret.name.value

  sku_name   = var.mysql_sku_name
  storage_mb = var.mysql_storage_mb
  version    = var.mysql_version

  auto_grow_enabled                 = true
  backup_retention_days             = 7
  geo_redundant_backup_enabled      = false
  infrastructure_encryption_enabled = true
  public_network_access_enabled     = true
  ssl_enforcement_enabled           = true
  ssl_minimal_tls_version_enforced  = "TLS1_2"
  threat_detection_policy {
    disabled_alerts      = []
    email_account_admins = false
    email_addresses      = []
    enabled              = true
    retention_days       = 0
  }

}

resource "azurerm_mysql_configuration" "time_zone" {
  name                = "time_zone"
  resource_group_name = data.azurerm_resource_group.main.name
  server_name         = azurerm_mysql_server.main.name
  value               = "+00:00"
}
resource "azurerm_mysql_configuration" "enforce_gtid_consistency" {
  name                = "enforce_gtid_consistency"
  resource_group_name = data.azurerm_resource_group.main.name
  server_name         = azurerm_mysql_server.main.name
  value               = "ON"
  depends_on = [
    azurerm_mysql_configuration.time_zone
  ]
}
resource "azurerm_mysql_configuration" "gtid_mode_OFF_permissive" {
  name                = "gtid_mode"
  resource_group_name = data.azurerm_resource_group.main.name
  server_name         = azurerm_mysql_server.main.name
  value               = "OFF_PERMISSIVE"
 depends_on = [
  azurerm_mysql_configuration.enforce_gtid_consistency,
 ]
}
resource "azurerm_mysql_configuration" "gtid_mode_ON_Permissive" {
  name                = "gtid_mode"
  resource_group_name = data.azurerm_resource_group.main.name
  server_name         = azurerm_mysql_server.main.name
  value               = "ON_PERMISSIVE"
 depends_on = [
  azurerm_mysql_configuration.gtid_mode_OFF_permissive
 ]
}
resource "azurerm_mysql_configuration" "gtid_mode_ON" {
  name                = "gtid_mode"
  resource_group_name = data.azurerm_resource_group.main.name
  server_name         = azurerm_mysql_server.main.name
  value               = "ON"
 depends_on = [
  azurerm_mysql_configuration.gtid_mode_ON_Permissive
 ]
}

variable.tf:

variable "mysql_server_name" {
  default = "ansumanmysqlserver"
}

variable "mysql_administrator_login" {
  default = "ansuman"
}

variable "mysql_sku_name" {
  default = "GP_Gen5_2"
}
variable "mysql_storage_mb" {
  default = "5120"
}
variable "mysql_version" {
  default = "5.7"
}

输出:

参考:

MySQL :: MySQL 8.0 Reference Manual :: 17.1.4.2 Enabling GTID Transactions Online