Skip to content

Commit 0ecdc7f

Browse files
add support for IAM Group authentication to google_sql_user (#9578) (#16681)
[upstream:05c4410c0e599f33ab255e3820187855c82c7739] Signed-off-by: Modular Magician <[email protected]>
1 parent 2edc05f commit 0ecdc7f

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

.changelog/9578.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note: enhancement
2+
sql: added support for IAM GROUP authentication in the `type` field of `google_sql_user`
3+
```

google/services/sql/resource_sql_user.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,10 @@ func ResourceSqlUser() *schema.Resource {
104104
ForceNew: true,
105105
DiffSuppressFunc: tpgresource.EmptyOrDefaultStringSuppress("BUILT_IN"),
106106
Description: `The user type. It determines the method to authenticate the user during login.
107-
The default is the database's built-in user type. Flags include "BUILT_IN", "CLOUD_IAM_USER", or "CLOUD_IAM_SERVICE_ACCOUNT".`,
108-
ValidateFunc: validation.StringInSlice([]string{"BUILT_IN", "CLOUD_IAM_USER", "CLOUD_IAM_SERVICE_ACCOUNT", ""}, false),
107+
The default is the database's built-in user type. Flags include "BUILT_IN", "CLOUD_IAM_USER", "CLOUD_IAM_SERVICE_ACCOUNT",
108+
"CLOUD_IAM_GROUP", "CLOUD_IAM_GROUP_USER" or "CLOUD_IAM_GROUP_SERVICE_ACCOUNT".`,
109+
ValidateFunc: validation.StringInSlice([]string{"BUILT_IN", "CLOUD_IAM_USER", "CLOUD_IAM_SERVICE_ACCOUNT",
110+
"CLOUD_IAM_GROUP", "CLOUD_IAM_GROUP_USER", "CLOUD_IAM_GROUP_SERVICE_ACCOUNT", ""}, false),
109111
},
110112
"sql_server_user_details": {
111113
Type: schema.TypeList,

google/services/sql/resource_sql_user_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func TestAccSqlUser_mysql(t *testing.T) {
2828
Check: resource.ComposeTestCheckFunc(
2929
testAccCheckGoogleSqlUserExists(t, "google_sql_user.user1"),
3030
testAccCheckGoogleSqlUserExists(t, "google_sql_user.user2"),
31+
testAccCheckGoogleSqlUserExists(t, "google_sql_user.user3"),
3132
),
3233
},
3334
{
@@ -36,6 +37,7 @@ func TestAccSqlUser_mysql(t *testing.T) {
3637
Check: resource.ComposeTestCheckFunc(
3738
testAccCheckGoogleSqlUserExists(t, "google_sql_user.user1"),
3839
testAccCheckGoogleSqlUserExists(t, "google_sql_user.user2"),
40+
testAccCheckGoogleSqlUserExists(t, "google_sql_user.user3"),
3941
),
4042
},
4143
{
@@ -313,6 +315,15 @@ resource "google_sql_user" "user2" {
313315
instance = google_sql_database_instance.instance.name
314316
host = "gmail.com"
315317
password = "hunter2"
318+
type = "CLOUD_IAM_USER"
319+
}
320+
321+
resource "google_sql_user" "user3" {
322+
name = "admin"
323+
instance = google_sql_database_instance.instance.name
324+
host = "gmail.com"
325+
password = "hunter3"
326+
type = "CLOUD_IAM_GROUP"
316327
}
317328
`, instance, password)
318329
}

website/docs/r/sql_user.html.markdown

+20-1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,24 @@ resource "google_sql_user" "iam_service_account_user" {
7272
instance = google_sql_database_instance.main.name
7373
type = "CLOUD_IAM_SERVICE_ACCOUNT"
7474
}
75+
76+
resource "google_sql_user" "iam_group" {
77+
78+
instance = google_sql_database_instance.main.name
79+
type = "CLOUD_IAM_GROUP"
80+
}
81+
82+
resource "google_sql_user" "iam_group_user" {
83+
84+
instance = google_sql_database_instance.main.name
85+
type = "CLOUD_IAM_GROUP_USER"
86+
}
87+
88+
resource "google_sql_user" "iam_group_service_account_user" {
89+
90+
instance = google_sql_database_instance.main.name
91+
type = "CLOUD_IAM_GROUP_SERVICE_ACCOUNT"
92+
}
7593
```
7694

7795
## Argument Reference
@@ -91,7 +109,8 @@ The following arguments are supported:
91109

92110
* `type` - (Optional) The user type. It determines the method to authenticate the
93111
user during login. The default is the database's built-in user type. Flags
94-
include "BUILT_IN", "CLOUD_IAM_USER", or "CLOUD_IAM_SERVICE_ACCOUNT".
112+
include "BUILT_IN", "CLOUD_IAM_USER", "CLOUD_IAM_SERVICE_ACCOUNT",
113+
"CLOUD_IAM_GROUP", "CLOUD_IAM_GROUP_USER" or "CLOUD_IAM_GROUP_SERVICE_ACCOUNT".
95114

96115
* `deletion_policy` - (Optional) The deletion policy for the user.
97116
Setting `ABANDON` allows the resource to be abandoned rather than deleted. This is useful

0 commit comments

Comments
 (0)