microsoft / azure-redcap-paas

Automated deployment of REDCap with Azure Blob storage as the storage back-end
MIT License
28 stars 53 forks source link

Terraform: add support for arbitrary number of azurerm_mysql_flexible_server_configuration resources #50

Open epopisces opened 8 months ago

epopisces commented 8 months ago

Terraform supports MySQL Flexible server configuration using azurerm_mysql_flexible_server_configuration resources, one for each configuration entry. An addition to the variables.tf file with a supporting variable in addition to the configuration resource using a for_each loop would be ideal.

Example implementation (including locals for universal defaults): variables.tf

variable "mysql_configuration_items" {
  description = "(Optional) Map of MySQL configurations to enable on the flexible server.  Defaults to `{}`"
  type        = map(string)
  default     = {}
}

main.tf (see #51 & #52 for why these locals could be included as defaults)

locals {
  mysql_logging_configuration = var.enable_audit_log ? {
    "audit_log_enabled" = "ON",
    "audit_log_events" = "ADMIN,CONNECTION,DCL,DDL",
  } : {}
  mysql_default_configuration_items = merge( local.mysql_logging_configuration, {
    "sql_generate_invisible_primary_key" = "OFF",  # resolves recent issues reported by REDCap database checks when using MySQL v8
  }
}

...

resource "azurerm_mysql_flexible_server_configuration" "config_item" {
  for_each            = merge(local.mysql_default_configuration_items, var.mysql_configuration_items)
  resource_group_name = azurerm_resource_group.redcap.name
  name                = each.key
  server_name         = azurerm_mysql_flexible_server.redcap.name
  value               = each.value
}

While not as familiar with the other deployment options, I assume an analog could be created for those deployment options as well.

This will facilitate a number of other features, including enabling audit logging on the MySQL server, addressing the sql_generate_invisible_primary_key issue with MySQL 8.x (see REDCap community entries on that issue), and others.

Example usage in a tfvars file:

mysql_configuration_items = {
  "max_connections" = 255
}
epopisces commented 8 months ago

Side note: I know I'm putting a number of issues on the board. I will try to get some time to fork this project and implement some of these fixes for the Terraform side of things, and submit a PR in the near future.

This is an awesome project, and I'd love to see it make others' REDCap journey on Azure smoother and more successful!

SvenAelterman commented 7 months ago

@epopisces Thanks for contributing the issues. We are actively discussing the value in maintaining the Terraform code. It's likely we will discontinue it and only maintain the Bicep.