Skip to content

Commit cdab8f5

Browse files
authored
Merge pull request #1221 from timofurrer/feature/group-hooks
Group Hook Resource and Data Sources
2 parents 00a121b + 412cae7 commit cdab8f5

15 files changed

+888
-0
lines changed

docs/data-sources/group_hook.md

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "gitlab_group_hook Data Source - terraform-provider-gitlab"
4+
subcategory: ""
5+
description: |-
6+
The gitlab_group_hook data source allows to retrieve details about a hook in a group.
7+
Upstream API: GitLab REST API docs https://docs.gitlab.com/ee/api/groups.html#get-group-hook
8+
---
9+
10+
# gitlab_group_hook (Data Source)
11+
12+
The `gitlab_group_hook` data source allows to retrieve details about a hook in a group.
13+
14+
**Upstream API**: [GitLab REST API docs](https://docs.gitlab.com/ee/api/groups.html#get-group-hook)
15+
16+
## Example Usage
17+
18+
```terraform
19+
data "gitlab_group" "example" {
20+
id = "foo/bar/baz"
21+
}
22+
23+
data "gitlab_group_hook" "example" {
24+
group = data.gitlab_group.example.id
25+
hook_id = 1
26+
}
27+
```
28+
29+
<!-- schema generated by tfplugindocs -->
30+
## Schema
31+
32+
### Required
33+
34+
- `group` (String) The ID or full path of the group.
35+
- `hook_id` (Number) The id of the group hook.
36+
37+
### Read-Only
38+
39+
- `confidential_issues_events` (Boolean) Invoke the hook for confidential issues events.
40+
- `confidential_note_events` (Boolean) Invoke the hook for confidential notes events.
41+
- `deployment_events` (Boolean) Invoke the hook for deployment events.
42+
- `enable_ssl_verification` (Boolean) Enable ssl verification when invoking the hook.
43+
- `group_id` (Number) The id of the group for the hook.
44+
- `id` (String) The ID of this resource.
45+
- `issues_events` (Boolean) Invoke the hook for issues events.
46+
- `job_events` (Boolean) Invoke the hook for job events.
47+
- `merge_requests_events` (Boolean) Invoke the hook for merge requests.
48+
- `note_events` (Boolean) Invoke the hook for notes events.
49+
- `pipeline_events` (Boolean) Invoke the hook for pipeline events.
50+
- `push_events` (Boolean) Invoke the hook for push events.
51+
- `push_events_branch_filter` (String) Invoke the hook for push events on matching branches only.
52+
- `releases_events` (Boolean) Invoke the hook for releases events.
53+
- `subgroup_events` (Boolean) Invoke the hook for subgroup events.
54+
- `tag_push_events` (Boolean) Invoke the hook for tag push events.
55+
- `token` (String) A token to present when invoking the hook. The token is not available for imported resources.
56+
- `url` (String) The url of the hook to invoke.
57+
- `wiki_page_events` (Boolean) Invoke the hook for wiki page events.
58+
59+

docs/data-sources/group_hooks.md

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "gitlab_group_hooks Data Source - terraform-provider-gitlab"
4+
subcategory: ""
5+
description: |-
6+
The gitlab_group_hooks data source allows to retrieve details about hooks in a group.
7+
Upstream API: GitLab REST API docs https://docs.gitlab.com/ee/api/groups.html#list-group-hooks
8+
---
9+
10+
# gitlab_group_hooks (Data Source)
11+
12+
The `gitlab_group_hooks` data source allows to retrieve details about hooks in a group.
13+
14+
**Upstream API**: [GitLab REST API docs](https://docs.gitlab.com/ee/api/groups.html#list-group-hooks)
15+
16+
## Example Usage
17+
18+
```terraform
19+
data "gitlab_group" "example" {
20+
id = "foo/bar/baz"
21+
}
22+
23+
data "gitlab_group_hooks" "examples" {
24+
group = data.gitlab_group.example.id
25+
}
26+
```
27+
28+
<!-- schema generated by tfplugindocs -->
29+
## Schema
30+
31+
### Required
32+
33+
- `group` (String) The ID or full path of the group.
34+
35+
### Read-Only
36+
37+
- `hooks` (List of Object) The list of hooks. (see [below for nested schema](#nestedatt--hooks))
38+
- `id` (String) The ID of this resource.
39+
40+
<a id="nestedatt--hooks"></a>
41+
### Nested Schema for `hooks`
42+
43+
Read-Only:
44+
45+
- `confidential_issues_events` (Boolean)
46+
- `confidential_note_events` (Boolean)
47+
- `deployment_events` (Boolean)
48+
- `enable_ssl_verification` (Boolean)
49+
- `group` (String)
50+
- `group_id` (Number)
51+
- `hook_id` (Number)
52+
- `issues_events` (Boolean)
53+
- `job_events` (Boolean)
54+
- `merge_requests_events` (Boolean)
55+
- `note_events` (Boolean)
56+
- `pipeline_events` (Boolean)
57+
- `push_events` (Boolean)
58+
- `push_events_branch_filter` (String)
59+
- `releases_events` (Boolean)
60+
- `subgroup_events` (Boolean)
61+
- `tag_push_events` (Boolean)
62+
- `token` (String)
63+
- `url` (String)
64+
- `wiki_page_events` (Boolean)
65+
66+

docs/resources/group_hook.md

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "gitlab_group_hook Resource - terraform-provider-gitlab"
4+
subcategory: ""
5+
description: |-
6+
The gitlab_group_hook resource allows to manage the lifecycle of a group hook.
7+
Upstream API: GitLab REST API docs https://docs.gitlab.com/ee/api/groups.html#hooks
8+
---
9+
10+
# gitlab_group_hook (Resource)
11+
12+
The `gitlab_group_hook` resource allows to manage the lifecycle of a group hook.
13+
14+
**Upstream API**: [GitLab REST API docs](https://docs.gitlab.com/ee/api/groups.html#hooks)
15+
16+
## Example Usage
17+
18+
```terraform
19+
resource "gitlab_group_hook" "example" {
20+
group = "example/hooked"
21+
url = "https://example.com/hook/example"
22+
merge_requests_events = true
23+
}
24+
25+
# Setting all attributes
26+
resource "gitlab_group_hook" "all_attributes" {
27+
group = 1
28+
url = "http://example.com"
29+
token = "supersecret"
30+
enable_ssl_verification = false
31+
push_events = true
32+
push_events_branch_filter = "devel"
33+
issues_events = false
34+
confidential_issues_events = false
35+
merge_requests_events = true
36+
tag_push_events = true
37+
note_events = true
38+
confidential_note_events = true
39+
job_events = true
40+
pipeline_events = true
41+
wiki_page_events = true
42+
deployment_events = true
43+
releases_events = true
44+
subgroup_events = true
45+
}
46+
```
47+
48+
<!-- schema generated by tfplugindocs -->
49+
## Schema
50+
51+
### Required
52+
53+
- `group` (String) The ID or full path of the group.
54+
- `url` (String) The url of the hook to invoke.
55+
56+
### Optional
57+
58+
- `confidential_issues_events` (Boolean) Invoke the hook for confidential issues events.
59+
- `confidential_note_events` (Boolean) Invoke the hook for confidential notes events.
60+
- `deployment_events` (Boolean) Invoke the hook for deployment events.
61+
- `enable_ssl_verification` (Boolean) Enable ssl verification when invoking the hook.
62+
- `issues_events` (Boolean) Invoke the hook for issues events.
63+
- `job_events` (Boolean) Invoke the hook for job events.
64+
- `merge_requests_events` (Boolean) Invoke the hook for merge requests.
65+
- `note_events` (Boolean) Invoke the hook for notes events.
66+
- `pipeline_events` (Boolean) Invoke the hook for pipeline events.
67+
- `push_events` (Boolean) Invoke the hook for push events.
68+
- `push_events_branch_filter` (String) Invoke the hook for push events on matching branches only.
69+
- `releases_events` (Boolean) Invoke the hook for releases events.
70+
- `subgroup_events` (Boolean) Invoke the hook for subgroup events.
71+
- `tag_push_events` (Boolean) Invoke the hook for tag push events.
72+
- `token` (String, Sensitive) A token to present when invoking the hook. The token is not available for imported resources.
73+
- `wiki_page_events` (Boolean) Invoke the hook for wiki page events.
74+
75+
### Read-Only
76+
77+
- `group_id` (Number) The id of the group for the hook.
78+
- `hook_id` (Number) The id of the group hook.
79+
- `id` (String) The ID of this resource.
80+
81+
## Import
82+
83+
Import is supported using the following syntax:
84+
85+
```shell
86+
# A GitLab Group Hook can be imported using a key composed of `<group-id>:<hook-id>`, e.g.
87+
terraform import gitlab_group_hook.example "12345:1"
88+
89+
# NOTE: the `token` resource attribute is not available for imported resources as this information cannot be read from the GitLab API.
90+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
data "gitlab_group" "example" {
2+
id = "foo/bar/baz"
3+
}
4+
5+
data "gitlab_group_hook" "example" {
6+
group = data.gitlab_group.example.id
7+
hook_id = 1
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
data "gitlab_group" "example" {
2+
id = "foo/bar/baz"
3+
}
4+
5+
data "gitlab_group_hooks" "examples" {
6+
group = data.gitlab_group.example.id
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# A GitLab Group Hook can be imported using a key composed of `<group-id>:<hook-id>`, e.g.
2+
terraform import gitlab_group_hook.example "12345:1"
3+
4+
# NOTE: the `token` resource attribute is not available for imported resources as this information cannot be read from the GitLab API.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
resource "gitlab_group_hook" "example" {
2+
group = "example/hooked"
3+
url = "https://example.com/hook/example"
4+
merge_requests_events = true
5+
}
6+
7+
# Setting all attributes
8+
resource "gitlab_group_hook" "all_attributes" {
9+
group = 1
10+
url = "http://example.com"
11+
token = "supersecret"
12+
enable_ssl_verification = false
13+
push_events = true
14+
push_events_branch_filter = "devel"
15+
issues_events = false
16+
confidential_issues_events = false
17+
merge_requests_events = true
18+
tag_push_events = true
19+
note_events = true
20+
confidential_note_events = true
21+
job_events = true
22+
pipeline_events = true
23+
wiki_page_events = true
24+
deployment_events = true
25+
releases_events = true
26+
subgroup_events = true
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package provider
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
9+
"github.com/xanzy/go-gitlab"
10+
)
11+
12+
var _ = registerDataSource("gitlab_group_hook", func() *schema.Resource {
13+
return &schema.Resource{
14+
Description: `The ` + "`gitlab_group_hook`" + ` data source allows to retrieve details about a hook in a group.
15+
16+
**Upstream API**: [GitLab REST API docs](https://docs.gitlab.com/ee/api/groups.html#get-group-hook)`,
17+
18+
ReadContext: dataSourceGitlabGroupHookRead,
19+
Schema: datasourceSchemaFromResourceSchema(gitlabGroupHookSchema(), []string{"group", "hook_id"}, nil),
20+
}
21+
})
22+
23+
func dataSourceGitlabGroupHookRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
24+
client := meta.(*gitlab.Client)
25+
group := d.Get("group").(string)
26+
hookID := d.Get("hook_id").(int)
27+
28+
hook, _, err := client.Groups.GetGroupHook(group, hookID, gitlab.WithContext(ctx))
29+
if err != nil {
30+
return diag.FromErr(err)
31+
}
32+
33+
d.SetId(fmt.Sprintf("%s:%d", group, hookID))
34+
stateMap := gitlabGroupHookToStateMap(group, hook)
35+
if err := setStateMapInResourceData(stateMap, d); err != nil {
36+
return diag.FromErr(err)
37+
}
38+
return nil
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//go:build acceptance
2+
// +build acceptance
3+
4+
package provider
5+
6+
import (
7+
"fmt"
8+
"testing"
9+
10+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
11+
)
12+
13+
func TestAccDataSourceGitlabGroupHook_basic(t *testing.T) {
14+
testAccCheckEE(t)
15+
16+
testGroup := testAccCreateGroups(t, 1)[0]
17+
testHook := testAccCreateGroupHooks(t, testGroup.ID, 1)[0]
18+
19+
resource.ParallelTest(t, resource.TestCase{
20+
ProviderFactories: providerFactories,
21+
Steps: []resource.TestStep{
22+
{
23+
Config: fmt.Sprintf(`
24+
data "gitlab_group_hook" "this" {
25+
group = "%s"
26+
hook_id = %d
27+
}
28+
`, testGroup.FullPath, testHook.ID),
29+
Check: resource.ComposeTestCheckFunc(
30+
resource.TestCheckResourceAttr("data.gitlab_group_hook.this", "hook_id", fmt.Sprintf("%d", testHook.ID)),
31+
resource.TestCheckResourceAttr("data.gitlab_group_hook.this", "group_id", fmt.Sprintf("%d", testGroup.ID)),
32+
resource.TestCheckResourceAttr("data.gitlab_group_hook.this", "url", testHook.URL),
33+
),
34+
},
35+
},
36+
})
37+
}

0 commit comments

Comments
 (0)