Skip to content
This repository has been archived by the owner on Jan 12, 2021. It is now read-only.

Granting roles to user requires useless database parameter #122

Open
tomalok opened this issue Mar 22, 2020 · 0 comments
Open

Granting roles to user requires useless database parameter #122

tomalok opened this issue Mar 22, 2020 · 0 comments

Comments

@tomalok
Copy link

tomalok commented Mar 22, 2020

Terraform Version

Terraform v0.12.23`
* provider.mysql: version = "~> 1.9"

MariaDB 10.4.12

Affected Resource(s)

mysql_grant (when granting roles to user)

Terraform Configuration Files

resource mysql_database "test_db" {
  name = "test_db"
}

resource mysql_role "test_role" {
  name = "test_role"
}

resource mysql_user "test_user" {
  user = "test_user"
}

resource mysql_grant "test_role_grant" {
  role        = mysql_role.test_role.name
  database    = mysql_database.test_db.name
  privileges  = [ "SELECT" ]
}

resource mysql_grant "test_user_grant_roles" {
  user      = mysql_user.test_user.user
  roles     = [ mysql_role.test_role.name ]
  database  = mysql_database.test_db.name # insists required, but is unnecessary
}

Plan Output

  # mysql_database.test_db will be created
  + resource "mysql_database" "test_db" {
      + default_character_set = "utf8"
      + default_collation     = "utf8_general_ci"
      + id                    = (known after apply)
      + name                  = "test_db"
    }

  # mysql_grant.test_role_grant will be created
  + resource "mysql_grant" "test_role_grant" {
      + database   = "test_db"
      + grant      = false
      + host       = "localhost"
      + id         = (known after apply)
      + privileges = [
          + "SELECT",
        ]
      + role       = "test_role"
      + table      = "*"
      + tls_option = "NONE"
    }

  # mysql_grant.test_user_grant_roles will be created
  + resource "mysql_grant" "test_user_grant_roles" {
      + database   = "test_db"
      + grant      = false
      + host       = "localhost"
      + id         = (known after apply)
      + roles      = [
          + "test_role",
        ]
      + table      = "*"
      + tls_option = "NONE"
      + user       = "test_user"
    }

  # mysql_role.test_role will be created
  + resource "mysql_role" "test_role" {
      + id   = (known after apply)
      + name = "test_role"
    }

  # mysql_user.test_user will be created
  + resource "mysql_user" "test_user" {
      + host       = "localhost"
      + id         = (known after apply)
      + tls_option = "NONE"
      + user       = "test_user"
    }

Resulting GRANTs

MariaDB [(none)]> show grants for 'test_role';
+--------------------------------------------+
| Grants for test_role                       |
+--------------------------------------------+
| GRANT USAGE ON *.* TO 'test_role'          |
| GRANT SELECT ON `test_db`.* TO 'test_role' |
+--------------------------------------------+
MariaDB [(none)]> show grants for 'test_user'@'localhost';
+-----------------------------------------------+
| Grants for test_user@localhost                |
+-----------------------------------------------+
| GRANT test_role TO 'test_user'@'localhost'    |
| GRANT USAGE ON *.* TO 'test_user'@'localhost' |
+-----------------------------------------------+

Expected Behavior

The mysql_grant resource should not require database attribute when roles attribute is being set. The database and table attributes probably should also be disallowed (like privileges) when roles is present.

Actual Behavior

The mysql_grant resource is requiring the unnecessary (and unused) database attribute when the roles attribute is being set.

As An Aside...

The MySQL Terraform provider's host default of localhost does not match MySQL/MariaDB's default of % when host is not specified.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant