Skip to content

Commit 4f86238

Browse files
add initial_size to google_compute_node_group (#4750) (#3228)
Co-authored-by: Riley Karson <[email protected]> Signed-off-by: Modular Magician <[email protected]> Co-authored-by: Riley Karson <[email protected]>
1 parent da7fca3 commit 4f86238

File tree

5 files changed

+41
-17
lines changed

5 files changed

+41
-17
lines changed

.changelog/4750.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
compute: added `initial_size` to account for scenarios where size may change under the hood in resource `google_compute_node_group`
3+
```

google-beta/resource_compute_node_group.go

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"fmt"
1919
"log"
2020
"reflect"
21+
"regexp"
2122
"strconv"
2223
"time"
2324

@@ -49,12 +50,6 @@ func resourceComputeNodeGroup() *schema.Resource {
4950
DiffSuppressFunc: compareSelfLinkOrResourceName,
5051
Description: `The URL of the node template to which this node group belongs.`,
5152
},
52-
"size": {
53-
Type: schema.TypeInt,
54-
Required: true,
55-
ForceNew: true,
56-
Description: `The total number of nodes in the node group.`,
57-
},
5853
"autoscaling_policy": {
5954
Type: schema.TypeList,
6055
Computed: true,
@@ -103,6 +98,13 @@ than or equal to max-nodes. The default value is 0.`,
10398
ForceNew: true,
10499
Description: `An optional textual description of the resource.`,
105100
},
101+
"initial_size": {
102+
Type: schema.TypeInt,
103+
Optional: true,
104+
ForceNew: true,
105+
Description: `The initial number of nodes in the node group. One of 'initial_size' or 'size' must be specified.`,
106+
ExactlyOneOf: []string{"size", "initial_size"},
107+
},
106108
"maintenance_policy": {
107109
Type: schema.TypeString,
108110
Optional: true,
@@ -133,6 +135,14 @@ than or equal to max-nodes. The default value is 0.`,
133135
ForceNew: true,
134136
Description: `Name of the resource.`,
135137
},
138+
"size": {
139+
Type: schema.TypeInt,
140+
Computed: true,
141+
Optional: true,
142+
ForceNew: true,
143+
Description: `The total number of nodes in the node group. One of 'initial_size' or 'size' must be specified.`,
144+
ExactlyOneOf: []string{"size", "initial_size"},
145+
},
136146
"zone": {
137147
Type: schema.TypeString,
138148
Computed: true,
@@ -218,7 +228,7 @@ func resourceComputeNodeGroupCreate(d *schema.ResourceData, meta interface{}) er
218228
obj["zone"] = zoneProp
219229
}
220230

221-
url, err := replaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/zones/{{zone}}/nodeGroups?initialNodeCount={{size}}")
231+
url, err := replaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/zones/{{zone}}/nodeGroups?initialNodeCount=PRE_CREATE_REPLACE_ME")
222232
if err != nil {
223233
return err
224234
}
@@ -237,6 +247,14 @@ func resourceComputeNodeGroupCreate(d *schema.ResourceData, meta interface{}) er
237247
billingProject = bp
238248
}
239249

250+
var sizeParam string
251+
if v, ok := d.GetOkExists("size"); ok {
252+
sizeParam = fmt.Sprintf("%v", v)
253+
} else if v, ok := d.GetOkExists("initial_size"); ok {
254+
sizeParam = fmt.Sprintf("%v", v)
255+
}
256+
257+
url = regexp.MustCompile("PRE_CREATE_REPLACE_ME").ReplaceAllLiteralString(url, sizeParam)
240258
res, err := sendRequestWithTimeout(config, "POST", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutCreate))
241259
if err != nil {
242260
return fmt.Errorf("Error creating NodeGroup: %s", err)

google-beta/resource_compute_node_group_generated_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestAccComputeNodeGroup_nodeGroupBasicExample(t *testing.T) {
4242
ResourceName: "google_compute_node_group.nodes",
4343
ImportState: true,
4444
ImportStateVerify: true,
45-
ImportStateVerifyIgnore: []string{"node_template", "zone"},
45+
ImportStateVerifyIgnore: []string{"node_template", "initial_size", "zone"},
4646
},
4747
},
4848
})
@@ -86,7 +86,7 @@ func TestAccComputeNodeGroup_nodeGroupAutoscalingPolicyExample(t *testing.T) {
8686
ResourceName: "google_compute_node_group.nodes",
8787
ImportState: true,
8888
ImportStateVerify: true,
89-
ImportStateVerifyIgnore: []string{"node_template", "zone"},
89+
ImportStateVerifyIgnore: []string{"node_template", "initial_size", "zone"},
9090
},
9191
},
9292
})
@@ -108,7 +108,7 @@ resource "google_compute_node_group" "nodes" {
108108
maintenance_window {
109109
start_time = "08:00"
110110
}
111-
size = 1
111+
initial_size = 1
112112
node_template = google_compute_node_template.soletenant-tmpl.id
113113
autoscaling_policy {
114114
mode = "ONLY_SCALE_OUT"

google-beta/resource_dataproc_cluster_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ import (
1313
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1414
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
1515

16-
"google.golang.org/api/googleapi"
17-
1816
dataproc "google.golang.org/api/dataproc/v1beta2"
17+
"google.golang.org/api/googleapi"
1918
)
2019

2120
func TestDataprocExtractInitTimeout(t *testing.T) {

website/docs/r/compute_node_group.html.markdown

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ resource "google_compute_node_group" "nodes" {
8383
maintenance_window {
8484
start_time = "08:00"
8585
}
86-
size = 1
86+
initial_size = 1
8787
node_template = google_compute_node_template.soletenant-tmpl.id
8888
autoscaling_policy {
8989
mode = "ONLY_SCALE_OUT"
@@ -102,10 +102,6 @@ The following arguments are supported:
102102
(Required)
103103
The URL of the node template to which this node group belongs.
104104

105-
* `size` -
106-
(Required)
107-
The total number of nodes in the node group.
108-
109105

110106
- - -
111107

@@ -118,6 +114,14 @@ The following arguments are supported:
118114
(Optional)
119115
Name of the resource.
120116

117+
* `size` -
118+
(Optional)
119+
The total number of nodes in the node group. One of `initial_size` or `size` must be specified.
120+
121+
* `initial_size` -
122+
(Optional)
123+
The initial number of nodes in the node group. One of `initial_size` or `size` must be specified.
124+
121125
* `maintenance_policy` -
122126
(Optional)
123127
Specifies how to handle instances when a node in the group undergoes maintenance. Set to one of: DEFAULT, RESTART_IN_PLACE, or MIGRATE_WITHIN_NODE_GROUP. The default value is DEFAULT.

0 commit comments

Comments
 (0)