@@ -25,108 +25,7 @@ var _ = registerResource("gitlab_project_hook", func() *schema.Resource {
25
25
Importer : & schema.ResourceImporter {
26
26
StateContext : resourceGitlabProjectHookStateImporter ,
27
27
},
28
-
29
- Schema : map [string ]* schema.Schema {
30
- "project" : {
31
- Description : "The name or id of the project to add the hook to." ,
32
- Type : schema .TypeString ,
33
- Required : true ,
34
- },
35
- "url" : {
36
- Description : "The url of the hook to invoke." ,
37
- Type : schema .TypeString ,
38
- Required : true ,
39
- },
40
- "token" : {
41
- Description : "A token to present when invoking the hook. The token is not available for imported resources." ,
42
- Type : schema .TypeString ,
43
- Optional : true ,
44
- Sensitive : true ,
45
- },
46
- "push_events" : {
47
- Description : "Invoke the hook for push events." ,
48
- Type : schema .TypeBool ,
49
- Optional : true ,
50
- Default : true ,
51
- },
52
- "push_events_branch_filter" : {
53
- Description : "Invoke the hook for push events on matching branches only." ,
54
- Type : schema .TypeString ,
55
- Optional : true ,
56
- },
57
- "issues_events" : {
58
- Description : "Invoke the hook for issues events." ,
59
- Type : schema .TypeBool ,
60
- Optional : true ,
61
- Default : false ,
62
- },
63
- "confidential_issues_events" : {
64
- Description : "Invoke the hook for confidential issues events." ,
65
- Type : schema .TypeBool ,
66
- Optional : true ,
67
- Default : false ,
68
- },
69
- "merge_requests_events" : {
70
- Description : "Invoke the hook for merge requests." ,
71
- Type : schema .TypeBool ,
72
- Optional : true ,
73
- Default : false ,
74
- },
75
- "tag_push_events" : {
76
- Description : "Invoke the hook for tag push events." ,
77
- Type : schema .TypeBool ,
78
- Optional : true ,
79
- Default : false ,
80
- },
81
- "note_events" : {
82
- Description : "Invoke the hook for notes events." ,
83
- Type : schema .TypeBool ,
84
- Optional : true ,
85
- Default : false ,
86
- },
87
- "confidential_note_events" : {
88
- Description : "Invoke the hook for confidential notes events." ,
89
- Type : schema .TypeBool ,
90
- Optional : true ,
91
- Default : false ,
92
- },
93
- "job_events" : {
94
- Description : "Invoke the hook for job events." ,
95
- Type : schema .TypeBool ,
96
- Optional : true ,
97
- Default : false ,
98
- },
99
- "pipeline_events" : {
100
- Description : "Invoke the hook for pipeline events." ,
101
- Type : schema .TypeBool ,
102
- Optional : true ,
103
- Default : false ,
104
- },
105
- "wiki_page_events" : {
106
- Description : "Invoke the hook for wiki page events." ,
107
- Type : schema .TypeBool ,
108
- Optional : true ,
109
- Default : false ,
110
- },
111
- "deployment_events" : {
112
- Description : "Invoke the hook for deployment events." ,
113
- Type : schema .TypeBool ,
114
- Optional : true ,
115
- Default : false ,
116
- },
117
- "releases_events" : {
118
- Description : "Invoke the hook for releases events." ,
119
- Type : schema .TypeBool ,
120
- Optional : true ,
121
- Default : false ,
122
- },
123
- "enable_ssl_verification" : {
124
- Description : "Enable ssl verification when invoking the hook." ,
125
- Type : schema .TypeBool ,
126
- Optional : true ,
127
- Default : true ,
128
- },
129
- },
28
+ Schema : gitlabProjectHookSchema (),
130
29
}
131
30
})
132
31
@@ -180,28 +79,17 @@ func resourceGitlabProjectHookRead(ctx context.Context, d *schema.ResourceData,
180
79
hook , _ , err := client .Projects .GetProjectHook (project , hookId , gitlab .WithContext (ctx ))
181
80
if err != nil {
182
81
if is404 (err ) {
183
- log .Printf ("[DEBUG] gitlab project hook not found %s/%d" , project , hookId )
82
+ log .Printf ("[DEBUG] gitlab project hook not found %s/%d, removing from state " , project , hookId )
184
83
d .SetId ("" )
185
84
return nil
186
85
}
187
86
return diag .FromErr (err )
188
87
}
189
88
190
- d .Set ("url" , hook .URL )
191
- d .Set ("push_events" , hook .PushEvents )
192
- d .Set ("push_events_branch_filter" , hook .PushEventsBranchFilter )
193
- d .Set ("issues_events" , hook .IssuesEvents )
194
- d .Set ("confidential_issues_events" , hook .ConfidentialIssuesEvents )
195
- d .Set ("merge_requests_events" , hook .MergeRequestsEvents )
196
- d .Set ("tag_push_events" , hook .TagPushEvents )
197
- d .Set ("note_events" , hook .NoteEvents )
198
- d .Set ("confidential_note_events" , hook .ConfidentialNoteEvents )
199
- d .Set ("job_events" , hook .JobEvents )
200
- d .Set ("pipeline_events" , hook .PipelineEvents )
201
- d .Set ("wiki_page_events" , hook .WikiPageEvents )
202
- d .Set ("deployment_events" , hook .DeploymentEvents )
203
- d .Set ("releases_events" , hook .ReleasesEvents )
204
- d .Set ("enable_ssl_verification" , hook .EnableSSLVerification )
89
+ stateMap := gitlabProjectHookToStateMap (project , hook )
90
+ if err = setStateMapInResourceData (stateMap , d ); err != nil {
91
+ return diag .FromErr (err )
92
+ }
205
93
return nil
206
94
}
207
95
0 commit comments