-
Notifications
You must be signed in to change notification settings - Fork 318
Add GitLab Data Group #129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5dd94a6
add some computed fields to gitlab group resource
matejvelikonja c78677c
update gitlab group resource documentation
matejvelikonja 5a70aa4
add gitlab group data resource
matejvelikonja 435ba8d
add documentation for the gitlab group data resource
matejvelikonja 94360d7
fix wrong conflicts with
matejvelikonja 8705fed
add gitlab_group data resource to side menu
matejvelikonja File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,112 @@ | ||
| package gitlab | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "github.com/hashicorp/terraform/helper/schema" | ||
| "github.com/xanzy/go-gitlab" | ||
| "log" | ||
| ) | ||
|
|
||
| func dataSourceGitlabGroup() *schema.Resource { | ||
| return &schema.Resource{ | ||
| Read: dataSourceGitlabGroupRead, | ||
| Schema: map[string]*schema.Schema{ | ||
| "group_id": { | ||
| Type: schema.TypeInt, | ||
| Computed: true, | ||
| Optional: true, | ||
| ConflictsWith: []string{ | ||
| "full_path", | ||
| }, | ||
| }, | ||
| "full_path": { | ||
| Type: schema.TypeString, | ||
| Computed: true, | ||
| Optional: true, | ||
| ConflictsWith: []string{ | ||
| "group_id", | ||
| }, | ||
| }, | ||
| "name": { | ||
| Type: schema.TypeString, | ||
| Computed: true, | ||
| }, | ||
| "full_name": { | ||
| Type: schema.TypeString, | ||
| Computed: true, | ||
| }, | ||
| "web_url": { | ||
| Type: schema.TypeString, | ||
| Computed: true, | ||
| }, | ||
| "path": { | ||
| Type: schema.TypeString, | ||
| Computed: true, | ||
| }, | ||
| "description": { | ||
| Type: schema.TypeString, | ||
| Computed: true, | ||
| }, | ||
| "lfs_enabled": { | ||
| Type: schema.TypeBool, | ||
| Computed: true, | ||
| }, | ||
| "request_access_enabled": { | ||
| Type: schema.TypeBool, | ||
| Computed: true, | ||
| }, | ||
| "visibility_level": { | ||
| Type: schema.TypeString, | ||
| Computed: true, | ||
| }, | ||
| "parent_id": { | ||
| Type: schema.TypeInt, | ||
| Computed: true, | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func dataSourceGitlabGroupRead(d *schema.ResourceData, meta interface{}) error { | ||
| client := meta.(*gitlab.Client) | ||
|
|
||
| var group *gitlab.Group | ||
| var err error | ||
|
|
||
| log.Printf("[INFO] Reading Gitlab group") | ||
|
|
||
| groupIDData, groupIDOk := d.GetOk("group_id") | ||
| fullPathData, fullPathOk := d.GetOk("full_path") | ||
|
|
||
| if groupIDOk { | ||
| // Get group by id | ||
| group, _, err = client.Groups.GetGroup(groupIDData.(int)) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| } else if fullPathOk { | ||
| // Get group by full path | ||
| group, _, err = client.Groups.GetGroup(fullPathData.(string)) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| } else { | ||
| return fmt.Errorf("one and only one of group_id or full_path must be set") | ||
| } | ||
|
|
||
| d.Set("group_id", group.ID) | ||
| d.Set("full_path", group.FullPath) | ||
| d.Set("name", group.Name) | ||
| d.Set("full_name", group.FullName) | ||
| d.Set("web_url", group.WebURL) | ||
| d.Set("path", group.Path) | ||
| d.Set("description", group.Description) | ||
| d.Set("lfs_enabled", group.LFSEnabled) | ||
| d.Set("request_access_enabled", group.RequestAccessEnabled) | ||
| d.Set("visibility_level", group.Visibility) | ||
| d.Set("parent_id", group.ParentID) | ||
|
|
||
| d.SetId(fmt.Sprintf("%d", group.ID)) | ||
|
|
||
| return nil | ||
| } | ||
This file contains hidden or 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,111 @@ | ||
| package gitlab | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| "github.com/hashicorp/terraform/helper/acctest" | ||
| "github.com/hashicorp/terraform/helper/resource" | ||
| "github.com/hashicorp/terraform/terraform" | ||
| ) | ||
|
|
||
| func TestAccDataSourceGitlabGroup_basic(t *testing.T) { | ||
| rString := fmt.Sprintf("%s", acctest.RandString(5)) | ||
|
|
||
| resource.Test(t, resource.TestCase{ | ||
| PreCheck: func() { testAccPreCheck(t) }, | ||
| Providers: testAccProviders, | ||
| Steps: []resource.TestStep{ | ||
| // Get group using its ID | ||
| { | ||
| Config: testAccDataGitlabGroupByID(rString), | ||
| Check: resource.ComposeTestCheckFunc( | ||
| testAccDataSourceGitlabGroup("gitlab_group.foo", "data.gitlab_group.foo"), | ||
| ), | ||
| }, | ||
| // Get group using its full path | ||
| { | ||
| Config: testAccDataGitlabGroupByFullPath(rString), | ||
| Check: resource.ComposeTestCheckFunc( | ||
| testAccDataSourceGitlabGroup("gitlab_group.sub_foo", "data.gitlab_group.sub_foo"), | ||
| ), | ||
| }, | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| func testAccDataSourceGitlabGroup(src, n string) resource.TestCheckFunc { | ||
| return func(s *terraform.State) error { | ||
|
|
||
| group := s.RootModule().Resources[src] | ||
| groupResource := group.Primary.Attributes | ||
|
|
||
| search := s.RootModule().Resources[n] | ||
| searchResource := search.Primary.Attributes | ||
|
|
||
| testAttributes := []string{ | ||
| "id", | ||
| "full_path", | ||
| "name", | ||
| "full_name", | ||
| "web_url", | ||
| "path", | ||
| "description", | ||
| "lfs_enabled", | ||
| "request_access_enabled", | ||
| "visibility_level", | ||
| "parent_id", | ||
| } | ||
|
|
||
| for _, attribute := range testAttributes { | ||
| if searchResource[attribute] != groupResource[attribute] { | ||
| return fmt.Errorf("expected group's parameter `%s` to be: %s, but got: `%s`", attribute, groupResource[attribute], searchResource[attribute]) | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
| } | ||
|
|
||
| func testAccDataGitlabGroupByID(rString string) string { | ||
| return fmt.Sprintf(` | ||
| %s | ||
|
|
||
| data "gitlab_group" "foo" { | ||
| group_id = "${gitlab_group.foo.id}" | ||
| } | ||
| `, testAccDataGitlabGroupSetup(rString)) | ||
| } | ||
|
|
||
| func testAccDataGitlabGroupByFullPath(rString string) string { | ||
| return fmt.Sprintf(` | ||
| %s | ||
|
|
||
| data "gitlab_group" "sub_foo" { | ||
| full_path = "${gitlab_group.foo.path}/${gitlab_group.sub_foo.path}" | ||
| } | ||
| `, testAccDataGitlabGroupSetup(rString)) | ||
| } | ||
|
|
||
| func testAccDataGitlabGroupSetup(rString string) string { | ||
| return fmt.Sprintf(` | ||
| resource "gitlab_group" "foo" { | ||
| name = "foo-name-%[1]s" | ||
| path = "foo-path-%[1]s" | ||
|
|
||
| # So that acceptance tests can be run in a gitlab organization | ||
| # with no billing | ||
| visibility_level = "public" | ||
| } | ||
|
|
||
| resource "gitlab_group" "sub_foo" { | ||
| name = "sub-foo-name-%[1]s" | ||
| path = "sub-foo-path-%[1]s" | ||
| parent_id = "${gitlab_group.foo.id}" | ||
|
|
||
| # So that acceptance tests can be run in a gitlab organization | ||
| # with no billing | ||
| visibility_level = "public" | ||
| } | ||
| `, rString) | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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,67 @@ | ||
| --- | ||
| layout: "gitlab" | ||
| page_title: "GitLab: gitlab_group" | ||
| sidebar_current: "docs-gitlab-data-source-group" | ||
| description: |- | ||
| Looks up a gitlab group | ||
| --- | ||
|
|
||
| # gitlab\_group | ||
|
|
||
| Provides details about a specific group in the gitlab provider. | ||
|
|
||
| ## Example Usage | ||
|
|
||
| **By group's ID** | ||
|
|
||
| ```hcl | ||
| data "gitlab_group" "foo" { | ||
| group_id = 123 | ||
| } | ||
| ``` | ||
|
|
||
| **By group's full path** | ||
|
|
||
| ```hcl | ||
| data "gitlab_group" "foo" { | ||
| full_path = "foo/bar" | ||
| } | ||
| ``` | ||
|
|
||
| ## Argument Reference | ||
|
|
||
| The following arguments are supported: | ||
|
|
||
| * `group_id` - (Optional) The ID of the group. | ||
|
|
||
| * `full_path` - (Optional) The full path of the group. | ||
|
|
||
| **Note**: exactly one of group_id or full_path must be provided. | ||
|
|
||
| ## Attributes Reference | ||
|
|
||
| The resource exports the following attributes: | ||
|
|
||
| * `id` - The unique ID assigned to the group. | ||
|
|
||
| * `name` - The name of this group. | ||
|
|
||
| * `path` - The path of the group. | ||
|
|
||
| * `description` - The description of the group. | ||
|
|
||
| * `lfs_enabled` - Boolean, is LFS enabled for projects in this group. | ||
|
|
||
| * `request_access_enabled` - Boolean, is request for access enabled to the group. | ||
|
|
||
| * `visibility_level` - Visibility level of the group. Possible values are `private`, `internal`, `public`. | ||
|
|
||
| * `parent_id` - Integer, ID of the parent group. | ||
|
|
||
| * `full_path` - The full path of the group. | ||
|
|
||
| * `full_name` - The full name of the group. | ||
|
|
||
| * `web_url` - Web URL of the group. | ||
|
|
||
| [doc]: https://docs.gitlab.com/ee/api/groups.html#details-of-a-group |
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.