@@ -2,6 +2,7 @@ package provider
2
2
3
3
import (
4
4
"fmt"
5
+ "regexp"
5
6
"testing"
6
7
7
8
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
@@ -54,6 +55,46 @@ func TestAccGitlabInstanceVariable_basic(t *testing.T) {
54
55
}),
55
56
),
56
57
},
58
+ // Update the instance variable to enable "masked" for a value that does not meet masking requirements, and expect an error with no state change.
59
+ // ref: https://docs.gitlab.com/ce/ci/variables/README.html#masked-variable-requirements
60
+ {
61
+ Config : testAccGitlabInstanceVariableUpdateConfigMaskedBad (rString ),
62
+ Check : resource .ComposeTestCheckFunc (
63
+ testAccCheckGitlabInstanceVariableExists ("gitlab_instance_variable.foo" , & instanceVariable ),
64
+ testAccCheckGitlabInstanceVariableAttributes (& instanceVariable , & testAccGitlabInstanceVariableExpectedAttributes {
65
+ Key : fmt .Sprintf ("key_%s" , rString ),
66
+ Value : fmt .Sprintf ("value-%s" , rString ),
67
+ }),
68
+ ),
69
+ ExpectError : regexp .MustCompile (regexp .QuoteMeta (
70
+ "Invalid value for a masked variable. Check the masked variable requirements: https://docs.gitlab.com/ee/ci/variables/#masked-variable-requirements" ,
71
+ )),
72
+ },
73
+ // Update the instance variable to to enable "masked" and meet masking requirements
74
+ // ref: https://docs.gitlab.com/ce/ci/variables/README.html#masked-variable-requirements
75
+ {
76
+ Config : testAccGitlabInstanceVariableUpdateConfigMaskedGood (rString ),
77
+ Check : resource .ComposeTestCheckFunc (
78
+ testAccCheckGitlabInstanceVariableExists ("gitlab_instance_variable.foo" , & instanceVariable ),
79
+ testAccCheckGitlabInstanceVariableAttributes (& instanceVariable , & testAccGitlabInstanceVariableExpectedAttributes {
80
+ Key : fmt .Sprintf ("key_%s" , rString ),
81
+ Value : fmt .Sprintf ("value-%s" , rString ),
82
+ Masked : true ,
83
+ }),
84
+ ),
85
+ },
86
+ // Update the instance variable to toggle the options back
87
+ {
88
+ Config : testAccGitlabInstanceVariableConfig (rString ),
89
+ Check : resource .ComposeTestCheckFunc (
90
+ testAccCheckGitlabInstanceVariableExists ("gitlab_instance_variable.foo" , & instanceVariable ),
91
+ testAccCheckGitlabInstanceVariableAttributes (& instanceVariable , & testAccGitlabInstanceVariableExpectedAttributes {
92
+ Key : fmt .Sprintf ("key_%s" , rString ),
93
+ Value : fmt .Sprintf ("value-%s" , rString ),
94
+ Protected : false ,
95
+ }),
96
+ ),
97
+ },
57
98
},
58
99
})
59
100
}
@@ -129,3 +170,26 @@ resource "gitlab_instance_variable" "foo" {
129
170
}
130
171
` , rString , rString )
131
172
}
173
+
174
+ func testAccGitlabInstanceVariableUpdateConfigMaskedBad (rString string ) string {
175
+ return fmt .Sprintf (`
176
+ resource "gitlab_instance_variable" "foo" {
177
+ key = "key_%s"
178
+ value = <<EOF
179
+ value-%s"
180
+ i am multiline
181
+ EOF
182
+ masked = true
183
+ }
184
+ ` , rString , rString )
185
+ }
186
+
187
+ func testAccGitlabInstanceVariableUpdateConfigMaskedGood (rString string ) string {
188
+ return fmt .Sprintf (`
189
+ resource "gitlab_instance_variable" "foo" {
190
+ key = "key_%s"
191
+ value = "value-%s"
192
+ masked = true
193
+ }
194
+ ` , rString , rString )
195
+ }
0 commit comments