generated from hashicorp/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 41
/
data_source_triggers.go
61 lines (50 loc) · 1.53 KB
/
data_source_triggers.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
50
51
52
53
54
55
56
57
58
59
60
61
package triggers
import (
"context"
"github.com/harness/terraform-provider-harness/helpers"
"github.com/harness/terraform-provider-harness/internal"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func DataSourceTriggers() *schema.Resource {
resource := &schema.Resource{
Description: "Data source for retrieving a Harness trigger.",
ReadContext: dataTriggersRead,
Schema: map[string]*schema.Schema{
"identifier": {
Description: "identifier of the trigger.",
Type: schema.TypeString,
Required: true,
},
"target_id": {
Description: "Identifier of the target pipeline",
Type: schema.TypeString,
Required: true,
},
"ignore_error": {
Description: "ignore error default false",
Type: schema.TypeBool,
Optional: true,
},
"yaml": {
Description: "trigger yaml",
Type: schema.TypeString,
Computed: true,
},
},
}
helpers.SetProjectLevelDataSourceSchema(resource.Schema)
return resource
}
func dataTriggersRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
c, ctx := meta.(*internal.Session).GetPlatformClientWithContext(ctx)
id := d.Get("identifier").(string)
resp, httpResp, err := c.TriggersApi.GetTrigger(ctx, c.AccountId,
d.Get("org_id").(string),
d.Get("project_id").(string), d.Get("target_id").(string), id)
if err != nil {
return helpers.HandleApiError(err, d, httpResp)
}
readTriggers(d, resp.Data)
return nil
}