-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
datasource/gitlab_group_hook: New Data Source
Refs: #680
- Loading branch information
1 parent
755125a
commit 76100ed
Showing
5 changed files
with
157 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "gitlab_group_hook Data Source - terraform-provider-gitlab" | ||
subcategory: "" | ||
description: |- | ||
The gitlab_group_hook data source allows to retrieve details about a hook in a group. | ||
Upstream API: GitLab REST API docs https://docs.gitlab.com/ee/api/groups.html#get-group-hook | ||
--- | ||
|
||
# gitlab_group_hook (Data Source) | ||
|
||
The `gitlab_group_hook` data source allows to retrieve details about a hook in a group. | ||
|
||
**Upstream API**: [GitLab REST API docs](https://docs.gitlab.com/ee/api/groups.html#get-group-hook) | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "gitlab_group" "example" { | ||
id = "foo/bar/baz" | ||
} | ||
data "gitlab_group_hook" "example" { | ||
group = data.gitlab_group.example.id | ||
hook_id = 1 | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `group` (String) The ID or full path of the group. | ||
- `hook_id` (Number) The id of the group hook. | ||
|
||
### Read-Only | ||
|
||
- `confidential_issues_events` (Boolean) Invoke the hook for confidential issues events. | ||
- `confidential_note_events` (Boolean) Invoke the hook for confidential notes events. | ||
- `deployment_events` (Boolean) Invoke the hook for deployment events. | ||
- `enable_ssl_verification` (Boolean) Enable ssl verification when invoking the hook. | ||
- `group_id` (Number) The id of the group for the hook. | ||
- `id` (String) The ID of this resource. | ||
- `issues_events` (Boolean) Invoke the hook for issues events. | ||
- `job_events` (Boolean) Invoke the hook for job events. | ||
- `merge_requests_events` (Boolean) Invoke the hook for merge requests. | ||
- `note_events` (Boolean) Invoke the hook for notes events. | ||
- `pipeline_events` (Boolean) Invoke the hook for pipeline events. | ||
- `push_events` (Boolean) Invoke the hook for push events. | ||
- `push_events_branch_filter` (String) Invoke the hook for push events on matching branches only. | ||
- `releases_events` (Boolean) Invoke the hook for releases events. | ||
- `subgroup_events` (Boolean) Invoke the hook for subgroup events. | ||
- `tag_push_events` (Boolean) Invoke the hook for tag push events. | ||
- `token` (String) A token to present when invoking the hook. The token is not available for imported resources. | ||
- `url` (String) The url of the hook to invoke. | ||
- `wiki_page_events` (Boolean) Invoke the hook for wiki page events. | ||
|
||
|
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,8 @@ | ||
data "gitlab_group" "example" { | ||
id = "foo/bar/baz" | ||
} | ||
|
||
data "gitlab_group_hook" "example" { | ||
group = data.gitlab_group.example.id | ||
hook_id = 1 | ||
} |
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,39 @@ | ||
package provider | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/xanzy/go-gitlab" | ||
) | ||
|
||
var _ = registerDataSource("gitlab_group_hook", func() *schema.Resource { | ||
return &schema.Resource{ | ||
Description: `The ` + "`gitlab_group_hook`" + ` data source allows to retrieve details about a hook in a group. | ||
**Upstream API**: [GitLab REST API docs](https://docs.gitlab.com/ee/api/groups.html#get-group-hook)`, | ||
|
||
ReadContext: dataSourceGitlabGroupHookRead, | ||
Schema: datasourceSchemaFromResourceSchema(gitlabGroupHookSchema(), []string{"group", "hook_id"}, nil), | ||
} | ||
}) | ||
|
||
func dataSourceGitlabGroupHookRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
client := meta.(*gitlab.Client) | ||
group := d.Get("group").(string) | ||
hookID := d.Get("hook_id").(int) | ||
|
||
hook, _, err := client.Groups.GetGroupHook(group, hookID, gitlab.WithContext(ctx)) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
d.SetId(fmt.Sprintf("%s:%d", group, hookID)) | ||
stateMap := gitlabGroupHookToStateMap(group, hook) | ||
if err := setStateMapInResourceData(stateMap, d); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//go:build acceptance | ||
// +build acceptance | ||
|
||
package provider | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceGitlabGroupHook_basic(t *testing.T) { | ||
testGroup := testAccCreateGroups(t, 1)[0] | ||
testHook := testAccCreateGroupHooks(t, testGroup.ID, 1)[0] | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
ProviderFactories: providerFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: fmt.Sprintf(` | ||
data "gitlab_group_hook" "this" { | ||
group = "%s" | ||
hook_id = %d | ||
} | ||
`, testGroup.FullPath, testHook.ID), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.gitlab_group_hook.this", "hook_id", fmt.Sprintf("%d", testHook.ID)), | ||
resource.TestCheckResourceAttr("data.gitlab_group_hook.this", "group_id", fmt.Sprintf("%d", testGroup.ID)), | ||
resource.TestCheckResourceAttr("data.gitlab_group_hook.this", "url", testHook.URL), | ||
), | ||
}, | ||
}, | ||
}) | ||
} |
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