Skip to content

Commit 2e71bd5

Browse files
author
Peter Junos
committed
Add docs + small test
1 parent 21e6241 commit 2e71bd5

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

mysql/resource_user.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,12 @@ func resourceUser() *schema.Resource {
5858
DiffSuppressFunc: NewEmptyStringSuppressFunc,
5959
ConflictsWith: []string{"plaintext_password", "password"},
6060
},
61+
6162
"auth_string_hashed": {
6263
Type: schema.TypeString,
6364
Optional: true,
6465
DiffSuppressFunc: NewEmptyStringSuppressFunc,
66+
RequiredWith: []string{"auth_plugin"},
6567
ConflictsWith: []string{"plaintext_password", "password"},
6668
},
6769

mysql/resource_user_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,24 @@ func TestAccUser_auth(t *testing.T) {
6565
resource.TestCheckResourceAttr("mysql_user.test", "auth_plugin", "mysql_no_login"),
6666
),
6767
},
68+
{
69+
Config: testAccUserConfig_auth_native,
70+
Check: resource.ComposeTestCheckFunc(
71+
testAccUserAuthExists("mysql_user.test"),
72+
resource.TestCheckResourceAttr("mysql_user.test", "user", "jdoe"),
73+
resource.TestCheckResourceAttr("mysql_user.test", "host", "example.com"),
74+
resource.TestCheckResourceAttr("mysql_user.test", "auth_plugin", "mysql_native_password"),
75+
),
76+
},
77+
{
78+
Config: testAccUserConfig_auth_iam_plugin,
79+
Check: resource.ComposeTestCheckFunc(
80+
testAccUserAuthExists("mysql_user.test"),
81+
resource.TestCheckResourceAttr("mysql_user.test", "user", "jdoe"),
82+
resource.TestCheckResourceAttr("mysql_user.test", "host", "example.com"),
83+
resource.TestCheckResourceAttr("mysql_user.test", "auth_plugin", "mysql_no_login"),
84+
),
85+
},
6886
},
6987
})
7088
}
@@ -232,3 +250,14 @@ resource "mysql_user" "test" {
232250
auth_plugin = "mysql_no_login"
233251
}
234252
`
253+
254+
const testAccUserConfig_auth_native = `
255+
resource "mysql_user" "test" {
256+
user = "jdoe"
257+
host = "example.com"
258+
auth_plugin = "mysql_native_password"
259+
260+
# Hash of "password"
261+
auth_string_hashed = "*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19"
262+
}
263+
`

website/docs/r/user.html.markdown

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ resource "mysql_user" "nologin" {
3636
}
3737
```
3838

39+
## Example Usage with an Authentication Plugin and hashed password
40+
41+
```hcl
42+
resource "mysql_user" "nologin" {
43+
user = "nologin"
44+
host = "example.com"
45+
auth_plugin = "mysql_native_password"
46+
auth_string_hashed = "*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19"
47+
}
48+
```
49+
3950
## Argument Reference
4051

4152
The following arguments are supported:
@@ -45,6 +56,7 @@ The following arguments are supported:
4556
* `plaintext_password` - (Optional) The password for the user. This must be provided in plain text, so the data source for it must be secured. An _unsalted_ hash of the provided password is stored in state. Conflicts with `auth_plugin`.
4657
* `password` - (Optional) Deprecated alias of `plaintext_password`, whose value is *stored as plaintext in state*. Prefer to use `plaintext_password` instead, which stores the password as an unsalted hash. Conflicts with `auth_plugin`.
4758
* `auth_plugin` - (Optional) Use an [authentication plugin][ref-auth-plugins] to authenticate the user instead of using password authentication. Description of the fields allowed in the block below. Conflicts with `password` and `plaintext_password`.
59+
* `auth_string_hashed` - (Optional) Use an already hashed string as a parameter to `auth_plugin`. This can be used with passwords as well as with other auth strings.
4860
* `tls_option` - (Optional) An TLS-Option for the `CREATE USER` or `ALTER USER` statement. The value is suffixed to `REQUIRE`. A value of 'SSL' will generate a `CREATE USER ... REQUIRE SSL` statement. See the [MYSQL `CREATE USER` documentation](https://dev.mysql.com/doc/refman/5.7/en/create-user.html) for more. Ignored if MySQL version is under 5.7.0.
4961

5062
[ref-auth-plugins]: https://dev.mysql.com/doc/refman/5.7/en/authentication-plugins.html
@@ -64,6 +76,7 @@ The `auth_plugin` value supports:
6476

6577
[ref-mysql-no-login]: https://dev.mysql.com/doc/refman/5.7/en/no-login-pluggable-authentication.html
6678

79+
* any other auth plugin supported by MySQL.
6780
## Attributes Reference
6881

6982
The following attributes are exported:

0 commit comments

Comments
 (0)