@@ -43,7 +43,7 @@ func newBlueprintResource() *schema.Resource {
43
43
Type : schema .TypeString ,
44
44
Description : "The icon of the blueprint" ,
45
45
ValidateFunc : validation .StringInSlice (ICONS , false ),
46
- Required : true ,
46
+ Optional : true ,
47
47
},
48
48
"description" : {
49
49
Type : schema .TypeString ,
@@ -182,6 +182,64 @@ func newBlueprintResource() *schema.Resource {
182
182
},
183
183
Optional : true ,
184
184
},
185
+ "calculation_properties" : {
186
+ Type : schema .TypeSet ,
187
+ Description : "A set of properties that are calculated upon Entitys regular properties." ,
188
+ Elem : & schema.Resource {
189
+ Schema : map [string ]* schema.Schema {
190
+ "identifier" : {
191
+ Type : schema .TypeString ,
192
+ Required : true ,
193
+ Description : "The identifier of the property" ,
194
+ },
195
+ "title" : {
196
+ Type : schema .TypeString ,
197
+ Optional : true ,
198
+ Description : "The name of this property" ,
199
+ },
200
+ "calculation" : {
201
+ Type : schema .TypeString ,
202
+ Required : true ,
203
+ Description : "A jq expression that calculates the value of the property, for instance \" 'https://grafana.' + .identifier\" " ,
204
+ },
205
+ "icon" : {
206
+ Type : schema .TypeString ,
207
+ ValidateFunc : validation .StringInSlice (ICONS , false ),
208
+ Optional : true ,
209
+ Description : "The icon of the property" ,
210
+ },
211
+ "type" : {
212
+ Type : schema .TypeString ,
213
+ Required : true ,
214
+ Description : "The type of the property" ,
215
+ },
216
+ "description" : {
217
+ Type : schema .TypeString ,
218
+ Optional : true ,
219
+ Description : "The description of the property" ,
220
+ },
221
+ "format" : {
222
+ Type : schema .TypeString ,
223
+ Optional : true ,
224
+ Description : "The format of the Property" ,
225
+ },
226
+ "colorized" : {
227
+ Type : schema .TypeBool ,
228
+ Optional : true ,
229
+ Description : "Whether or not the property is colorized" ,
230
+ },
231
+ "colors" : {
232
+ Type : schema .TypeMap ,
233
+ Elem : & schema.Schema {
234
+ Type : schema .TypeString ,
235
+ },
236
+ Optional : true ,
237
+ Description : "A map of colors for the property" ,
238
+ },
239
+ },
240
+ },
241
+ Optional : true ,
242
+ },
185
243
"changelog_destination" : {
186
244
Type : schema .TypeList ,
187
245
MinItems : 1 ,
@@ -256,7 +314,12 @@ func writeBlueprintFieldsToResource(d *schema.ResourceData, b *cli.Blueprint) {
256
314
return schema .HashString (id )
257
315
}}
258
316
259
- mirror_properties := schema.Set {F : func (i interface {}) int {
317
+ mirrorPoperties := schema.Set {F : func (i interface {}) int {
318
+ id := (i .(map [string ]interface {}))["identifier" ].(string )
319
+ return schema .HashString (id )
320
+ }}
321
+
322
+ calculationProperties := schema.Set {F : func (i interface {}) int {
260
323
id := (i .(map [string ]interface {}))["identifier" ].(string )
261
324
return schema .HashString (id )
262
325
}}
@@ -304,11 +367,27 @@ func writeBlueprintFieldsToResource(d *schema.ResourceData, b *cli.Blueprint) {
304
367
p ["identifier" ] = k
305
368
p ["title" ] = v .Title
306
369
p ["path" ] = v .Path
307
- mirror_properties .Add (p )
370
+ mirrorPoperties .Add (p )
371
+ }
372
+
373
+ for k , v := range b .CalculationProperties {
374
+ p := map [string ]interface {}{}
375
+ p ["identifier" ] = k
376
+ p ["title" ] = v .Title
377
+ p ["description" ] = v .Description
378
+ p ["icon" ] = v .Icon
379
+ p ["calculation" ] = v .Calculation
380
+ p ["type" ] = v .Type
381
+ p ["format" ] = v .Format
382
+ p ["colorized" ] = v .Colorized
383
+ p ["colors" ] = v .Colors
384
+
385
+ calculationProperties .Add (p )
308
386
}
309
387
310
388
d .Set ("properties" , & properties )
311
- d .Set ("mirror_properties" , & mirror_properties )
389
+ d .Set ("mirror_properties" , & mirrorPoperties )
390
+ d .Set ("calculation_properties" , & calculationProperties )
312
391
}
313
392
314
393
func blueprintResourceToBody (d * schema.ResourceData ) (* cli.Blueprint , error ) {
@@ -325,7 +404,8 @@ func blueprintResourceToBody(d *schema.ResourceData) (*cli.Blueprint, error) {
325
404
b .Icon = d .Get ("icon" ).(string )
326
405
b .Description = d .Get ("description" ).(string )
327
406
props := d .Get ("properties" ).(* schema.Set )
328
- mirror_props := d .Get ("mirror_properties" ).(* schema.Set )
407
+ mirrorProps := d .Get ("mirror_properties" ).(* schema.Set )
408
+ calcProps := d .Get ("calculation_properties" ).(* schema.Set )
329
409
330
410
if changelogDestination , ok := d .GetOk ("changelog_destination" ); ok {
331
411
if b .ChangelogDestination == nil {
@@ -411,8 +491,8 @@ func blueprintResourceToBody(d *schema.ResourceData) (*cli.Blueprint, error) {
411
491
}
412
492
}
413
493
414
- mirror_properties := make (map [string ]cli.BlueprintMirrorProperty , mirror_props .Len ())
415
- for _ , prop := range mirror_props .List () {
494
+ mirrorProperties := make (map [string ]cli.BlueprintMirrorProperty , mirrorProps .Len ())
495
+ for _ , prop := range mirrorProps .List () {
416
496
p := prop .(map [string ]interface {})
417
497
propFields := cli.BlueprintMirrorProperty {}
418
498
if t , ok := p ["title" ]; ok && t != "" {
@@ -421,7 +501,43 @@ func blueprintResourceToBody(d *schema.ResourceData) (*cli.Blueprint, error) {
421
501
if p , ok := p ["path" ]; ok && p != "" {
422
502
propFields .Path = p .(string )
423
503
}
424
- mirror_properties [p ["identifier" ].(string )] = propFields
504
+ mirrorProperties [p ["identifier" ].(string )] = propFields
505
+ }
506
+
507
+ calculationProperties := make (map [string ]cli.BlueprintCalculationProperty , calcProps .Len ())
508
+ for _ , prop := range calcProps .List () {
509
+ p := prop .(map [string ]interface {})
510
+ calcFields := cli.BlueprintCalculationProperty {}
511
+ if t , ok := p ["type" ]; ok && t != "" {
512
+ calcFields .Type = t .(string )
513
+ }
514
+ if t , ok := p ["title" ]; ok && t != "" {
515
+ calcFields .Title = t .(string )
516
+ }
517
+ if d , ok := p ["description" ]; ok && d != "" {
518
+ calcFields .Description = d .(string )
519
+ }
520
+ if f , ok := p ["format" ]; ok && f != "" {
521
+ calcFields .Format = f .(string )
522
+ }
523
+ if i , ok := p ["icon" ]; ok && i != "" {
524
+ calcFields .Icon = i .(string )
525
+ }
526
+ if r , ok := p ["colorized" ]; ok && r .(bool ) {
527
+ calcFields .Colorized = r .(bool )
528
+ }
529
+ if e , ok := p ["colors" ]; ok && e != nil {
530
+ colors := make (map [string ]string )
531
+ for key , value := range e .(map [string ]interface {}) {
532
+ colors [key ] = value .(string )
533
+ }
534
+ calcFields .Colors = colors
535
+ }
536
+ calcFields .Calculation = p ["calculation" ].(string )
537
+ // TODO: remove the if statement when this issues is solved, https://github.com/hashicorp/terraform-plugin-sdk/pull/1042/files
538
+ if p ["identifier" ] != "" {
539
+ calculationProperties [p ["identifier" ].(string )] = calcFields
540
+ }
425
541
}
426
542
427
543
rels := d .Get ("relations" ).(* schema.Set )
@@ -447,7 +563,8 @@ func blueprintResourceToBody(d *schema.ResourceData) (*cli.Blueprint, error) {
447
563
448
564
b .Schema = cli.BlueprintSchema {Properties : properties , Required : required }
449
565
b .Relations = relations
450
- b .MirrorProperties = mirror_properties
566
+ b .MirrorProperties = mirrorProperties
567
+ b .CalculationProperties = calculationProperties
451
568
return b , nil
452
569
}
453
570
0 commit comments