@@ -3,6 +3,7 @@ package provider
3
3
import (
4
4
"context"
5
5
"fmt"
6
+ "regexp"
6
7
"testing"
7
8
8
9
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
@@ -58,6 +59,49 @@ func TestAccGitlabGroupVariable_basic(t *testing.T) {
58
59
}),
59
60
),
60
61
},
62
+ // Update the group variable to enable "masked" for a value that does not meet masking requirements, and expect an error with no state change.
63
+ // ref: https://docs.gitlab.com/ce/ci/variables/README.html#masked-variable-requirements
64
+ {
65
+ Config : testAccGitlabGroupVariableUpdateConfigMaskedBad (rString ),
66
+ Check : resource .ComposeTestCheckFunc (
67
+ testAccCheckGitlabGroupVariableExists ("gitlab_group_variable.foo" , & groupVariable ),
68
+ testAccCheckGitlabGroupVariableAttributes (& groupVariable , & testAccGitlabGroupVariableExpectedAttributes {
69
+ Key : fmt .Sprintf ("key_%s" , rString ),
70
+ Value : fmt .Sprintf ("value-%s" , rString ),
71
+ EnvironmentScope : "*" ,
72
+ }),
73
+ ),
74
+ ExpectError : regexp .MustCompile (regexp .QuoteMeta (
75
+ "Invalid value for a masked variable. Check the masked variable requirements: https://docs.gitlab.com/ee/ci/variables/#masked-variable-requirements" ,
76
+ )),
77
+ },
78
+ // Update the group variable to to enable "masked" and meet masking requirements
79
+ // ref: https://docs.gitlab.com/ce/ci/variables/README.html#masked-variable-requirements
80
+ {
81
+ Config : testAccGitlabGroupVariableUpdateConfigMaskedGood (rString ),
82
+ Check : resource .ComposeTestCheckFunc (
83
+ testAccCheckGitlabGroupVariableExists ("gitlab_group_variable.foo" , & groupVariable ),
84
+ testAccCheckGitlabGroupVariableAttributes (& groupVariable , & testAccGitlabGroupVariableExpectedAttributes {
85
+ Key : fmt .Sprintf ("key_%s" , rString ),
86
+ Value : fmt .Sprintf ("value-%s" , rString ),
87
+ EnvironmentScope : "*" ,
88
+ Masked : true ,
89
+ }),
90
+ ),
91
+ },
92
+ // Update the group variable to toggle the options back
93
+ {
94
+ Config : testAccGitlabGroupVariableConfig (rString ),
95
+ Check : resource .ComposeTestCheckFunc (
96
+ testAccCheckGitlabGroupVariableExists ("gitlab_group_variable.foo" , & groupVariable ),
97
+ testAccCheckGitlabGroupVariableAttributes (& groupVariable , & testAccGitlabGroupVariableExpectedAttributes {
98
+ Key : fmt .Sprintf ("key_%s" , rString ),
99
+ Value : fmt .Sprintf ("value-%s" , rString ),
100
+ EnvironmentScope : "*" ,
101
+ Protected : false ,
102
+ }),
103
+ ),
104
+ },
61
105
},
62
106
})
63
107
}
@@ -291,3 +335,40 @@ resource "gitlab_group_variable" "b" {
291
335
}
292
336
` , rString , rString , rString , valueA , scopeA , rString , valueB , scopeB )
293
337
}
338
+
339
+ func testAccGitlabGroupVariableUpdateConfigMaskedBad (rString string ) string {
340
+ return fmt .Sprintf (`
341
+ resource "gitlab_group" "foo" {
342
+ name = "foo%v"
343
+ path = "foo%v"
344
+ }
345
+
346
+ resource "gitlab_group_variable" "foo" {
347
+ group = "${gitlab_group.foo.id}"
348
+ key = "key_%s"
349
+ value = <<EOF
350
+ value-%s"
351
+ i am multiline
352
+ EOF
353
+ variable_type = "env_var"
354
+ masked = true
355
+ }
356
+ ` , rString , rString , rString , rString )
357
+ }
358
+
359
+ func testAccGitlabGroupVariableUpdateConfigMaskedGood (rString string ) string {
360
+ return fmt .Sprintf (`
361
+ resource "gitlab_group" "foo" {
362
+ name = "foo%v"
363
+ path = "foo%v"
364
+ }
365
+
366
+ resource "gitlab_group_variable" "foo" {
367
+ group = "${gitlab_group.foo.id}"
368
+ key = "key_%s"
369
+ value = "value-%s"
370
+ variable_type = "env_var"
371
+ masked = true
372
+ }
373
+ ` , rString , rString , rString , rString )
374
+ }
0 commit comments