Skip to content

Commit e29384e

Browse files
Teams: Skip team synced members when reading team status (#702)
* skip team synced members * add flag that allows skipping team synced members * generate docs for the new field * update Golang API client dependency * fix tests * fix broken link * fix tests attempt 2 * uncomment test conditionals
1 parent 954d88e commit e29384e

File tree

5 files changed

+28
-9
lines changed

5 files changed

+28
-9
lines changed

docs/resources/team.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ resource "grafana_team" "test-team" {
3333
### Optional
3434

3535
- `email` (String) An email address for the team.
36+
- `ignore_externally_synced_members` (Boolean) Ignores team members that have been added to team by [Team Sync](https://grafana.com/docs/grafana/latest/enterprise/team-sync/).
37+
Team Sync can be provisioned using [grafana_team_external_group resource](https://registry.terraform.io/providers/grafana/grafana/latest/docs/resources/team_external_group).
38+
Defaults to `true`.
3639
- `members` (Set of String) A set of email addresses corresponding to users who should be given membership
3740
to the team. Note: users specified here must already exist in Grafana.
3841

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.12.1
8+
github.com/grafana/grafana-api-golang-client v0.13.0
99
github.com/grafana/machine-learning-go-client v0.1.1
1010
github.com/grafana/synthetic-monitoring-agent v0.9.4
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
@@ -115,8 +115,8 @@ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
115115
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
116116
github.com/grafana/amixr-api-go-client v0.0.5 h1:jqmljnd5FozuOsCNuyhZVpooxmj0BW9MmeLA7PaLK6U=
117117
github.com/grafana/amixr-api-go-client v0.0.5/go.mod h1:N6x26XUrM5zGtK5zL5vNJnAn2JFMxLFPPLTw/6pDkFE=
118-
github.com/grafana/grafana-api-golang-client v0.12.1 h1:GLkNXslTWf/ZBxjRHK6VYW6FSqFnhaiA47pTZe9GUBw=
119-
github.com/grafana/grafana-api-golang-client v0.12.1/go.mod h1:24W29gPe9yl0/3A9X624TPkAOR8DpHno490cPwnkv8E=
118+
github.com/grafana/grafana-api-golang-client v0.13.0 h1:o/gL3F7EjBSBKgrpjH9/+sYFJ0HBUofvAYlKhrT2opE=
119+
github.com/grafana/grafana-api-golang-client v0.13.0/go.mod h1:24W29gPe9yl0/3A9X624TPkAOR8DpHno490cPwnkv8E=
120120
github.com/grafana/machine-learning-go-client v0.1.1 h1:Gw6cX8xAd6IVF2LApkXOIdBK8Gzz07B3jQPukecw7fc=
121121
github.com/grafana/machine-learning-go-client v0.1.1/go.mod h1:QFfZz8NkqVF8++skjkKQXJEZfpCYd8S0yTWJUpsLLTA=
122122
github.com/grafana/synthetic-monitoring-agent v0.9.4 h1:Enx5s6gFbc/RAzL5KDX/00catAlbcY7/1IFPBe5lo/c=

grafana/resource_team.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ func ResourceTeam() *schema.Resource {
6969
Description: `
7070
A set of email addresses corresponding to users who should be given membership
7171
to the team. Note: users specified here must already exist in Grafana.
72+
`,
73+
},
74+
"ignore_externally_synced_members": {
75+
Type: schema.TypeBool,
76+
Optional: true,
77+
Default: true,
78+
Description: `
79+
Ignores team members that have been added to team by [Team Sync](https://grafana.com/docs/grafana/latest/enterprise/team-sync/).
80+
Team Sync can be provisioned using [grafana_team_external_group resource](https://registry.terraform.io/providers/grafana/grafana/latest/docs/resources/team_external_group).
7281
`,
7382
},
7483
},
@@ -158,6 +167,11 @@ func ReadMembers(d *schema.ResourceData, meta interface{}) error {
158167
if teamMember.Email == "admin@localhost" {
159168
continue
160169
}
170+
// Labels store information about auth provider used to sync the team member.
171+
// Team synced members should be managed through team_external_group resource and should be ignored here.
172+
if d.Get("ignore_externally_synced_members").(bool) && len(teamMember.Labels) > 0 {
173+
continue
174+
}
161175
memberSlice = append(memberSlice, teamMember.Email)
162176
}
163177
d.Set("members", memberSlice)

grafana/resource_team_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ func TestAccTeam_basic(t *testing.T) {
4747
),
4848
},
4949
{
50-
ResourceName: "grafana_team.test",
51-
ImportState: true,
52-
ImportStateVerify: true,
50+
ResourceName: "grafana_team.test",
51+
ImportState: true,
52+
ImportStateVerify: true,
53+
ImportStateVerifyIgnore: []string{"ignore_externally_synced_members"},
5354
},
5455
},
5556
})
@@ -102,9 +103,10 @@ func TestAccTeam_Members(t *testing.T) {
102103
},
103104
// Test the import with members
104105
{
105-
ResourceName: "grafana_team.test",
106-
ImportState: true,
107-
ImportStateVerify: true,
106+
ResourceName: "grafana_team.test",
107+
ImportState: true,
108+
ImportStateVerify: true,
109+
ImportStateVerifyIgnore: []string{"ignore_externally_synced_members"},
108110
},
109111
{
110112
Config: testAccTeamConfig_memberRemove,

0 commit comments

Comments
 (0)