@@ -45,6 +45,7 @@ func resourceApigeeEnvironment() *schema.Resource {
45
45
"name" : {
46
46
Type : schema .TypeString ,
47
47
Required : true ,
48
+ ForceNew : true ,
48
49
Description : `The resource ID of the environment.` ,
49
50
},
50
51
"org_id" : {
@@ -89,6 +90,37 @@ Creating, updating, or deleting target servers. Possible values: ["DEPLOYMENT_TY
89
90
ForceNew : true ,
90
91
Description : `Display name of the environment.` ,
91
92
},
93
+ "node_config" : {
94
+ Type : schema .TypeList ,
95
+ Computed : true ,
96
+ Optional : true ,
97
+ Description : `NodeConfig for setting the min/max number of nodes associated with the environment.` ,
98
+ MaxItems : 1 ,
99
+ Elem : & schema.Resource {
100
+ Schema : map [string ]* schema.Schema {
101
+ "max_node_count" : {
102
+ Type : schema .TypeString ,
103
+ Optional : true ,
104
+ Description : `The maximum total number of gateway nodes that the is reserved for all instances that
105
+ has the specified environment. If not specified, the default is determined by the
106
+ recommended maximum number of nodes for that gateway.` ,
107
+ },
108
+ "min_node_count" : {
109
+ Type : schema .TypeString ,
110
+ Optional : true ,
111
+ Description : `The minimum total number of gateway nodes that the is reserved for all instances that
112
+ has the specified environment. If not specified, the default is determined by the
113
+ recommended minimum number of nodes for that gateway.` ,
114
+ },
115
+ "current_aggregate_node_count" : {
116
+ Type : schema .TypeString ,
117
+ Computed : true ,
118
+ Description : `The current total number of gateway nodes that each environment currently has across
119
+ all instances.` ,
120
+ },
121
+ },
122
+ },
123
+ },
92
124
},
93
125
UseJSONNumber : true ,
94
126
}
@@ -132,6 +164,12 @@ func resourceApigeeEnvironmentCreate(d *schema.ResourceData, meta interface{}) e
132
164
} else if v , ok := d .GetOkExists ("api_proxy_type" ); ! isEmptyValue (reflect .ValueOf (apiProxyTypeProp )) && (ok || ! reflect .DeepEqual (v , apiProxyTypeProp )) {
133
165
obj ["apiProxyType" ] = apiProxyTypeProp
134
166
}
167
+ nodeConfigProp , err := expandApigeeEnvironmentNodeConfig (d .Get ("node_config" ), d , config )
168
+ if err != nil {
169
+ return err
170
+ } else if v , ok := d .GetOkExists ("node_config" ); ! isEmptyValue (reflect .ValueOf (nodeConfigProp )) && (ok || ! reflect .DeepEqual (v , nodeConfigProp )) {
171
+ obj ["nodeConfig" ] = nodeConfigProp
172
+ }
135
173
136
174
url , err := replaceVars (d , config , "{{ApigeeBasePath}}{{org_id}}/environments" )
137
175
if err != nil {
@@ -225,6 +263,9 @@ func resourceApigeeEnvironmentRead(d *schema.ResourceData, meta interface{}) err
225
263
if err := d .Set ("api_proxy_type" , flattenApigeeEnvironmentApiProxyType (res ["apiProxyType" ], d , config )); err != nil {
226
264
return fmt .Errorf ("Error reading Environment: %s" , err )
227
265
}
266
+ if err := d .Set ("node_config" , flattenApigeeEnvironmentNodeConfig (res ["nodeConfig" ], d , config )); err != nil {
267
+ return fmt .Errorf ("Error reading Environment: %s" , err )
268
+ }
228
269
229
270
return nil
230
271
}
@@ -239,35 +280,11 @@ func resourceApigeeEnvironmentUpdate(d *schema.ResourceData, meta interface{}) e
239
280
billingProject := ""
240
281
241
282
obj := make (map [string ]interface {})
242
- nameProp , err := expandApigeeEnvironmentName (d .Get ("name " ), d , config )
283
+ nodeConfigProp , err := expandApigeeEnvironmentNodeConfig (d .Get ("node_config " ), d , config )
243
284
if err != nil {
244
285
return err
245
- } else if v , ok := d .GetOkExists ("name" ); ! isEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , nameProp )) {
246
- obj ["name" ] = nameProp
247
- }
248
- displayNameProp , err := expandApigeeEnvironmentDisplayName (d .Get ("display_name" ), d , config )
249
- if err != nil {
250
- return err
251
- } else if v , ok := d .GetOkExists ("display_name" ); ! isEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , displayNameProp )) {
252
- obj ["displayName" ] = displayNameProp
253
- }
254
- descriptionProp , err := expandApigeeEnvironmentDescription (d .Get ("description" ), d , config )
255
- if err != nil {
256
- return err
257
- } else if v , ok := d .GetOkExists ("description" ); ! isEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , descriptionProp )) {
258
- obj ["description" ] = descriptionProp
259
- }
260
- deploymentTypeProp , err := expandApigeeEnvironmentDeploymentType (d .Get ("deployment_type" ), d , config )
261
- if err != nil {
262
- return err
263
- } else if v , ok := d .GetOkExists ("deployment_type" ); ! isEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , deploymentTypeProp )) {
264
- obj ["deploymentType" ] = deploymentTypeProp
265
- }
266
- apiProxyTypeProp , err := expandApigeeEnvironmentApiProxyType (d .Get ("api_proxy_type" ), d , config )
267
- if err != nil {
268
- return err
269
- } else if v , ok := d .GetOkExists ("api_proxy_type" ); ! isEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , apiProxyTypeProp )) {
270
- obj ["apiProxyType" ] = apiProxyTypeProp
286
+ } else if v , ok := d .GetOkExists ("node_config" ); ! isEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , nodeConfigProp )) {
287
+ obj ["nodeConfig" ] = nodeConfigProp
271
288
}
272
289
273
290
url , err := replaceVars (d , config , "{{ApigeeBasePath}}{{org_id}}/environments/{{name}}" )
@@ -276,13 +293,24 @@ func resourceApigeeEnvironmentUpdate(d *schema.ResourceData, meta interface{}) e
276
293
}
277
294
278
295
log .Printf ("[DEBUG] Updating Environment %q: %#v" , d .Id (), obj )
296
+ updateMask := []string {}
297
+
298
+ if d .HasChange ("node_config" ) {
299
+ updateMask = append (updateMask , "nodeConfig" )
300
+ }
301
+ // updateMask is a URL parameter but not present in the schema, so replaceVars
302
+ // won't set it
303
+ url , err = addQueryParams (url , map [string ]string {"updateMask" : strings .Join (updateMask , "," )})
304
+ if err != nil {
305
+ return err
306
+ }
279
307
280
308
// err == nil indicates that the billing_project value was found
281
309
if bp , err := getBillingProject (d , config ); err == nil {
282
310
billingProject = bp
283
311
}
284
312
285
- res , err := sendRequestWithTimeout (config , "PUT " , billingProject , url , userAgent , obj , d .Timeout (schema .TimeoutUpdate ))
313
+ res , err := sendRequestWithTimeout (config , "PATCH " , billingProject , url , userAgent , obj , d .Timeout (schema .TimeoutUpdate ))
286
314
287
315
if err != nil {
288
316
return fmt .Errorf ("Error updating Environment %q: %s" , d .Id (), err )
@@ -405,6 +433,35 @@ func flattenApigeeEnvironmentApiProxyType(v interface{}, d *schema.ResourceData,
405
433
return v
406
434
}
407
435
436
+ func flattenApigeeEnvironmentNodeConfig (v interface {}, d * schema.ResourceData , config * Config ) interface {} {
437
+ if v == nil {
438
+ return nil
439
+ }
440
+ original := v .(map [string ]interface {})
441
+ if len (original ) == 0 {
442
+ return nil
443
+ }
444
+ transformed := make (map [string ]interface {})
445
+ transformed ["min_node_count" ] =
446
+ flattenApigeeEnvironmentNodeConfigMinNodeCount (original ["minNodeCount" ], d , config )
447
+ transformed ["max_node_count" ] =
448
+ flattenApigeeEnvironmentNodeConfigMaxNodeCount (original ["maxNodeCount" ], d , config )
449
+ transformed ["current_aggregate_node_count" ] =
450
+ flattenApigeeEnvironmentNodeConfigCurrentAggregateNodeCount (original ["currentAggregateNodeCount" ], d , config )
451
+ return []interface {}{transformed }
452
+ }
453
+ func flattenApigeeEnvironmentNodeConfigMinNodeCount (v interface {}, d * schema.ResourceData , config * Config ) interface {} {
454
+ return v
455
+ }
456
+
457
+ func flattenApigeeEnvironmentNodeConfigMaxNodeCount (v interface {}, d * schema.ResourceData , config * Config ) interface {} {
458
+ return v
459
+ }
460
+
461
+ func flattenApigeeEnvironmentNodeConfigCurrentAggregateNodeCount (v interface {}, d * schema.ResourceData , config * Config ) interface {} {
462
+ return v
463
+ }
464
+
408
465
func expandApigeeEnvironmentName (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
409
466
return v , nil
410
467
}
@@ -424,3 +481,48 @@ func expandApigeeEnvironmentDeploymentType(v interface{}, d TerraformResourceDat
424
481
func expandApigeeEnvironmentApiProxyType (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
425
482
return v , nil
426
483
}
484
+
485
+ func expandApigeeEnvironmentNodeConfig (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
486
+ l := v .([]interface {})
487
+ if len (l ) == 0 || l [0 ] == nil {
488
+ return nil , nil
489
+ }
490
+ raw := l [0 ]
491
+ original := raw .(map [string ]interface {})
492
+ transformed := make (map [string ]interface {})
493
+
494
+ transformedMinNodeCount , err := expandApigeeEnvironmentNodeConfigMinNodeCount (original ["min_node_count" ], d , config )
495
+ if err != nil {
496
+ return nil , err
497
+ } else if val := reflect .ValueOf (transformedMinNodeCount ); val .IsValid () && ! isEmptyValue (val ) {
498
+ transformed ["minNodeCount" ] = transformedMinNodeCount
499
+ }
500
+
501
+ transformedMaxNodeCount , err := expandApigeeEnvironmentNodeConfigMaxNodeCount (original ["max_node_count" ], d , config )
502
+ if err != nil {
503
+ return nil , err
504
+ } else if val := reflect .ValueOf (transformedMaxNodeCount ); val .IsValid () && ! isEmptyValue (val ) {
505
+ transformed ["maxNodeCount" ] = transformedMaxNodeCount
506
+ }
507
+
508
+ transformedCurrentAggregateNodeCount , err := expandApigeeEnvironmentNodeConfigCurrentAggregateNodeCount (original ["current_aggregate_node_count" ], d , config )
509
+ if err != nil {
510
+ return nil , err
511
+ } else if val := reflect .ValueOf (transformedCurrentAggregateNodeCount ); val .IsValid () && ! isEmptyValue (val ) {
512
+ transformed ["currentAggregateNodeCount" ] = transformedCurrentAggregateNodeCount
513
+ }
514
+
515
+ return transformed , nil
516
+ }
517
+
518
+ func expandApigeeEnvironmentNodeConfigMinNodeCount (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
519
+ return v , nil
520
+ }
521
+
522
+ func expandApigeeEnvironmentNodeConfigMaxNodeCount (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
523
+ return v , nil
524
+ }
525
+
526
+ func expandApigeeEnvironmentNodeConfigCurrentAggregateNodeCount (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
527
+ return v , nil
528
+ }
0 commit comments