@@ -259,28 +259,50 @@ func flattenVariableGroup(d *schema.ResourceData, variableGroup *taskagent.Varia
259
259
d .SetId (fmt .Sprintf ("%d" , * variableGroup .Id ))
260
260
d .Set ("name" , * variableGroup .Name )
261
261
d .Set ("description" , * variableGroup .Description )
262
- d .Set ("variable" , flattenVariables (variableGroup ))
262
+ d .Set ("variable" , flattenVariables (d , variableGroup ))
263
263
d .Set ("project_id" , projectID )
264
264
}
265
265
266
266
// Convert AzDO Variables data structure to Terraform TypeSet
267
- func flattenVariables (variableGroup * taskagent.VariableGroup ) interface {} {
267
+ //
268
+ // Note: The AzDO API does not return the value for variables marked as a secret. For this reason
269
+ // variables marked as secret will need to be pulled from the state itself
270
+ func flattenVariables (d * schema.ResourceData , variableGroup * taskagent.VariableGroup ) interface {} {
268
271
// Preallocate list of variable prop maps
269
272
variables := make ([]map [string ]interface {}, len (* variableGroup .Variables ))
270
273
271
274
index := 0
272
- for k , v := range * variableGroup .Variables {
273
- variables [index ] = map [string ]interface {}{
274
- "name" : k ,
275
- "value" : converter .ToString (v .Value , "" ),
276
- "is_secret" : converter .ToBool (v .IsSecret , false ),
275
+ for varName , varVal := range * variableGroup .Variables {
276
+ var variable map [string ]interface {}
277
+ if converter .ToBool (varVal .IsSecret , false ) {
278
+ variable = findVariableFromState (d , varName )
279
+ } else {
280
+ variable = map [string ]interface {}{
281
+ "name" : varName ,
282
+ "value" : converter .ToString (varVal .Value , "" ),
283
+ "is_secret" : false ,
284
+ }
277
285
}
286
+ variables [index ] = variable
278
287
index = index + 1
279
288
}
280
289
281
290
return variables
282
291
}
283
292
293
+ // Pulls a variable with a given name from the state. If no such variable is found, nil
294
+ // will be returned.
295
+ func findVariableFromState (d * schema.ResourceData , name string ) map [string ]interface {} {
296
+ for _ , variable := range d .Get ("variable" ).(* schema.Set ).List () {
297
+ asMap := variable .(map [string ]interface {})
298
+ // Note: casing matters here so we will use `==` over `strings.EqualFold`
299
+ if asMap ["name" ] == name {
300
+ return asMap
301
+ }
302
+ }
303
+ return nil
304
+ }
305
+
284
306
// Convert internal Terraform data structure to an AzDO data structure for Allow Access
285
307
func expandDefinitionResourceAuth (d * schema.ResourceData , createdVariableGroup * taskagent.VariableGroup ) []build.DefinitionResourceReference {
286
308
resourceRefType := "variablegroup"
0 commit comments