1
1
package provider
2
2
3
3
import (
4
+ "context"
4
5
"fmt"
5
6
"log"
6
7
"strconv"
7
8
"strings"
8
9
10
+ "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
9
11
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
10
12
gitlab "github.com/xanzy/go-gitlab"
11
13
)
@@ -26,26 +28,26 @@ func CreateCustomAttributeResource(idName string, createGetter CreateGetter, cre
26
28
d .Set ("value" , customAttribute .Value )
27
29
}
28
30
29
- readFunc := func (d * schema.ResourceData , meta interface {}) error {
31
+ readFunc := func (ctx context. Context , d * schema.ResourceData , meta interface {}) diag. Diagnostics {
30
32
client := meta .(* gitlab.Client )
31
33
getter := createGetter (client )
32
34
log .Printf ("[DEBUG] read Custom Attribute %s" , d .Id ())
33
35
34
36
id , key , err := parseId (d .Id ())
35
37
if err != nil {
36
- return err
38
+ return diag . FromErr ( err )
37
39
}
38
40
39
41
customAttribute , _ , err := getter (id , key )
40
42
if err != nil {
41
- return err
43
+ return diag . FromErr ( err )
42
44
}
43
45
44
46
setToState (d , id , customAttribute )
45
47
return nil
46
48
}
47
49
48
- setFunc := func (d * schema.ResourceData , meta interface {}) error {
50
+ setFunc := func (ctx context. Context , d * schema.ResourceData , meta interface {}) diag. Diagnostics {
49
51
client := meta .(* gitlab.Client )
50
52
setter := createSetter (client )
51
53
@@ -57,39 +59,39 @@ func CreateCustomAttributeResource(idName string, createGetter CreateGetter, cre
57
59
58
60
log .Printf ("[DEBUG] set (create or update) Custom Attribute %s with value %s for %s %d" , options .Key , options .Value , idName , id )
59
61
60
- customAttribute , _ , err := setter (id , * options )
62
+ customAttribute , _ , err := setter (id , * options , gitlab . WithContext ( ctx ) )
61
63
if err != nil {
62
- return err
64
+ return diag . FromErr ( err )
63
65
}
64
66
65
67
d .SetId (buildId (id , customAttribute .Key ))
66
- return readFunc (d , meta )
68
+ return readFunc (ctx , d , meta )
67
69
}
68
70
69
- deleteFunc := func (d * schema.ResourceData , meta interface {}) error {
71
+ deleteFunc := func (ctx context. Context , d * schema.ResourceData , meta interface {}) diag. Diagnostics {
70
72
client := meta .(* gitlab.Client )
71
73
deleter := createDeleter (client )
72
74
log .Printf ("[DEBUG] delete Custom Attribute %s" , d .Id ())
73
75
74
76
id , key , err := parseId (d .Id ())
75
77
if err != nil {
76
- return err
78
+ return diag . FromErr ( err )
77
79
}
78
80
79
- _ , err = deleter (id , key )
81
+ _ , err = deleter (id , key , gitlab . WithContext ( ctx ) )
80
82
if err != nil {
81
- return err
83
+ return diag . FromErr ( err )
82
84
}
83
85
84
86
return nil
85
87
}
86
88
87
89
return & schema.Resource {
88
- Description : description ,
89
- Create : setFunc ,
90
- Read : readFunc ,
91
- Update : setFunc ,
92
- Delete : deleteFunc ,
90
+ Description : description ,
91
+ CreateContext : setFunc ,
92
+ ReadContext : readFunc ,
93
+ UpdateContext : setFunc ,
94
+ DeleteContext : deleteFunc ,
93
95
Importer : & schema.ResourceImporter {
94
96
StateContext : schema .ImportStatePassthroughContext ,
95
97
},
0 commit comments