@@ -132,6 +132,35 @@ all instances.`,
132
132
},
133
133
},
134
134
},
135
+ "properties" : {
136
+ Type : schema .TypeList ,
137
+ Optional : true ,
138
+ Description : `Key-value pairs that may be used for customizing the environment.` ,
139
+ MaxItems : 1 ,
140
+ Elem : & schema.Resource {
141
+ Schema : map [string ]* schema.Schema {
142
+ "property" : {
143
+ Type : schema .TypeList ,
144
+ Optional : true ,
145
+ Description : `List of all properties in the object.` ,
146
+ Elem : & schema.Resource {
147
+ Schema : map [string ]* schema.Schema {
148
+ "name" : {
149
+ Type : schema .TypeString ,
150
+ Optional : true ,
151
+ Description : `The property key.` ,
152
+ },
153
+ "value" : {
154
+ Type : schema .TypeString ,
155
+ Optional : true ,
156
+ Description : `The property value.` ,
157
+ },
158
+ },
159
+ },
160
+ },
161
+ },
162
+ },
163
+ },
135
164
"type" : {
136
165
Type : schema .TypeString ,
137
166
Computed : true ,
@@ -203,6 +232,12 @@ func resourceApigeeEnvironmentCreate(d *schema.ResourceData, meta interface{}) e
203
232
} else if v , ok := d .GetOkExists ("forward_proxy_uri" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (forwardProxyUriProp )) && (ok || ! reflect .DeepEqual (v , forwardProxyUriProp )) {
204
233
obj ["forwardProxyUri" ] = forwardProxyUriProp
205
234
}
235
+ propertiesProp , err := expandApigeeEnvironmentProperties (d .Get ("properties" ), d , config )
236
+ if err != nil {
237
+ return err
238
+ } else if v , ok := d .GetOkExists ("properties" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (propertiesProp )) && (ok || ! reflect .DeepEqual (v , propertiesProp )) {
239
+ obj ["properties" ] = propertiesProp
240
+ }
206
241
207
242
url , err := tpgresource .ReplaceVars (d , config , "{{ApigeeBasePath}}{{org_id}}/environments" )
208
243
if err != nil {
@@ -324,6 +359,9 @@ func resourceApigeeEnvironmentRead(d *schema.ResourceData, meta interface{}) err
324
359
if err := d .Set ("forward_proxy_uri" , flattenApigeeEnvironmentForwardProxyUri (res ["forwardProxyUri" ], d , config )); err != nil {
325
360
return fmt .Errorf ("Error reading Environment: %s" , err )
326
361
}
362
+ if err := d .Set ("properties" , flattenApigeeEnvironmentProperties (res ["properties" ], d , config )); err != nil {
363
+ return fmt .Errorf ("Error reading Environment: %s" , err )
364
+ }
327
365
328
366
return nil
329
367
}
@@ -368,6 +406,12 @@ func resourceApigeeEnvironmentUpdate(d *schema.ResourceData, meta interface{}) e
368
406
} else if v , ok := d .GetOkExists ("forward_proxy_uri" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , forwardProxyUriProp )) {
369
407
obj ["forwardProxyUri" ] = forwardProxyUriProp
370
408
}
409
+ propertiesProp , err := expandApigeeEnvironmentProperties (d .Get ("properties" ), d , config )
410
+ if err != nil {
411
+ return err
412
+ } else if v , ok := d .GetOkExists ("properties" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , propertiesProp )) {
413
+ obj ["properties" ] = propertiesProp
414
+ }
371
415
372
416
url , err := tpgresource .ReplaceVars (d , config , "{{ApigeeBasePath}}{{org_id}}/environments/{{name}}" )
373
417
if err != nil {
@@ -397,6 +441,10 @@ func resourceApigeeEnvironmentUpdate(d *schema.ResourceData, meta interface{}) e
397
441
if d .HasChange ("forward_proxy_uri" ) {
398
442
updateMask = append (updateMask , "forwardProxyUri" )
399
443
}
444
+
445
+ if d .HasChange ("properties" ) {
446
+ updateMask = append (updateMask , "properties" )
447
+ }
400
448
// updateMask is a URL parameter but not present in the schema, so ReplaceVars
401
449
// won't set it
402
450
url , err = transport_tpg .AddQueryParams (url , map [string ]string {"updateMask" : strings .Join (updateMask , "," )})
@@ -585,6 +633,46 @@ func flattenApigeeEnvironmentForwardProxyUri(v interface{}, d *schema.ResourceDa
585
633
return v
586
634
}
587
635
636
+ func flattenApigeeEnvironmentProperties (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
637
+ if v == nil {
638
+ return nil
639
+ }
640
+ original := v .(map [string ]interface {})
641
+ if len (original ) == 0 {
642
+ return nil
643
+ }
644
+ transformed := make (map [string ]interface {})
645
+ transformed ["property" ] =
646
+ flattenApigeeEnvironmentPropertiesProperty (original ["property" ], d , config )
647
+ return []interface {}{transformed }
648
+ }
649
+ func flattenApigeeEnvironmentPropertiesProperty (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
650
+ if v == nil {
651
+ return v
652
+ }
653
+ l := v .([]interface {})
654
+ transformed := make ([]interface {}, 0 , len (l ))
655
+ for _ , raw := range l {
656
+ original := raw .(map [string ]interface {})
657
+ if len (original ) < 1 {
658
+ // Do not include empty json objects coming back from the api
659
+ continue
660
+ }
661
+ transformed = append (transformed , map [string ]interface {}{
662
+ "name" : flattenApigeeEnvironmentPropertiesPropertyName (original ["name" ], d , config ),
663
+ "value" : flattenApigeeEnvironmentPropertiesPropertyValue (original ["value" ], d , config ),
664
+ })
665
+ }
666
+ return transformed
667
+ }
668
+ func flattenApigeeEnvironmentPropertiesPropertyName (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
669
+ return v
670
+ }
671
+
672
+ func flattenApigeeEnvironmentPropertiesPropertyValue (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
673
+ return v
674
+ }
675
+
588
676
func expandApigeeEnvironmentName (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
589
677
return v , nil
590
678
}
@@ -657,3 +745,59 @@ func expandApigeeEnvironmentType(v interface{}, d tpgresource.TerraformResourceD
657
745
func expandApigeeEnvironmentForwardProxyUri (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
658
746
return v , nil
659
747
}
748
+
749
+ func expandApigeeEnvironmentProperties (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
750
+ l := v .([]interface {})
751
+ if len (l ) == 0 || l [0 ] == nil {
752
+ return nil , nil
753
+ }
754
+ raw := l [0 ]
755
+ original := raw .(map [string ]interface {})
756
+ transformed := make (map [string ]interface {})
757
+
758
+ transformedProperty , err := expandApigeeEnvironmentPropertiesProperty (original ["property" ], d , config )
759
+ if err != nil {
760
+ return nil , err
761
+ } else if val := reflect .ValueOf (transformedProperty ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
762
+ transformed ["property" ] = transformedProperty
763
+ }
764
+
765
+ return transformed , nil
766
+ }
767
+
768
+ func expandApigeeEnvironmentPropertiesProperty (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
769
+ l := v .([]interface {})
770
+ req := make ([]interface {}, 0 , len (l ))
771
+ for _ , raw := range l {
772
+ if raw == nil {
773
+ continue
774
+ }
775
+ original := raw .(map [string ]interface {})
776
+ transformed := make (map [string ]interface {})
777
+
778
+ transformedName , err := expandApigeeEnvironmentPropertiesPropertyName (original ["name" ], d , config )
779
+ if err != nil {
780
+ return nil , err
781
+ } else if val := reflect .ValueOf (transformedName ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
782
+ transformed ["name" ] = transformedName
783
+ }
784
+
785
+ transformedValue , err := expandApigeeEnvironmentPropertiesPropertyValue (original ["value" ], d , config )
786
+ if err != nil {
787
+ return nil , err
788
+ } else if val := reflect .ValueOf (transformedValue ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
789
+ transformed ["value" ] = transformedValue
790
+ }
791
+
792
+ req = append (req , transformed )
793
+ }
794
+ return req , nil
795
+ }
796
+
797
+ func expandApigeeEnvironmentPropertiesPropertyName (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
798
+ return v , nil
799
+ }
800
+
801
+ func expandApigeeEnvironmentPropertiesPropertyValue (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
802
+ return v , nil
803
+ }
0 commit comments