petoju / terraform-provider-mysql

Terraform MySQL provider – unofficial fork
https://registry.terraform.io/providers/petoju/mysql
Mozilla Public License 2.0
73 stars 48 forks source link

Specify Default Role for a user? #38

Closed Krobar closed 5 months ago

Krobar commented 2 years ago

Is this possible with this provider?

petoju commented 2 years ago

@Krobar currently, it is not possible.

I am open to PRs implementing it - it could be a separate resource with user and default role.

yadirhb commented 7 months ago

Here a workaround implementation using a null_resource:

resource "null_resource" "activate_default_roles" {
  for_each = mysql_grant.users

  provisioner "local-exec" {
    command     = <<-EOT
      mysql \
        --user='${sensitive(var.target_database_server_administrator_login)}' \
        --password='${sensitive(var.target_database_server_administrator_password)}' \
        --host='${var.target_database_server_hostname}' \
        --port='${var.target_database_server_port}' \
        --database='${each.value.database}' \
        --execute="SET DEFAULT ROLE ALL TO '${each.value.user}'@'${each.value.host}';"
    EOT
    interpreter = ["/bin/bash", "-c"]
    working_dir = path.module
  }
}

... where:

Are the same values supplied to the provider config, ex:

# Configure the MySQL provider
provider "mysql" {
  endpoint = "my-database.example.com:3306"
  username = "app-user"
  password = "app-password"
}
petoju commented 5 months ago

The new resource was released as a part of provider version 3.0.55 - thanks to @rneascu5