@@ -25,8 +25,9 @@ func TestAccGitlabGroupVariable_basic(t *testing.T) {
25
25
Check : resource .ComposeTestCheckFunc (
26
26
testAccCheckGitlabGroupVariableExists ("gitlab_group_variable.foo" , & groupVariable ),
27
27
testAccCheckGitlabGroupVariableAttributes (& groupVariable , & testAccGitlabGroupVariableExpectedAttributes {
28
- Key : fmt .Sprintf ("key_%s" , rString ),
29
- Value : fmt .Sprintf ("value-%s" , rString ),
28
+ Key : fmt .Sprintf ("key_%s" , rString ),
29
+ Value : fmt .Sprintf ("value-%s" , rString ),
30
+ EnvironmentScope : "*" ,
30
31
}),
31
32
),
32
33
},
@@ -36,9 +37,10 @@ func TestAccGitlabGroupVariable_basic(t *testing.T) {
36
37
Check : resource .ComposeTestCheckFunc (
37
38
testAccCheckGitlabGroupVariableExists ("gitlab_group_variable.foo" , & groupVariable ),
38
39
testAccCheckGitlabGroupVariableAttributes (& groupVariable , & testAccGitlabGroupVariableExpectedAttributes {
39
- Key : fmt .Sprintf ("key_%s" , rString ),
40
- Value : fmt .Sprintf ("value-inverse-%s" , rString ),
41
- Protected : true ,
40
+ Key : fmt .Sprintf ("key_%s" , rString ),
41
+ Value : fmt .Sprintf ("value-inverse-%s" , rString ),
42
+ Protected : true ,
43
+ EnvironmentScope : "*" ,
42
44
}),
43
45
),
44
46
},
@@ -48,9 +50,80 @@ func TestAccGitlabGroupVariable_basic(t *testing.T) {
48
50
Check : resource .ComposeTestCheckFunc (
49
51
testAccCheckGitlabGroupVariableExists ("gitlab_group_variable.foo" , & groupVariable ),
50
52
testAccCheckGitlabGroupVariableAttributes (& groupVariable , & testAccGitlabGroupVariableExpectedAttributes {
51
- Key : fmt .Sprintf ("key_%s" , rString ),
52
- Value : fmt .Sprintf ("value-%s" , rString ),
53
- Protected : false ,
53
+ Key : fmt .Sprintf ("key_%s" , rString ),
54
+ Value : fmt .Sprintf ("value-%s" , rString ),
55
+ Protected : false ,
56
+ EnvironmentScope : "*" ,
57
+ }),
58
+ ),
59
+ },
60
+ },
61
+ })
62
+ }
63
+
64
+ func TestAccGitlabGroupVariable_scope (t * testing.T ) {
65
+ var groupVariableA , groupVariableB gitlab.GroupVariable
66
+ rString := acctest .RandString (5 )
67
+
68
+ resource .Test (t , resource.TestCase {
69
+ PreCheck : func () { testAccPreCheck (t ) },
70
+ Providers : testAccProviders ,
71
+ CheckDestroy : testAccCheckGitlabGroupVariableDestroy ,
72
+ Steps : []resource.TestStep {
73
+ // Create a group and variables with same keys, different scopes
74
+ {
75
+ Config : testAccGitlabGroupVariableScopeConfig (rString , "*" , "review/*" ),
76
+ SkipFunc : isRunningInCE ,
77
+ Check : resource .ComposeTestCheckFunc (
78
+ testAccCheckGitlabGroupVariableExists ("gitlab_group_variable.a" , & groupVariableA ),
79
+ testAccCheckGitlabGroupVariableExists ("gitlab_group_variable.b" , & groupVariableB ),
80
+ testAccCheckGitlabGroupVariableAttributes (& groupVariableA , & testAccGitlabGroupVariableExpectedAttributes {
81
+ Key : fmt .Sprintf ("key_%s" , rString ),
82
+ Value : fmt .Sprintf ("value-%s-a" , rString ),
83
+ EnvironmentScope : "*" ,
84
+ }),
85
+ testAccCheckGitlabGroupVariableAttributes (& groupVariableB , & testAccGitlabGroupVariableExpectedAttributes {
86
+ Key : fmt .Sprintf ("key_%s" , rString ),
87
+ Value : fmt .Sprintf ("value-%s-b" , rString ),
88
+ EnvironmentScope : "review/*" ,
89
+ }),
90
+ ),
91
+ },
92
+ // Change a variable's scope
93
+ {
94
+ Config : testAccGitlabGroupVariableScopeConfig (rString , "my-new-scope" , "review/*" ),
95
+ SkipFunc : isRunningInCE ,
96
+ Check : resource .ComposeTestCheckFunc (
97
+ testAccCheckGitlabGroupVariableExists ("gitlab_group_variable.a" , & groupVariableA ),
98
+ testAccCheckGitlabGroupVariableExists ("gitlab_group_variable.b" , & groupVariableB ),
99
+ testAccCheckGitlabGroupVariableAttributes (& groupVariableA , & testAccGitlabGroupVariableExpectedAttributes {
100
+ Key : fmt .Sprintf ("key_%s" , rString ),
101
+ Value : fmt .Sprintf ("value-%s-a" , rString ),
102
+ EnvironmentScope : "my-new-scope" ,
103
+ }),
104
+ testAccCheckGitlabGroupVariableAttributes (& groupVariableB , & testAccGitlabGroupVariableExpectedAttributes {
105
+ Key : fmt .Sprintf ("key_%s" , rString ),
106
+ Value : fmt .Sprintf ("value-%s-b" , rString ),
107
+ EnvironmentScope : "review/*" ,
108
+ }),
109
+ ),
110
+ },
111
+ // Change both variables scopes at the same time
112
+ {
113
+ Config : testAccGitlabGroupVariableScopeConfig (rString , "my-new-new-scope" , "review/hello-world" ),
114
+ SkipFunc : isRunningInCE ,
115
+ Check : resource .ComposeTestCheckFunc (
116
+ testAccCheckGitlabGroupVariableExists ("gitlab_group_variable.a" , & groupVariableA ),
117
+ testAccCheckGitlabGroupVariableExists ("gitlab_group_variable.b" , & groupVariableB ),
118
+ testAccCheckGitlabGroupVariableAttributes (& groupVariableA , & testAccGitlabGroupVariableExpectedAttributes {
119
+ Key : fmt .Sprintf ("key_%s" , rString ),
120
+ Value : fmt .Sprintf ("value-%s-a" , rString ),
121
+ EnvironmentScope : "my-new-new-scope" ,
122
+ }),
123
+ testAccCheckGitlabGroupVariableAttributes (& groupVariableB , & testAccGitlabGroupVariableExpectedAttributes {
124
+ Key : fmt .Sprintf ("key_%s" , rString ),
125
+ Value : fmt .Sprintf ("value-%s-b" , rString ),
126
+ EnvironmentScope : "review/hello-world" ,
54
127
}),
55
128
),
56
129
},
@@ -85,10 +158,11 @@ func testAccCheckGitlabGroupVariableExists(n string, groupVariable *gitlab.Group
85
158
}
86
159
87
160
type testAccGitlabGroupVariableExpectedAttributes struct {
88
- Key string
89
- Value string
90
- Protected bool
91
- Masked bool
161
+ Key string
162
+ Value string
163
+ Protected bool
164
+ Masked bool
165
+ EnvironmentScope string
92
166
}
93
167
94
168
func testAccCheckGitlabGroupVariableAttributes (variable * gitlab.GroupVariable , want * testAccGitlabGroupVariableExpectedAttributes ) resource.TestCheckFunc {
@@ -109,6 +183,10 @@ func testAccCheckGitlabGroupVariableAttributes(variable *gitlab.GroupVariable, w
109
183
return fmt .Errorf ("got masked %t; want %t" , variable .Masked , want .Masked )
110
184
}
111
185
186
+ if variable .EnvironmentScope != want .EnvironmentScope {
187
+ return fmt .Errorf ("got environment_scope %s; want %s" , variable .EnvironmentScope , want .EnvironmentScope )
188
+ }
189
+
112
190
return nil
113
191
}
114
192
}
@@ -170,3 +248,26 @@ resource "gitlab_group_variable" "foo" {
170
248
}
171
249
` , rString , rString , rString , rString )
172
250
}
251
+
252
+ func testAccGitlabGroupVariableScopeConfig (rString , scopeA , scopeB string ) string {
253
+ return fmt .Sprintf (`
254
+ resource "gitlab_group" "foo" {
255
+ name = "foo%v"
256
+ path = "foo%v"
257
+ }
258
+
259
+ resource "gitlab_group_variable" "a" {
260
+ group = "${gitlab_group.foo.id}"
261
+ key = "key_%s"
262
+ value = "value-%s-a"
263
+ environment_scope = "%s"
264
+ }
265
+
266
+ resource "gitlab_group_variable" "b" {
267
+ group = "${gitlab_group.foo.id}"
268
+ key = "key_%s"
269
+ value = "value-%s-b"
270
+ environment_scope = "%s"
271
+ }
272
+ ` , rString , rString , rString , rString , scopeA , rString , rString , scopeB )
273
+ }
0 commit comments