Skip to content

Commit 0097bdd

Browse files
Allow creating an organization with many users (#724)
* Allow creating an organization with many users Currently, we're limited by the pagination (1000 by default) * Fix loop * 1024 max * oops * Fix the test * oops * Replace the library * New version * Update client version * update client again * go mod update
1 parent 1ac457e commit 0097bdd

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.18
55
require (
66
github.com/Masterminds/semver/v3 v3.1.1
77
github.com/grafana/amixr-api-go-client v0.0.5
8-
github.com/grafana/grafana-api-golang-client v0.13.1
8+
github.com/grafana/grafana-api-golang-client v0.14.0
99
github.com/grafana/machine-learning-go-client v0.2.0
1010
github.com/grafana/synthetic-monitoring-agent v0.11.0
1111
github.com/grafana/synthetic-monitoring-api-go-client v0.6.3

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
7676
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
7777
github.com/grafana/amixr-api-go-client v0.0.5 h1:jqmljnd5FozuOsCNuyhZVpooxmj0BW9MmeLA7PaLK6U=
7878
github.com/grafana/amixr-api-go-client v0.0.5/go.mod h1:N6x26XUrM5zGtK5zL5vNJnAn2JFMxLFPPLTw/6pDkFE=
79-
github.com/grafana/grafana-api-golang-client v0.13.1 h1:a5R8bIwL98xd79zFTQnYgpva3ns7Nm5/DnVAWYBdWVk=
80-
github.com/grafana/grafana-api-golang-client v0.13.1/go.mod h1:24W29gPe9yl0/3A9X624TPkAOR8DpHno490cPwnkv8E=
79+
github.com/grafana/grafana-api-golang-client v0.14.0 h1:Jo2oZ85Y58zM7cOzQFxDfKopE3E6oyujU2KCeu7iSFA=
80+
github.com/grafana/grafana-api-golang-client v0.14.0/go.mod h1:24W29gPe9yl0/3A9X624TPkAOR8DpHno490cPwnkv8E=
8181
github.com/grafana/machine-learning-go-client v0.2.0 h1:5JgfJn5Q72D0jZlXnM0gZ9lV4Q4zzq9X0GVfPu8Vxis=
8282
github.com/grafana/machine-learning-go-client v0.2.0/go.mod h1:QFfZz8NkqVF8++skjkKQXJEZfpCYd8S0yTWJUpsLLTA=
8383
github.com/grafana/synthetic-monitoring-agent v0.11.0 h1:B+JAiBqsKx8074A2cVdXG2+pmn5mCkr/Z55E7A+4XTc=

grafana/resource_organization_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,32 @@ func TestAccOrganization_users(t *testing.T) {
130130
})
131131
}
132132

133+
func TestAccOrganization_createManyUsers(t *testing.T) {
134+
CheckOSSTestsEnabled(t)
135+
136+
var org gapi.Org
137+
138+
resource.Test(t, resource.TestCase{
139+
ProviderFactories: testAccProviderFactories,
140+
CheckDestroy: testAccOrganizationCheckDestroy(&org),
141+
Steps: []resource.TestStep{
142+
{Config: testAccOrganizationConfig_usersCreateMany_1},
143+
{
144+
Config: testAccOrganizationConfig_usersCreateMany_2,
145+
Check: resource.ComposeTestCheckFunc(
146+
testAccOrganizationCheckExists("grafana_organization.test", &org),
147+
resource.TestCheckResourceAttr(
148+
"grafana_organization.test", "name", "terraform-acc-test",
149+
),
150+
resource.TestCheckResourceAttr(
151+
"grafana_organization.test", "admins.#", "1500",
152+
),
153+
),
154+
},
155+
},
156+
})
157+
}
158+
133159
func TestAccOrganization_defaultAdmin(t *testing.T) {
134160
CheckOSSTestsEnabled(t)
135161

@@ -353,3 +379,32 @@ resource "grafana_organization" "test" {
353379
admins = []
354380
}
355381
`
382+
383+
const testAccOrganizationConfig_usersCreateMany_1 = `
384+
resource "grafana_user" "users" {
385+
count = 1500
386+
387+
name = "user-${count.index}"
388+
email = "user-${count.index}@example.com"
389+
login = "user-${count.index}@example.com"
390+
password = "password"
391+
}
392+
`
393+
394+
const testAccOrganizationConfig_usersCreateMany_2 = `
395+
resource "grafana_user" "users" {
396+
count = 1500
397+
398+
name = "user-${count.index}"
399+
email = "user-${count.index}@example.com"
400+
login = "user-${count.index}@example.com"
401+
password = "password"
402+
}
403+
404+
resource "grafana_organization" "test" {
405+
name = "terraform-acc-test"
406+
admin_user = "admin"
407+
create_users = false
408+
admins = [ for user in grafana_user.users : user.email ]
409+
}
410+
`

0 commit comments

Comments
 (0)