Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
epopisces opened this issue Nov 20, 2023 · 2 comments
Labels
terraform Items related to the Terraform IaC code
Milestone

Comments

@epopisces
Copy link

epopisces commented Nov 20, 2023

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 epopisces changed the title Add support for arbitrary number of azurerm_mysql_flexible_server_configuration resources in Terraform Terraform: add support for arbitrary number of azurerm_mysql_flexible_server_configuration resources Nov 20, 2023
@epopisces
Copy link
Author

epopisces commented Nov 20, 2023

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
Copy link
Contributor

@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.

@SvenAelterman SvenAelterman added the terraform Items related to the Terraform IaC code label Nov 25, 2023
@SvenAelterman SvenAelterman added this to the Backlog milestone Dec 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
terraform Items related to the Terraform IaC code
Projects
None yet
Development

No branches or pull requests

2 participants