File tree 3 files changed +44
-6
lines changed
examples/resources/coder_parameter 3 files changed +44
-6
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ data "coder_parameter" "example" {
7
7
description = " Specify a region to place your workspace."
8
8
mutable = false
9
9
type = " string"
10
+ default = " asia-central1-a"
10
11
option {
11
12
value = " us-central1-a"
12
13
name = " US Central"
Original file line number Diff line number Diff line change @@ -122,6 +122,13 @@ func parameterDataSource() *schema.Resource {
122
122
values [option .Value ] = nil
123
123
names [option .Name ] = nil
124
124
}
125
+
126
+ if parameter .Default != "" {
127
+ _ , defaultIsValid := values [parameter .Default ]
128
+ if ! defaultIsValid {
129
+ return diag .Errorf ("default value %q must be defined as one of options" , parameter .Default )
130
+ }
131
+ }
125
132
}
126
133
127
134
return nil
@@ -156,10 +163,9 @@ func parameterDataSource() *schema.Resource {
156
163
Description : "Whether this value can be changed after workspace creation. This can be destructive for values like region, so use with caution!" ,
157
164
},
158
165
"default" : {
159
- Type : schema .TypeString ,
160
- Optional : true ,
161
- Description : "A default value for the parameter." ,
162
- ExactlyOneOf : []string {"option" },
166
+ Type : schema .TypeString ,
167
+ Optional : true ,
168
+ Description : "A default value for the parameter." ,
163
169
},
164
170
"icon" : {
165
171
Type : schema .TypeString ,
Original file line number Diff line number Diff line change @@ -174,7 +174,38 @@ data "coder_parameter" "region" {
174
174
}
175
175
},
176
176
}, {
177
- Name : "DefaultWithOption" ,
177
+ Name : "ValidDefaultWithOptions" ,
178
+ Config : `
179
+ data "coder_parameter" "region" {
180
+ name = "Region"
181
+ type = "string"
182
+ default = "2"
183
+ option {
184
+ name = "1"
185
+ value = "1"
186
+ icon = "/icon/code.svg"
187
+ description = "Something!"
188
+ }
189
+ option {
190
+ name = "2"
191
+ value = "2"
192
+ }
193
+ }
194
+ ` ,
195
+ Check : func (state * terraform.ResourceState ) {
196
+ for key , expected := range map [string ]string {
197
+ "name" : "Region" ,
198
+ "option.#" : "2" ,
199
+ "option.0.name" : "1" ,
200
+ "option.0.value" : "1" ,
201
+ "option.0.icon" : "/icon/code.svg" ,
202
+ "option.0.description" : "Something!" ,
203
+ } {
204
+ require .Equal (t , expected , state .Primary .Attributes [key ])
205
+ }
206
+ },
207
+ }, {
208
+ Name : "InvalidDefaultWithOption" ,
178
209
Config : `
179
210
data "coder_parameter" "region" {
180
211
name = "Region"
@@ -189,7 +220,7 @@ data "coder_parameter" "region" {
189
220
}
190
221
}
191
222
` ,
192
- ExpectError : regexp .MustCompile ("Invalid combination of arguments " ),
223
+ ExpectError : regexp .MustCompile ("must be defined as one of options " ),
193
224
}, {
194
225
Name : "SingleOption" ,
195
226
Config : `
You can’t perform that action at this time.
0 commit comments