Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add initial_size to google_compute_node_group #9078

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/4750.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
compute: added `initial_size` to account for scenarios where size may change under the hood in resource `google_compute_node_group`
```
32 changes: 25 additions & 7 deletions google/resource_compute_node_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"fmt"
"log"
"reflect"
"regexp"
"strconv"
"time"

Expand Down Expand Up @@ -49,12 +50,6 @@ func resourceComputeNodeGroup() *schema.Resource {
DiffSuppressFunc: compareSelfLinkOrResourceName,
Description: `The URL of the node template to which this node group belongs.`,
},
"size": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
Description: `The total number of nodes in the node group.`,
},
"autoscaling_policy": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -103,6 +98,13 @@ than or equal to max-nodes. The default value is 0.`,
ForceNew: true,
Description: `An optional textual description of the resource.`,
},
"initial_size": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
Description: `The initial number of nodes in the node group. One of 'initial_size' or 'size' must be specified.`,
ExactlyOneOf: []string{"size", "initial_size"},
},
"maintenance_policy": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -133,6 +135,14 @@ than or equal to max-nodes. The default value is 0.`,
ForceNew: true,
Description: `Name of the resource.`,
},
"size": {
Type: schema.TypeInt,
Computed: true,
Optional: true,
ForceNew: true,
Description: `The total number of nodes in the node group. One of 'initial_size' or 'size' must be specified.`,
ExactlyOneOf: []string{"size", "initial_size"},
},
"zone": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -218,7 +228,7 @@ func resourceComputeNodeGroupCreate(d *schema.ResourceData, meta interface{}) er
obj["zone"] = zoneProp
}

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

var sizeParam string
if v, ok := d.GetOkExists("size"); ok {
sizeParam = fmt.Sprintf("%v", v)
} else if v, ok := d.GetOkExists("initial_size"); ok {
sizeParam = fmt.Sprintf("%v", v)
}

url = regexp.MustCompile("PRE_CREATE_REPLACE_ME").ReplaceAllLiteralString(url, sizeParam)
res, err := sendRequestWithTimeout(config, "POST", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutCreate))
if err != nil {
return fmt.Errorf("Error creating NodeGroup: %s", err)
Expand Down
6 changes: 3 additions & 3 deletions google/resource_compute_node_group_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestAccComputeNodeGroup_nodeGroupBasicExample(t *testing.T) {
ResourceName: "google_compute_node_group.nodes",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"node_template", "zone"},
ImportStateVerifyIgnore: []string{"node_template", "initial_size", "zone"},
},
},
})
Expand Down Expand Up @@ -86,7 +86,7 @@ func TestAccComputeNodeGroup_nodeGroupAutoscalingPolicyExample(t *testing.T) {
ResourceName: "google_compute_node_group.nodes",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"node_template", "zone"},
ImportStateVerifyIgnore: []string{"node_template", "initial_size", "zone"},
},
},
})
Expand All @@ -108,7 +108,7 @@ resource "google_compute_node_group" "nodes" {
maintenance_window {
start_time = "08:00"
}
size = 1
initial_size = 1
node_template = google_compute_node_template.soletenant-tmpl.id
autoscaling_policy {
mode = "ONLY_SCALE_OUT"
Expand Down
14 changes: 9 additions & 5 deletions website/docs/r/compute_node_group.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ resource "google_compute_node_group" "nodes" {
maintenance_window {
start_time = "08:00"
}
size = 1
initial_size = 1
node_template = google_compute_node_template.soletenant-tmpl.id
autoscaling_policy {
mode = "ONLY_SCALE_OUT"
Expand All @@ -102,10 +102,6 @@ The following arguments are supported:
(Required)
The URL of the node template to which this node group belongs.

* `size` -
(Required)
The total number of nodes in the node group.


- - -

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

* `size` -
(Optional)
The total number of nodes in the node group. One of `initial_size` or `size` must be specified.

* `initial_size` -
(Optional)
The initial number of nodes in the node group. One of `initial_size` or `size` must be specified.

* `maintenance_policy` -
(Optional)
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.
Expand Down