Skip to content

Commit

Permalink
Maintenance interval for sole-tenant node groups. (#9307) (#6561)
Browse files Browse the repository at this point in the history
[upstream:a67d6a338c538d6ee383540f734b748e72ce0c84]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Oct 24, 2023
1 parent ac46796 commit eb38747
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/9307.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
compute: added `maintenance_interval` field to `google_compute_node_group` resource (beta)
```
36 changes: 36 additions & 0 deletions google-beta/services/compute/resource_compute_node_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ than or equal to max-nodes. The default value is 0.`,
Optional: true,
Description: `The initial number of nodes in the node group. One of 'initial_size' or 'autoscaling_policy' must be configured on resource creation.`,
},
"maintenance_interval": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ValidateFunc: verify.ValidateEnum([]string{"AS_NEEDED", "RECURRENT", ""}),
Description: `Specifies the frequency of planned maintenance events. Set to one of the following:
- AS_NEEDED: Hosts are eligible to receive infrastructure and hypervisor updates as they become available.
- RECURRENT: Hosts receive planned infrastructure and hypervisor updates on a periodic basis, but not more frequently than every 28 days. This minimizes the number of planned maintenance operations on individual hosts and reduces the frequency of disruptions, both live migrations and terminations, on individual VMs. Possible values: ["AS_NEEDED", "RECURRENT"]`,
},
"maintenance_policy": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -255,6 +264,12 @@ func resourceComputeNodeGroupCreate(d *schema.ResourceData, meta interface{}) er
} else if v, ok := d.GetOkExists("share_settings"); !tpgresource.IsEmptyValue(reflect.ValueOf(shareSettingsProp)) && (ok || !reflect.DeepEqual(v, shareSettingsProp)) {
obj["shareSettings"] = shareSettingsProp
}
maintenanceIntervalProp, err := expandComputeNodeGroupMaintenanceInterval(d.Get("maintenance_interval"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("maintenance_interval"); !tpgresource.IsEmptyValue(reflect.ValueOf(maintenanceIntervalProp)) && (ok || !reflect.DeepEqual(v, maintenanceIntervalProp)) {
obj["maintenanceInterval"] = maintenanceIntervalProp
}
zoneProp, err := expandComputeNodeGroupZone(d.Get("zone"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -395,6 +410,9 @@ func resourceComputeNodeGroupRead(d *schema.ResourceData, meta interface{}) erro
if err := d.Set("share_settings", flattenComputeNodeGroupShareSettings(res["shareSettings"], d, config)); err != nil {
return fmt.Errorf("Error reading NodeGroup: %s", err)
}
if err := d.Set("maintenance_interval", flattenComputeNodeGroupMaintenanceInterval(res["maintenanceInterval"], d, config)); err != nil {
return fmt.Errorf("Error reading NodeGroup: %s", err)
}
if err := d.Set("zone", flattenComputeNodeGroupZone(res["zone"], d, config)); err != nil {
return fmt.Errorf("Error reading NodeGroup: %s", err)
}
Expand Down Expand Up @@ -457,6 +475,12 @@ func resourceComputeNodeGroupUpdate(d *schema.ResourceData, meta interface{}) er
} else if v, ok := d.GetOkExists("share_settings"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, shareSettingsProp)) {
obj["shareSettings"] = shareSettingsProp
}
maintenanceIntervalProp, err := expandComputeNodeGroupMaintenanceInterval(d.Get("maintenance_interval"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("maintenance_interval"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, maintenanceIntervalProp)) {
obj["maintenanceInterval"] = maintenanceIntervalProp
}
zoneProp, err := expandComputeNodeGroupZone(d.Get("zone"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -496,6 +520,10 @@ func resourceComputeNodeGroupUpdate(d *schema.ResourceData, meta interface{}) er
updateMask = append(updateMask, "shareSettings")
}

if d.HasChange("maintenance_interval") {
updateMask = append(updateMask, "maintenanceInterval")
}

if d.HasChange("zone") {
updateMask = append(updateMask, "zone")
}
Expand Down Expand Up @@ -811,6 +839,10 @@ func flattenComputeNodeGroupShareSettingsProjectMapProjectId(v interface{}, d *s
return v
}

func flattenComputeNodeGroupMaintenanceInterval(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenComputeNodeGroupZone(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return v
Expand Down Expand Up @@ -965,6 +997,10 @@ func expandComputeNodeGroupShareSettingsProjectMapProjectId(v interface{}, d tpg
return v, nil
}

func expandComputeNodeGroupMaintenanceInterval(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandComputeNodeGroupZone(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
f, err := tpgresource.ParseGlobalFieldValue("zones", v.(string), "project", d, config, true)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,54 @@ resource "google_compute_node_group" "nodes" {
`, context)
}

func TestAccComputeNodeGroup_nodeGroupMaintenanceIntervalExample(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
CheckDestroy: testAccCheckComputeNodeGroupDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeNodeGroup_nodeGroupMaintenanceIntervalExample(context),
},
{
ResourceName: "google_compute_node_group.nodes",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"node_template", "initial_size", "zone"},
},
},
})
}

func testAccComputeNodeGroup_nodeGroupMaintenanceIntervalExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_compute_node_template" "soletenant-tmpl" {
provider = google-beta
name = "tf-test-soletenant-tmpl%{random_suffix}"
region = "us-central1"
node_type = "c2-node-60-240"
}
resource "google_compute_node_group" "nodes" {
provider = google-beta
name = "tf-test-soletenant-group%{random_suffix}"
zone = "us-central1-a"
description = "example google_compute_node_group for Terraform Google Provider"
initial_size = 1
node_template = google_compute_node_template.soletenant-tmpl.id
maintenance_interval = "RECURRENT"
}
`, context)
}

func TestAccComputeNodeGroup_nodeGroupAutoscalingPolicyExample(t *testing.T) {
t.Parallel()

Expand Down
35 changes: 35 additions & 0 deletions website/docs/r/compute_node_group.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,34 @@ resource "google_compute_node_group" "nodes" {
node_template = google_compute_node_template.soletenant-tmpl.id
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=node_group_maintenance_interval&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## Example Usage - Node Group Maintenance Interval


```hcl
resource "google_compute_node_template" "soletenant-tmpl" {
provider = google-beta
name = "soletenant-tmpl"
region = "us-central1"
node_type = "c2-node-60-240"
}
resource "google_compute_node_group" "nodes" {
provider = google-beta
name = "soletenant-group"
zone = "us-central1-a"
description = "example google_compute_node_group for Terraform Google Provider"
initial_size = 1
node_template = google_compute_node_template.soletenant-tmpl.id
maintenance_interval = "RECURRENT"
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=node_group_autoscaling_policy&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
Expand Down Expand Up @@ -164,6 +192,13 @@ The following arguments are supported:
Share settings for the node group.
Structure is [documented below](#nested_share_settings).

* `maintenance_interval` -
(Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
Specifies the frequency of planned maintenance events. Set to one of the following:
- AS_NEEDED: Hosts are eligible to receive infrastructure and hypervisor updates as they become available.
- RECURRENT: Hosts receive planned infrastructure and hypervisor updates on a periodic basis, but not more frequently than every 28 days. This minimizes the number of planned maintenance operations on individual hosts and reduces the frequency of disruptions, both live migrations and terminations, on individual VMs.
Possible values are: `AS_NEEDED`, `RECURRENT`.

* `zone` -
(Optional)
Zone where this node group is located
Expand Down

0 comments on commit eb38747

Please sign in to comment.