@@ -5,14 +5,14 @@ import (
5
5
"fmt"
6
6
"log"
7
7
"strconv"
8
+ "strings"
8
9
9
10
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
10
11
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
11
12
gitlab "github.com/xanzy/go-gitlab"
12
13
)
13
14
14
15
var _ = registerResource ("gitlab_project_hook" , func () * schema.Resource {
15
- // lintignore: XR002 // TODO: Resolve this tfproviderlint issue
16
16
return & schema.Resource {
17
17
Description : `The ` + "`" + `gitlab_project_hook` + "`" + ` resource allows to manage the lifecycle of a project hook.
18
18
@@ -22,6 +22,9 @@ var _ = registerResource("gitlab_project_hook", func() *schema.Resource {
22
22
ReadContext : resourceGitlabProjectHookRead ,
23
23
UpdateContext : resourceGitlabProjectHookUpdate ,
24
24
DeleteContext : resourceGitlabProjectHookDelete ,
25
+ Importer : & schema.ResourceImporter {
26
+ StateContext : resourceGitlabProjectHookStateImporter ,
27
+ },
25
28
26
29
Schema : map [string ]* schema.Schema {
27
30
"project" : {
@@ -35,7 +38,7 @@ var _ = registerResource("gitlab_project_hook", func() *schema.Resource {
35
38
Required : true ,
36
39
},
37
40
"token" : {
38
- Description : "A token to present when invoking the hook." ,
41
+ Description : "A token to present when invoking the hook. The token is not available for imported resources. " ,
39
42
Type : schema .TypeString ,
40
43
Optional : true ,
41
44
Sensitive : true ,
@@ -160,6 +163,7 @@ func resourceGitlabProjectHookCreate(ctx context.Context, d *schema.ResourceData
160
163
}
161
164
162
165
d .SetId (fmt .Sprintf ("%d" , hook .ID ))
166
+ d .Set ("token" , options .Token )
163
167
164
168
return resourceGitlabProjectHookRead (ctx , d , meta )
165
169
}
@@ -256,3 +260,17 @@ func resourceGitlabProjectHookDelete(ctx context.Context, d *schema.ResourceData
256
260
257
261
return nil
258
262
}
263
+
264
+ func resourceGitlabProjectHookStateImporter (ctx context.Context , d * schema.ResourceData , meta interface {}) ([]* schema.ResourceData , error ) {
265
+ s := strings .Split (d .Id (), ":" )
266
+ if len (s ) != 2 {
267
+ d .SetId ("" )
268
+ return nil , fmt .Errorf ("Invalid Project Hook import format; expected '{project_id}:{hook_id}'" )
269
+ }
270
+ project , id := s [0 ], s [1 ]
271
+
272
+ d .SetId (id )
273
+ d .Set ("project" , project )
274
+
275
+ return []* schema.ResourceData {d }, nil
276
+ }
0 commit comments