generated from hashicorp/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 41
/
data_source_pipeline_filters.go
281 lines (267 loc) · 9.15 KB
/
data_source_pipeline_filters.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
package pipeline_filters
import (
"context"
"errors"
"net/http"
"regexp"
"github.com/harness/harness-go-sdk/harness/nextgen"
"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"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)
func DataSourcePipelineFilters() *schema.Resource {
resource := &schema.Resource{
Description: "Data source for retrieving a Harness Pipeline Filter.",
ReadContext: dataSourcePipelineFiltersRead,
Schema: map[string]*schema.Schema{
"identifier": {
Description: "Unique identifier of the resource.",
Type: schema.TypeString,
Required: true,
},
"name": {
Description: "Name of the Filter.",
Type: schema.TypeString,
Computed: true,
},
"type": {
Description: "Type of filter. Currently supported types are {PipelineSetup, PipelineExecution, Deployment, Template, EnvironmentGroup, Environment}.",
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"PipelineSetup", "PipelineExecution", "Deployment", "Template", "EnvironmentGroup", "Environment"}, false),
},
"org_id": {
Description: "Organization Identifier for the Entity.",
Type: schema.TypeString,
Optional: true,
},
"project_id": {
Description: "Project Identifier for the Entity.",
Type: schema.TypeString,
Optional: true,
},
"filter_properties": {
Description: "Properties of the filter entity defined in Harness.",
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"filter_type": {
Description: "Corresponding Entity of the filters. Currently supported types are {Connector, DelegateProfile, Delegate, PipelineSetup, PipelineExecution, Deployment, Audit, Template, EnvironmentGroup, FileStore, CCMRecommendation, Anomaly, Environment}.",
Type: schema.TypeString,
Computed: true,
},
"tags": {
Description: "Tags to associate with the resource. Tags should be in the form `name:value`.",
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"pipeline_tags": {
Description: "Tags to associate with the pipeline. tags should be in the form of `{key:key1, value:key1value}`",
Type: schema.TypeList,
Optional: true,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeMap,
ValidateDiagFunc: validation.MapKeyMatch(regexp.MustCompile("^key$|^value$"), "Please provide valid pipeline tags. valid values: key and value."),
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
"pipeline_identifiers": {
Description: "Pipeline identifiers to filter on.",
Type: schema.TypeList,
Optional: true,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"name": {
Description: "Name of the pipeline filter.",
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"description": {
Description: "description of the pipline filter.",
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"module_properties": {
Description: "module properties of the pipline filter.",
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"ci": {
Type: schema.TypeList,
Optional: true,
Computed: true,
Description: "CI related properties to be filtered on.",
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"build_type": {
Description: "Build type of the pipeline. Possible values: branch.",
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"branch": {
Description: "Branch which was used while building.",
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"tag": {
Description: "Tags to associate with the CI pipeline resource.",
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"repo_names": {
Description: "name of the repository used in the pipeline.",
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"ci_execution_info": {
Description: "CI execution info for the pipeline.",
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"event": {
Description: "Event for the ci execution, Possible values: pullRequest.",
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"pull_request": {
Description: "The pull request details of the CI pipeline.",
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"source_branch": {
Description: "Source branch of the pull request.",
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"target_branch": {
Description: "Target branch of the pull request.",
Type: schema.TypeString,
Optional: true,
Computed: true,
},
},
},
},
},
},
},
},
},
},
"cd": {
Description: "CD related properties to be filtered on.",
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"deployment_types": {
Description: "Deployment type of the CD pipeline, eg. Kubernetes",
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"service_names": {
Description: "Service names of the CD pipeline.",
Type: schema.TypeSet,
Optional: true,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"environment_names": {
Description: "Environment names of the CD pipeline.",
Type: schema.TypeSet,
Optional: true,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"artifact_display_names": {
Description: "Artifact display names of the CD pipeline.",
Type: schema.TypeSet,
Optional: true,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
},
},
},
},
},
},
"filter_visibility": {
Description: "This indicates visibility of filter. By default, everyone can view this filter.",
Type: schema.TypeString,
Computed: true,
},
},
}
return resource
}
func dataSourcePipelineFiltersRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
c, ctx := meta.(*internal.Session).GetPlatformClientWithContext(ctx)
var filter *nextgen.PipelineFilter
var err error
var httpResp *http.Response
id := d.Get("identifier").(string)
type_ := d.Get("type").(string)
if id != "" {
var resp nextgen.ResponseDtoPipelineFilter
resp, httpResp, err = c.FilterApi.PipelinegetFilter(ctx, c.AccountId, id, type_, &nextgen.FilterApiPipelinegetFilterOpts{
OrgIdentifier: helpers.BuildField(d, "org_id"),
ProjectIdentifier: helpers.BuildField(d, "project_id"),
})
filter = resp.Data
} else {
return diag.FromErr(errors.New(" identifier must be specified"))
}
if err != nil {
return helpers.HandleReadApiError(err, d, httpResp)
}
if filter == nil {
d.SetId("")
d.MarkNewResource()
return nil
}
readPipelineFilter(d, filter)
return nil
}