1
1
package gitlab
2
2
3
3
import (
4
+ "context"
4
5
"log"
5
6
"strings"
6
7
8
+ "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
7
9
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
8
10
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
9
11
gitlab "github.com/xanzy/go-gitlab"
10
12
)
11
13
12
14
func resourceGitlabServicePipelinesEmail () * schema.Resource {
13
15
return & schema.Resource {
14
- Create : resourceGitlabServicePipelinesEmailCreate ,
15
- Read : resourceGitlabServicePipelinesEmailRead ,
16
- Update : resourceGitlabServicePipelinesEmailCreate ,
17
- Delete : resourceGitlabServicePipelinesEmailDelete ,
16
+ CreateContext : resourceGitlabServicePipelinesEmailCreate ,
17
+ ReadContext : resourceGitlabServicePipelinesEmailRead ,
18
+ UpdateContext : resourceGitlabServicePipelinesEmailCreate ,
19
+ DeleteContext : resourceGitlabServicePipelinesEmailDelete ,
18
20
Importer : & schema.ResourceImporter {
19
21
StateContext : schema .ImportStatePassthroughContext ,
20
22
},
@@ -51,7 +53,7 @@ func resourceGitlabServicePipelinesEmailSetToState(d *schema.ResourceData, servi
51
53
d .Set ("branches_to_be_notified" , service .Properties .BranchesToBeNotified )
52
54
}
53
55
54
- func resourceGitlabServicePipelinesEmailCreate (d * schema.ResourceData , meta interface {}) error {
56
+ func resourceGitlabServicePipelinesEmailCreate (ctx context. Context , d * schema.ResourceData , meta interface {}) diag. Diagnostics {
55
57
client := meta .(* gitlab.Client )
56
58
project := d .Get ("project" ).(string )
57
59
d .SetId (project )
@@ -63,41 +65,45 @@ func resourceGitlabServicePipelinesEmailCreate(d *schema.ResourceData, meta inte
63
65
64
66
log .Printf ("[DEBUG] create gitlab pipelines emails service for project %s" , project )
65
67
66
- _ , err := client .Services .SetPipelinesEmailService (project , options )
68
+ _ , err := client .Services .SetPipelinesEmailService (project , options , gitlab . WithContext ( ctx ) )
67
69
if err != nil {
68
- return err
70
+ return diag . FromErr ( err )
69
71
}
70
72
71
- return resourceGitlabServicePipelinesEmailRead (d , meta )
73
+ return resourceGitlabServicePipelinesEmailRead (ctx , d , meta )
72
74
}
73
75
74
- func resourceGitlabServicePipelinesEmailRead (d * schema.ResourceData , meta interface {}) error {
76
+ func resourceGitlabServicePipelinesEmailRead (ctx context. Context , d * schema.ResourceData , meta interface {}) diag. Diagnostics {
75
77
client := meta .(* gitlab.Client )
76
78
project := d .Id ()
77
79
78
80
log .Printf ("[DEBUG] read gitlab pipelines emails service for project %s" , project )
79
81
80
- service , _ , err := client .Services .GetPipelinesEmailService (project )
82
+ service , _ , err := client .Services .GetPipelinesEmailService (project , gitlab . WithContext ( ctx ) )
81
83
if err != nil {
82
84
if is404 (err ) {
83
85
log .Printf ("[DEBUG] gitlab pipelines emails service not found for project %s" , project )
84
86
d .SetId ("" )
85
87
return nil
86
88
}
87
- return err
89
+ return diag . FromErr ( err )
88
90
}
89
91
90
92
d .Set ("project" , project )
91
93
resourceGitlabServicePipelinesEmailSetToState (d , service )
92
94
return nil
93
95
}
94
96
95
- func resourceGitlabServicePipelinesEmailDelete (d * schema.ResourceData , meta interface {}) error {
97
+ func resourceGitlabServicePipelinesEmailDelete (ctx context. Context , d * schema.ResourceData , meta interface {}) diag. Diagnostics {
96
98
client := meta .(* gitlab.Client )
97
99
project := d .Id ()
98
100
99
101
log .Printf ("[DEBUG] delete gitlab pipelines email service for project %s" , project )
100
102
101
- _ , err := client .Services .DeletePipelinesEmailService (project )
102
- return err
103
+ _ , err := client .Services .DeletePipelinesEmailService (project , gitlab .WithContext (ctx ))
104
+ if err != nil {
105
+ return diag .FromErr (err )
106
+ }
107
+
108
+ return nil
103
109
}
0 commit comments