@@ -2,7 +2,6 @@ package gitlab
2
2
3
3
import (
4
4
"context"
5
- "fmt"
6
5
"log"
7
6
8
7
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
@@ -19,7 +18,7 @@ func resourceGitlabServiceSlack() *schema.Resource {
19
18
UpdateContext : resourceGitlabServiceSlackUpdate ,
20
19
DeleteContext : resourceGitlabServiceSlackDelete ,
21
20
Importer : & schema.ResourceImporter {
22
- StateContext : resourceGitlabServiceSlackImportState ,
21
+ StateContext : schema . ImportStatePassthroughContext ,
23
22
},
24
23
25
24
Schema : map [string ]* schema.Schema {
@@ -46,7 +45,7 @@ func resourceGitlabServiceSlack() *schema.Resource {
46
45
Computed : true ,
47
46
},
48
47
"notify_only_default_branch" : {
49
- Description : "DEPRECATED: This parameter has been replaced with `branches_to_be_notified`." ,
48
+ Description : "This parameter has been replaced with `branches_to_be_notified`." ,
50
49
Type : schema .TypeBool ,
51
50
Optional : true ,
52
51
Computed : true ,
@@ -58,58 +57,84 @@ func resourceGitlabServiceSlack() *schema.Resource {
58
57
Optional : true ,
59
58
Computed : true ,
60
59
},
61
- "push_events" : {
62
- Description : "Enable notifications for push events." ,
63
- Type : schema .TypeBool ,
60
+ // TODO: Currently, go-gitlab doesn't implement this option yet.
61
+ // see https://github.com/xanzy/go-gitlab/issues/1354
62
+ // "commit_events": {
63
+ // Description: "Enable notifications for commit events.",
64
+ // Type: schema.TypeBool,
65
+ // Optional: true,
66
+ // Computed: true,
67
+ // },
68
+ "confidential_issue_channel" : {
69
+ Description : "The name of the channel to receive confidential issue events notifications." ,
70
+ Type : schema .TypeString ,
64
71
Optional : true ,
65
- Computed : true ,
66
72
},
67
- "push_channel " : {
68
- Description : "The name of the channel to receive push events notifications ." ,
69
- Type : schema .TypeString ,
73
+ "confidential_issues_events " : {
74
+ Description : "Enable notifications for confidential issues events." ,
75
+ Type : schema .TypeBool ,
70
76
Optional : true ,
77
+ Computed : true ,
71
78
},
72
- "issues_events" : {
73
- Description : "Enable notifications for issues events." ,
79
+ // TODO: Currently, GitLab ignores this option (not implemented yet?), so
80
+ // there is no way to set it. Uncomment when this is fixed.
81
+ // See: https://gitlab.com/gitlab-org/gitlab-ce/issues/49730
82
+ // "confidential_note_channel": {
83
+ // Description: "The name of the channel to receive confidential note events notifications.",
84
+ // Type: schema.TypeString,
85
+ // Optional: true,
86
+ // },
87
+ "confidential_note_events" : {
88
+ Description : "Enable notifications for confidential note events." ,
74
89
Type : schema .TypeBool ,
75
90
Optional : true ,
76
91
Computed : true ,
77
92
},
93
+ // TODO: Currently, GitLab doesn't correctly implement the API, so this is
94
+ // impossible to implement here at the moment.
95
+ // see https://gitlab.com/gitlab-org/gitlab/-/issues/28903
96
+ // "deployment_channel": {
97
+ // Description: "The name of the channel to receive deployment events notifications.",
98
+ // Type: schema.TypeString,
99
+ // Optional: true,
100
+ // },
101
+ // "deployment_events": {
102
+ // Description: "Enable notifications for deployment events.",
103
+ // Type: schema.TypeBool,
104
+ // Optional: true,
105
+ // Computed: true,
106
+ // },
78
107
"issue_channel" : {
79
108
Description : "The name of the channel to receive issue events notifications." ,
80
109
Type : schema .TypeString ,
81
110
Optional : true ,
82
111
},
83
- "confidential_issues_events " : {
84
- Description : "Enable notifications for confidential issues events." ,
112
+ "issues_events " : {
113
+ Description : "Enable notifications for issues events." ,
85
114
Type : schema .TypeBool ,
86
115
Optional : true ,
87
116
Computed : true ,
88
117
},
89
- "confidential_issue_channel" : {
90
- Description : "The name of the channel to receive confidential issue events notifications." ,
91
- Type : schema .TypeString ,
92
- Optional : true ,
93
- },
94
- "merge_requests_events" : {
95
- Description : "Enable notifications for merge requests events." ,
118
+ // TODO: Currently, go-gitlab doesn't implement this option yet.
119
+ // see https://github.com/xanzy/go-gitlab/issues/1354
120
+ "job_events" : {
121
+ Description : "Enable notifications for job events. **ATTENTION**: This attribute is currently not being submitted to the GitLab API, due to https://github.com/xanzy/go-gitlab/issues/1354." ,
96
122
Type : schema .TypeBool ,
97
- Optional : true ,
98
123
Computed : true ,
99
124
},
100
125
"merge_request_channel" : {
101
126
Description : "The name of the channel to receive merge request events notifications." ,
102
127
Type : schema .TypeString ,
103
128
Optional : true ,
104
129
},
105
- "tag_push_events " : {
106
- Description : "Enable notifications for tag push events." ,
130
+ "merge_requests_events " : {
131
+ Description : "Enable notifications for merge requests events." ,
107
132
Type : schema .TypeBool ,
108
133
Optional : true ,
109
134
Computed : true ,
110
135
},
111
- "tag_push_channel " : {
112
- Description : "The name of the channel to receive tag push events notifications." ,
136
+ "note_channel " : {
137
+ Description : "The name of the channel to receive note events notifications." ,
113
138
Type : schema .TypeString ,
114
139
Optional : true ,
115
140
},
@@ -119,38 +144,35 @@ func resourceGitlabServiceSlack() *schema.Resource {
119
144
Optional : true ,
120
145
Computed : true ,
121
146
},
122
- "note_channel " : {
123
- Description : "The name of the channel to receive note events notifications." ,
147
+ "pipeline_channel " : {
148
+ Description : "The name of the channel to receive pipeline events notifications." ,
124
149
Type : schema .TypeString ,
125
150
Optional : true ,
126
151
},
127
- "confidential_note_events " : {
128
- Description : "Enable notifications for confidential note events." ,
152
+ "pipeline_events " : {
153
+ Description : "Enable notifications for pipeline events." ,
129
154
Type : schema .TypeBool ,
130
155
Optional : true ,
131
156
Computed : true ,
132
157
},
133
- // TODO: Currently, GitLab ignores this option (not implemented yet?), so
134
- // there is no way to set it. Uncomment when this is fixed.
135
- // See: https://gitlab.com/gitlab-org/gitlab-ce/issues/49730
136
- //"confidential_note_channel": {
137
- // Type: schema.TypeString,
138
- // Optional: true,
139
- // Computed: true,
140
- //},
141
- "pipeline_events" : {
142
- Description : "Enable notifications for pipeline events." ,
158
+ "push_channel" : {
159
+ Description : "The name of the channel to receive push events notifications." ,
160
+ Type : schema .TypeString ,
161
+ Optional : true ,
162
+ },
163
+ "push_events" : {
164
+ Description : "Enable notifications for push events." ,
143
165
Type : schema .TypeBool ,
144
166
Optional : true ,
145
167
Computed : true ,
146
168
},
147
- "pipeline_channel " : {
148
- Description : "The name of the channel to receive pipeline events notifications." ,
169
+ "tag_push_channel " : {
170
+ Description : "The name of the channel to receive tag push events notifications." ,
149
171
Type : schema .TypeString ,
150
172
Optional : true ,
151
173
},
152
- "wiki_page_events " : {
153
- Description : "Enable notifications for wiki page events." ,
174
+ "tag_push_events " : {
175
+ Description : "Enable notifications for tag push events." ,
154
176
Type : schema .TypeBool ,
155
177
Optional : true ,
156
178
Computed : true ,
@@ -160,49 +182,20 @@ func resourceGitlabServiceSlack() *schema.Resource {
160
182
Type : schema .TypeString ,
161
183
Optional : true ,
162
184
},
163
- "job_events " : {
164
- Description : "Enable notifications for job events." ,
185
+ "wiki_page_events " : {
186
+ Description : "Enable notifications for wiki page events." ,
165
187
Type : schema .TypeBool ,
188
+ Optional : true ,
166
189
Computed : true ,
167
190
},
168
191
},
169
192
}
170
193
}
171
194
172
- func resourceGitlabServiceSlackSetToState (d * schema.ResourceData , service * gitlab.SlackService ) error {
173
- d .SetId (fmt .Sprintf ("%d" , service .ID ))
174
- d .Set ("webhook" , service .Properties .WebHook )
175
- d .Set ("username" , service .Properties .Username )
176
- d .Set ("notify_only_broken_pipelines" , bool (service .Properties .NotifyOnlyBrokenPipelines ))
177
- d .Set ("notify_only_default_branch" , bool (service .Properties .NotifyOnlyDefaultBranch ))
178
- d .Set ("branches_to_be_notified" , service .Properties .BranchesToBeNotified )
179
- d .Set ("push_events" , service .PushEvents )
180
- d .Set ("push_channel" , service .Properties .PushChannel )
181
- d .Set ("issues_events" , service .IssuesEvents )
182
- d .Set ("issue_channel" , service .Properties .IssueChannel )
183
- d .Set ("confidential_issues_events" , service .ConfidentialIssuesEvents )
184
- d .Set ("confidential_issue_channel" , service .Properties .ConfidentialIssueChannel )
185
- d .Set ("merge_requests_events" , service .MergeRequestsEvents )
186
- d .Set ("merge_request_channel" , service .Properties .MergeRequestChannel )
187
- d .Set ("tag_push_events" , service .TagPushEvents )
188
- d .Set ("tag_push_channel" , service .Properties .TagPushChannel )
189
- d .Set ("note_events" , service .NoteEvents )
190
- d .Set ("note_channel" , service .Properties .NoteChannel )
191
- d .Set ("confidential_note_events" , service .ConfidentialNoteEvents )
192
- // See comment to "confidential_note_channel" in resourceGitlabServiceSlack()
193
- //d.Set("confidential_note_channel", service.Properties.ConfidentialNoteChannel)
194
- d .Set ("pipeline_events" , service .PipelineEvents )
195
- d .Set ("pipeline_channel" , service .Properties .PipelineChannel )
196
- d .Set ("wiki_page_events" , service .WikiPageEvents )
197
- d .Set ("wiki_page_channel" , service .Properties .WikiPageChannel )
198
- d .Set ("job_events" , service .JobEvents )
199
-
200
- return nil
201
- }
202
-
203
195
func resourceGitlabServiceSlackCreate (ctx context.Context , d * schema.ResourceData , meta interface {}) diag.Diagnostics {
204
196
client := meta .(* gitlab.Client )
205
197
project := d .Get ("project" ).(string )
198
+ d .SetId (project )
206
199
207
200
log .Printf ("[DEBUG] create gitlab slack service for project %s" , project )
208
201
@@ -214,23 +207,38 @@ func resourceGitlabServiceSlackCreate(ctx context.Context, d *schema.ResourceDat
214
207
opts .NotifyOnlyBrokenPipelines = gitlab .Bool (d .Get ("notify_only_broken_pipelines" ).(bool ))
215
208
opts .NotifyOnlyDefaultBranch = gitlab .Bool (d .Get ("notify_only_default_branch" ).(bool ))
216
209
opts .BranchesToBeNotified = gitlab .String (d .Get ("branches_to_be_notified" ).(string ))
217
- opts .PushEvents = gitlab .Bool (d .Get ("push_events" ).(bool ))
218
- opts .PushChannel = gitlab .String (d .Get ("push_channel" ).(string ))
219
- opts .IssuesEvents = gitlab .Bool (d .Get ("issues_events" ).(bool ))
220
- opts .IssueChannel = gitlab .String (d .Get ("issue_channel" ).(string ))
221
- opts .ConfidentialIssuesEvents = gitlab .Bool (d .Get ("confidential_issues_events" ).(bool ))
210
+ // TODO: Currently, go-gitlab doesn't implement this option yet.
211
+ // see https://github.com/xanzy/go-gitlab/issues/1354
212
+ // opts.CommitEvents = gitlab.Bool(d.Get("commit_events").(bool))
222
213
opts .ConfidentialIssueChannel = gitlab .String (d .Get ("confidential_issue_channel" ).(string ))
223
- opts .MergeRequestsEvents = gitlab .Bool (d .Get ("merge_requests_events" ).(bool ))
214
+ opts .ConfidentialIssuesEvents = gitlab .Bool (d .Get ("confidential_issues_events" ).(bool ))
215
+ // TODO: Currently, GitLab ignores this option (not implemented yet?), so
216
+ // there is no way to set it. Uncomment when this is fixed.
217
+ // See: https://gitlab.com/gitlab-org/gitlab-ce/issues/49730
218
+ // opts.ConfidentialNoteChannel = gitlab.String(d.Get("confidential_note_channel").(string))
219
+ opts .ConfidentialNoteEvents = gitlab .Bool (d .Get ("confidential_note_events" ).(bool ))
220
+ // TODO: Currently, GitLab doesn't correctly implement the API, so this is
221
+ // impossible to implement here at the moment.
222
+ // see https://gitlab.com/gitlab-org/gitlab/-/issues/28903
223
+ // opts.DeploymentChannel = gitlab.String(d.Get("deployment_channel").(string))
224
+ // opts.DeploymentEvents = gitlab.Bool(d.Get("deployment_events").(bool))
225
+ opts .IssueChannel = gitlab .String (d .Get ("issue_channel" ).(string ))
226
+ opts .IssuesEvents = gitlab .Bool (d .Get ("issues_events" ).(bool ))
227
+ // TODO: Currently, go-gitlab doesn't implement this option yet.
228
+ // see https://github.com/xanzy/go-gitlab/issues/1354
229
+ // opts.JobEvents = gitlab.Bool(d.Get("job_events").(bool))
224
230
opts .MergeRequestChannel = gitlab .String (d .Get ("merge_request_channel" ).(string ))
225
- opts .TagPushEvents = gitlab .Bool (d .Get ("tag_push_events" ).(bool ))
226
- opts .TagPushChannel = gitlab .String (d .Get ("tag_push_channel" ).(string ))
227
- opts .NoteEvents = gitlab .Bool (d .Get ("note_events" ).(bool ))
231
+ opts .MergeRequestsEvents = gitlab .Bool (d .Get ("merge_requests_events" ).(bool ))
228
232
opts .NoteChannel = gitlab .String (d .Get ("note_channel" ).(string ))
229
- opts .ConfidentialNoteEvents = gitlab .Bool (d .Get ("confidential_note_events" ).(bool ))
230
- opts .PipelineEvents = gitlab .Bool (d .Get ("pipeline_events" ).(bool ))
233
+ opts .NoteEvents = gitlab .Bool (d .Get ("note_events" ).(bool ))
231
234
opts .PipelineChannel = gitlab .String (d .Get ("pipeline_channel" ).(string ))
232
- opts .WikiPageEvents = gitlab .Bool (d .Get ("wiki_page_events" ).(bool ))
235
+ opts .PipelineEvents = gitlab .Bool (d .Get ("pipeline_events" ).(bool ))
236
+ opts .PushChannel = gitlab .String (d .Get ("push_channel" ).(string ))
237
+ opts .PushEvents = gitlab .Bool (d .Get ("push_events" ).(bool ))
238
+ opts .TagPushChannel = gitlab .String (d .Get ("tag_push_channel" ).(string ))
239
+ opts .TagPushEvents = gitlab .Bool (d .Get ("tag_push_events" ).(bool ))
233
240
opts .WikiPageChannel = gitlab .String (d .Get ("wiki_page_channel" ).(string ))
241
+ opts .WikiPageEvents = gitlab .Bool (d .Get ("wiki_page_events" ).(bool ))
234
242
235
243
_ , err := client .Services .SetSlackService (project , opts , gitlab .WithContext (ctx ))
236
244
if err != nil {
@@ -242,7 +250,7 @@ func resourceGitlabServiceSlackCreate(ctx context.Context, d *schema.ResourceDat
242
250
243
251
func resourceGitlabServiceSlackRead (ctx context.Context , d * schema.ResourceData , meta interface {}) diag.Diagnostics {
244
252
client := meta .(* gitlab.Client )
245
- project := d .Get ( "project" ).( string )
253
+ project := d .Id ( )
246
254
247
255
log .Printf ("[DEBUG] read gitlab slack service for project %s" , project )
248
256
@@ -256,9 +264,41 @@ func resourceGitlabServiceSlackRead(ctx context.Context, d *schema.ResourceData,
256
264
return diag .FromErr (err )
257
265
}
258
266
259
- if err = resourceGitlabServiceSlackSetToState (d , service ); err != nil {
260
- return diag .FromErr (err )
261
- }
267
+ d .Set ("project" , project )
268
+ d .Set ("webhook" , service .Properties .WebHook )
269
+ d .Set ("username" , service .Properties .Username )
270
+ d .Set ("notify_only_broken_pipelines" , bool (service .Properties .NotifyOnlyBrokenPipelines ))
271
+ d .Set ("notify_only_default_branch" , bool (service .Properties .NotifyOnlyDefaultBranch ))
272
+ d .Set ("branches_to_be_notified" , service .Properties .BranchesToBeNotified )
273
+ d .Set ("confidential_issue_channel" , service .Properties .ConfidentialIssueChannel )
274
+ d .Set ("confidential_issues_events" , service .ConfidentialIssuesEvents )
275
+ // TODO: Currently, GitLab ignores this option (not implemented yet?), so
276
+ // there is no way to set it. Uncomment when this is fixed.
277
+ // See: https://gitlab.com/gitlab-org/gitlab-ce/issues/49730
278
+ // d.Set("confidential_note_channel", service.Properties.ConfidentialNoteChannel)
279
+ d .Set ("confidential_note_events" , service .ConfidentialNoteEvents )
280
+ // TODO: Currently, GitLab doesn't correctly implement the API, so this is
281
+ // impossible to implement here at the moment.
282
+ // see https://gitlab.com/gitlab-org/gitlab/-/issues/28903
283
+ // d.Set("deployment_channel", service.Properties.DeploymentChannel)
284
+ // d.Set("deployment_events", service.DeploymentEvents)
285
+ d .Set ("issue_channel" , service .Properties .IssueChannel )
286
+ d .Set ("issues_events" , service .IssuesEvents )
287
+ // TODO: Currently, go-gitlab doesn't implement this option yet.
288
+ // see https://github.com/xanzy/go-gitlab/issues/1354
289
+ d .Set ("job_events" , service .JobEvents )
290
+ d .Set ("merge_request_channel" , service .Properties .MergeRequestChannel )
291
+ d .Set ("merge_requests_events" , service .MergeRequestsEvents )
292
+ d .Set ("note_channel" , service .Properties .NoteChannel )
293
+ d .Set ("note_events" , service .NoteEvents )
294
+ d .Set ("pipeline_channel" , service .Properties .PipelineChannel )
295
+ d .Set ("pipeline_events" , service .PipelineEvents )
296
+ d .Set ("push_channel" , service .Properties .PushChannel )
297
+ d .Set ("push_events" , service .PushEvents )
298
+ d .Set ("tag_push_channel" , service .Properties .TagPushChannel )
299
+ d .Set ("tag_push_events" , service .TagPushEvents )
300
+ d .Set ("wiki_page_channel" , service .Properties .WikiPageChannel )
301
+ d .Set ("wiki_page_events" , service .WikiPageEvents )
262
302
263
303
return nil
264
304
}
@@ -269,7 +309,7 @@ func resourceGitlabServiceSlackUpdate(ctx context.Context, d *schema.ResourceDat
269
309
270
310
func resourceGitlabServiceSlackDelete (ctx context.Context , d * schema.ResourceData , meta interface {}) diag.Diagnostics {
271
311
client := meta .(* gitlab.Client )
272
- project := d .Get ( "project" ).( string )
312
+ project := d .Id ( )
273
313
274
314
log .Printf ("[DEBUG] delete gitlab slack service for project %s" , project )
275
315
@@ -280,9 +320,3 @@ func resourceGitlabServiceSlackDelete(ctx context.Context, d *schema.ResourceDat
280
320
281
321
return nil
282
322
}
283
-
284
- func resourceGitlabServiceSlackImportState (ctx context.Context , d * schema.ResourceData , meta interface {}) ([]* schema.ResourceData , error ) {
285
- d .Set ("project" , d .Id ())
286
-
287
- return []* schema.ResourceData {d }, nil
288
- }
0 commit comments