Skip to content

Commit 8be44db

Browse files
Add support for nodeConfig in ApigeeEnvironment (#6349) (#12394)
Signed-off-by: Modular Magician <[email protected]> Signed-off-by: Modular Magician <[email protected]>
1 parent ad7b6e6 commit 8be44db

File tree

4 files changed

+157
-28
lines changed

4 files changed

+157
-28
lines changed

.changelog/6349.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
Add support for nodeConfig in ApigeeEnvironment
3+
```

google/resource_apigee_environment.go

+130-28
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func resourceApigeeEnvironment() *schema.Resource {
4545
"name": {
4646
Type: schema.TypeString,
4747
Required: true,
48+
ForceNew: true,
4849
Description: `The resource ID of the environment.`,
4950
},
5051
"org_id": {
@@ -89,6 +90,37 @@ Creating, updating, or deleting target servers. Possible values: ["DEPLOYMENT_TY
8990
ForceNew: true,
9091
Description: `Display name of the environment.`,
9192
},
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+
},
92124
},
93125
UseJSONNumber: true,
94126
}
@@ -132,6 +164,12 @@ func resourceApigeeEnvironmentCreate(d *schema.ResourceData, meta interface{}) e
132164
} else if v, ok := d.GetOkExists("api_proxy_type"); !isEmptyValue(reflect.ValueOf(apiProxyTypeProp)) && (ok || !reflect.DeepEqual(v, apiProxyTypeProp)) {
133165
obj["apiProxyType"] = apiProxyTypeProp
134166
}
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+
}
135173

136174
url, err := replaceVars(d, config, "{{ApigeeBasePath}}{{org_id}}/environments")
137175
if err != nil {
@@ -225,6 +263,9 @@ func resourceApigeeEnvironmentRead(d *schema.ResourceData, meta interface{}) err
225263
if err := d.Set("api_proxy_type", flattenApigeeEnvironmentApiProxyType(res["apiProxyType"], d, config)); err != nil {
226264
return fmt.Errorf("Error reading Environment: %s", err)
227265
}
266+
if err := d.Set("node_config", flattenApigeeEnvironmentNodeConfig(res["nodeConfig"], d, config)); err != nil {
267+
return fmt.Errorf("Error reading Environment: %s", err)
268+
}
228269

229270
return nil
230271
}
@@ -239,35 +280,11 @@ func resourceApigeeEnvironmentUpdate(d *schema.ResourceData, meta interface{}) e
239280
billingProject := ""
240281

241282
obj := make(map[string]interface{})
242-
nameProp, err := expandApigeeEnvironmentName(d.Get("name"), d, config)
283+
nodeConfigProp, err := expandApigeeEnvironmentNodeConfig(d.Get("node_config"), d, config)
243284
if err != nil {
244285
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
271288
}
272289

273290
url, err := replaceVars(d, config, "{{ApigeeBasePath}}{{org_id}}/environments/{{name}}")
@@ -276,13 +293,24 @@ func resourceApigeeEnvironmentUpdate(d *schema.ResourceData, meta interface{}) e
276293
}
277294

278295
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+
}
279307

280308
// err == nil indicates that the billing_project value was found
281309
if bp, err := getBillingProject(d, config); err == nil {
282310
billingProject = bp
283311
}
284312

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))
286314

287315
if err != nil {
288316
return fmt.Errorf("Error updating Environment %q: %s", d.Id(), err)
@@ -405,6 +433,35 @@ func flattenApigeeEnvironmentApiProxyType(v interface{}, d *schema.ResourceData,
405433
return v
406434
}
407435

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+
408465
func expandApigeeEnvironmentName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
409466
return v, nil
410467
}
@@ -424,3 +481,48 @@ func expandApigeeEnvironmentDeploymentType(v interface{}, d TerraformResourceDat
424481
func expandApigeeEnvironmentApiProxyType(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
425482
return v, nil
426483
}
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package google

website/docs/r/apigee_environment.html.markdown

+23
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,29 @@ The following arguments are supported:
111111
the Environment and cannot be changed.
112112
Possible values are `API_PROXY_TYPE_UNSPECIFIED`, `PROGRAMMABLE`, and `CONFIGURABLE`.
113113

114+
* `node_config` -
115+
(Optional)
116+
NodeConfig for setting the min/max number of nodes associated with the environment.
117+
Structure is [documented below](#nested_node_config).
118+
119+
120+
<a name="nested_node_config"></a>The `node_config` block supports:
121+
122+
* `min_node_count` -
123+
(Optional)
124+
The minimum total number of gateway nodes that the is reserved for all instances that
125+
has the specified environment. If not specified, the default is determined by the
126+
recommended minimum number of nodes for that gateway.
127+
128+
* `max_node_count` -
129+
(Optional)
130+
The maximum total number of gateway nodes that the is reserved for all instances that
131+
has the specified environment. If not specified, the default is determined by the
132+
recommended maximum number of nodes for that gateway.
133+
134+
* `current_aggregate_node_count` -
135+
The current total number of gateway nodes that each environment currently has across
136+
all instances.
114137

115138
## Attributes Reference
116139

0 commit comments

Comments
 (0)