Skip to content

Commit

Permalink
Allow creating an organization with many users (#724)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
julienduchesne authored Nov 22, 2022
1 parent 1ac457e commit 0097bdd
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.18
require (
github.com/Masterminds/semver/v3 v3.1.1
github.com/grafana/amixr-api-go-client v0.0.5
github.com/grafana/grafana-api-golang-client v0.13.1
github.com/grafana/grafana-api-golang-client v0.14.0
github.com/grafana/machine-learning-go-client v0.2.0
github.com/grafana/synthetic-monitoring-agent v0.11.0
github.com/grafana/synthetic-monitoring-api-go-client v0.6.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/grafana/amixr-api-go-client v0.0.5 h1:jqmljnd5FozuOsCNuyhZVpooxmj0BW9MmeLA7PaLK6U=
github.com/grafana/amixr-api-go-client v0.0.5/go.mod h1:N6x26XUrM5zGtK5zL5vNJnAn2JFMxLFPPLTw/6pDkFE=
github.com/grafana/grafana-api-golang-client v0.13.1 h1:a5R8bIwL98xd79zFTQnYgpva3ns7Nm5/DnVAWYBdWVk=
github.com/grafana/grafana-api-golang-client v0.13.1/go.mod h1:24W29gPe9yl0/3A9X624TPkAOR8DpHno490cPwnkv8E=
github.com/grafana/grafana-api-golang-client v0.14.0 h1:Jo2oZ85Y58zM7cOzQFxDfKopE3E6oyujU2KCeu7iSFA=
github.com/grafana/grafana-api-golang-client v0.14.0/go.mod h1:24W29gPe9yl0/3A9X624TPkAOR8DpHno490cPwnkv8E=
github.com/grafana/machine-learning-go-client v0.2.0 h1:5JgfJn5Q72D0jZlXnM0gZ9lV4Q4zzq9X0GVfPu8Vxis=
github.com/grafana/machine-learning-go-client v0.2.0/go.mod h1:QFfZz8NkqVF8++skjkKQXJEZfpCYd8S0yTWJUpsLLTA=
github.com/grafana/synthetic-monitoring-agent v0.11.0 h1:B+JAiBqsKx8074A2cVdXG2+pmn5mCkr/Z55E7A+4XTc=
Expand Down
55 changes: 55 additions & 0 deletions grafana/resource_organization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,32 @@ func TestAccOrganization_users(t *testing.T) {
})
}

func TestAccOrganization_createManyUsers(t *testing.T) {
CheckOSSTestsEnabled(t)

var org gapi.Org

resource.Test(t, resource.TestCase{
ProviderFactories: testAccProviderFactories,
CheckDestroy: testAccOrganizationCheckDestroy(&org),
Steps: []resource.TestStep{
{Config: testAccOrganizationConfig_usersCreateMany_1},
{
Config: testAccOrganizationConfig_usersCreateMany_2,
Check: resource.ComposeTestCheckFunc(
testAccOrganizationCheckExists("grafana_organization.test", &org),
resource.TestCheckResourceAttr(
"grafana_organization.test", "name", "terraform-acc-test",
),
resource.TestCheckResourceAttr(
"grafana_organization.test", "admins.#", "1500",
),
),
},
},
})
}

func TestAccOrganization_defaultAdmin(t *testing.T) {
CheckOSSTestsEnabled(t)

Expand Down Expand Up @@ -353,3 +379,32 @@ resource "grafana_organization" "test" {
admins = []
}
`

const testAccOrganizationConfig_usersCreateMany_1 = `
resource "grafana_user" "users" {
count = 1500
name = "user-${count.index}"
email = "user-${count.index}@example.com"
login = "user-${count.index}@example.com"
password = "password"
}
`

const testAccOrganizationConfig_usersCreateMany_2 = `
resource "grafana_user" "users" {
count = 1500
name = "user-${count.index}"
email = "user-${count.index}@example.com"
login = "user-${count.index}@example.com"
password = "password"
}
resource "grafana_organization" "test" {
name = "terraform-acc-test"
admin_user = "admin"
create_users = false
admins = [ for user in grafana_user.users : user.email ]
}
`

0 comments on commit 0097bdd

Please sign in to comment.