From e7ca3773f1dc344b073f0ae06700096da121a9f4 Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Wed, 5 May 2021 02:52:34 +0000 Subject: [PATCH] add initial_size to google_compute_node_group (#4750) Co-authored-by: Riley Karson Signed-off-by: Modular Magician --- .changelog/4750.txt | 3 ++ google/resource_compute_node_group.go | 32 +++++++++++++++---- ...ource_compute_node_group_generated_test.go | 6 ++-- .../docs/r/compute_node_group.html.markdown | 14 +++++--- 4 files changed, 40 insertions(+), 15 deletions(-) create mode 100644 .changelog/4750.txt diff --git a/.changelog/4750.txt b/.changelog/4750.txt new file mode 100644 index 00000000000..c9532fa6231 --- /dev/null +++ b/.changelog/4750.txt @@ -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` +``` diff --git a/google/resource_compute_node_group.go b/google/resource_compute_node_group.go index 81f3048c7b7..4e7e1430d16 100644 --- a/google/resource_compute_node_group.go +++ b/google/resource_compute_node_group.go @@ -18,6 +18,7 @@ import ( "fmt" "log" "reflect" + "regexp" "strconv" "time" @@ -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, @@ -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, @@ -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, @@ -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 } @@ -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) diff --git a/google/resource_compute_node_group_generated_test.go b/google/resource_compute_node_group_generated_test.go index c6e340de9ff..79b0a52c39e 100644 --- a/google/resource_compute_node_group_generated_test.go +++ b/google/resource_compute_node_group_generated_test.go @@ -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"}, }, }, }) @@ -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"}, }, }, }) @@ -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" diff --git a/website/docs/r/compute_node_group.html.markdown b/website/docs/r/compute_node_group.html.markdown index 10725ad5033..56f728d1316 100644 --- a/website/docs/r/compute_node_group.html.markdown +++ b/website/docs/r/compute_node_group.html.markdown @@ -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" @@ -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. - - - - @@ -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.