-
Notifications
You must be signed in to change notification settings - Fork 26
/
data_gitlab_webhook_endpoint.go
49 lines (37 loc) · 1.36 KB
/
data_gitlab_webhook_endpoint.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package spacelift
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/spacelift-io/terraform-provider-spacelift/spacelift/internal"
)
var gitlabWebhookEndpointFields = struct {
WebhookEndpoint string
}{
WebhookEndpoint: "webhook_endpoint",
}
func dataGitlabWebhookEndpoint() *schema.Resource {
return &schema.Resource{
Description: "`spacelift_gitlab_webhook_endpoint` returns details about Gitlab webhook endpoint",
ReadContext: dataGitlabWebhookEndpointRead,
Schema: map[string]*schema.Schema{
gitlabWebhookEndpointFields.WebhookEndpoint: {
Type: schema.TypeString,
Description: "Gitlab webhook endpoint address",
Computed: true,
},
},
}
}
func dataGitlabWebhookEndpointRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var query struct {
GitlabWebhooksEndpoint string `graphql:"gitlabWebhooksEndpoint"`
}
if err := meta.(*internal.Client).Query(ctx, "GitlabWebhookEndpointRead", &query, nil); err != nil {
d.SetId("")
return diag.Errorf("could not query for gitlab webhook endpoint: %v", err)
}
d.SetId("spacelift_gitlab_webhook_endpoint_id") // TF expects id to be set otherwise it will fail
d.Set(gitlabWebhookEndpointFields.WebhookEndpoint, query.GitlabWebhooksEndpoint)
return nil
}