@@ -13,6 +13,9 @@ func resourceGitlabProjectVariable() *schema.Resource {
13
13
Read : resourceGitlabProjectVariableRead ,
14
14
Update : resourceGitlabProjectVariableUpdate ,
15
15
Delete : resourceGitlabProjectVariableDelete ,
16
+ Importer : & schema.ResourceImporter {
17
+ State : schema .ImportStatePassthrough ,
18
+ },
16
19
17
20
Schema : map [string ]* schema.Schema {
18
21
"project" : {
@@ -49,27 +52,37 @@ func resourceGitlabProjectVariableCreate(d *schema.ResourceData, meta interface{
49
52
}
50
53
log .Printf ("[DEBUG] create gitlab project variable %s/%s" , project , key )
51
54
52
- _ , _ , err := client .BuildVariables .CreateBuildVariable (project , options )
55
+ v , _ , err := client .BuildVariables .CreateBuildVariable (project , options )
53
56
if err != nil {
54
57
return err
55
58
}
56
59
60
+ d .SetId (buildTwoPartID (& project , & v .Key ))
61
+
57
62
return resourceGitlabProjectVariableRead (d , meta )
58
63
}
59
64
60
65
func resourceGitlabProjectVariableRead (d * schema.ResourceData , meta interface {}) error {
61
66
client := meta .(* gitlab.Client )
62
- project := d .Get ("project" ).(string )
63
- key := d .Get ("key" ).(string )
67
+
68
+ project , key , err := parseTwoPartID (d .Id ())
69
+ if err != nil {
70
+ return err
71
+ }
72
+
64
73
log .Printf ("[DEBUG] read gitlab project variable %s/%s" , project , key )
65
74
66
75
v , _ , err := client .BuildVariables .GetBuildVariable (project , key )
67
76
if err != nil {
68
77
return err
69
78
}
70
79
80
+ d .Set ("key" , v .Key )
71
81
d .Set ("value" , v .Value )
82
+ d .Set ("project" , project )
72
83
d .Set ("protected" , v .Protected )
84
+ d .SetId (buildTwoPartID (& project , & v .Key ))
85
+
73
86
return nil
74
87
}
75
88
@@ -84,11 +97,13 @@ func resourceGitlabProjectVariableUpdate(d *schema.ResourceData, meta interface{
84
97
}
85
98
log .Printf ("[DEBUG] update gitlab project variable %s/%s" , project , key )
86
99
87
- _ , _ , err := client .BuildVariables .UpdateBuildVariable (project , key , options )
100
+ v , _ , err := client .BuildVariables .UpdateBuildVariable (project , key , options )
88
101
if err != nil {
89
102
return err
90
103
}
91
104
105
+ d .SetId (buildTwoPartID (& project , & v .Key ))
106
+
92
107
return resourceGitlabProjectVariableRead (d , meta )
93
108
}
94
109
0 commit comments