forked from integrations/terraform-provider-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create data source for external groups (integrations#1185)
* Initial commit of EMU data source * Set groups in state * Some renames * Correct google/go-github client version to v45 in new data source * Rename data source file to something more appropriate * Set a sensible ID * Add documentation for new data source * Fix website formatting
- Loading branch information
1 parent
12ddfc3
commit 1ce402b
Showing
5 changed files
with
118 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package github | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/google/go-github/v45/github" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
) | ||
|
||
func dataSourceGithubExternalGroups() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceGithubExternalGroupsRead, | ||
Schema: map[string]*schema.Schema{ | ||
"external_groups": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"group_id": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
"group_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"updated_at": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceGithubExternalGroupsRead(d *schema.ResourceData, meta interface{}) error { | ||
err := checkOrganization(meta) | ||
if err != nil { | ||
return err | ||
} | ||
client := meta.(*Owner).v3client | ||
orgName := meta.(*Owner).name | ||
|
||
ctx := context.WithValue(context.Background(), ctxId, d.Id()) | ||
opts := &github.ListExternalGroupsOptions{} | ||
|
||
externalGroups, _, err := client.Teams.ListExternalGroups(ctx, orgName, opts) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// convert to JSON in order to martial to format we can return | ||
jsonGroups, err := json.Marshal(externalGroups.Groups) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
groupsState := make([]map[string]interface{}, 0) | ||
err = json.Unmarshal(jsonGroups, &groupsState) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err := d.Set("external_groups", groupsState); err != nil { | ||
return err | ||
} | ||
|
||
d.SetId(fmt.Sprintf("/orgs/%v/external-groups", orgName)) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--- | ||
layout: "github" | ||
page_title: "GitHub: github_external_group" | ||
description: |- | ||
Retrieve external groups belonging to an organization. | ||
--- | ||
|
||
# github\_external\_group | ||
|
||
Use this data source to retrieve external groups belonging to an organization. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "github_external_groups" "example_external_groups" {} | ||
locals { | ||
local_groups = "${data.github_external_groups.example_external_groups}" | ||
} | ||
output "groups" { | ||
value = local.local_groups | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
N/A. This resource will retrieve all the external groups belonging to an organization. | ||
|
||
## Attributes Reference | ||
|
||
* `external_groups` - an array of external groups belonging to the organization. Each group consists of the fields documented below. | ||
|
||
___ | ||
|
||
|
||
* `group_id` - the ID of the group. | ||
* `group_name` - the name of the group. | ||
* `updated_at` - the date the group was last updated. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters