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

Improper lifecycle of maintenance_interval in VM scheduling block #16345

Assignees
Labels
bug forward/review In review; remove label to forward service/compute-instances

Comments

@tpdownes
Copy link

tpdownes commented Oct 24, 2023

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request.
  • Please do not leave +1 or me too comments, they generate extra noise for issue followers and do not help prioritize the request.
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.
  • If an issue is assigned to the modular-magician user, it is either in the process of being autogenerated, or is planned to be autogenerated soon. If an issue is assigned to a user, that user is claiming responsibility for the issue. If an issue is assigned to hashibot, a community member has claimed the issue already.

Terraform Version

Terraform v1.5.6
on linux_amd64
+ provider registry.terraform.io/hashicorp/google-beta v5.3.0

Affected Resource(s)

  • google_compute_instance_template

Terraform Configuration Files

resource "google_compute_instance_template" "tpl" {
  provider                = google-beta
  name_prefix             = "${var.name_prefix}-"
  project                 = var.project_id
  machine_type            = var.machine_type

  disk {
    source_image = "https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-12-bookworm-v20231010"
    auto_delete  = true
    boot         = true
  }

  network_interface {
    network = "default"
  }

  scheduling {
    maintenance_interval = "PERIODIC"
  }
}

variable "project_id" {
  type        = string
  description = "The GCP project ID"
}

variable "name_prefix" {
  description = "Name prefix for the instance template"
  type        = string
  default     = "default-instance-template"
}

variable "machine_type" {
  description = "Machine type to create, e.g. n1-standard-1"
  type        = string
  default     = "n1-standard-1"
}

Expected Behavior

I apply the module above, supplying a project ID at the CLI. Then I comment out the scheduling block and re-apply. I expect that Terraform will plan the removal of maintenanceInterval field from the template, probably through destroy / create.

Actual Behavior

The Terraform plan is empty - i.e. it doesn't detect that I have removed the (non-default) setting of maintenance_interval. I can verify that the field is in the template through gcloud beta compute instance-templates describe ...:

  scheduling:
    automaticRestart: true
    maintenanceInterval: PERIODIC
    onHostMaintenance: MIGRATE
    preemptible: false
    provisioningModel: STANDARD

Steps to Reproduce

  1. terraform apply (supply project ID)
  2. Comment out scheduling block
  3. terraform apply (supply project ID)
  • it does nothing (leaving non-default maintenanceInterval in template)

Alternative test

  1. Start by removing the scheduling block and provision a template. That goes fine.
  2. Now add on_host_maintenance = "TERMINATE" to the scheduling block. This results in the appropriate replacement plan:
          ~ on_host_maintenance  = "MIGRATE" -> "TERMINATE" # forces replacement
  1. Now leave on_host_maintenance = "TERMINATE" in the block, and add maintenance_interval = "PERIODIC". It proposes an in-place replacement of the template, which cannot happen. The error looks like:
Terraform will perform the following actions:

  # google_compute_instance_template.tpl will be updated in-place
  ~ resource "google_compute_instance_template" "tpl" {
        id                   = "projects/toolkit-demo-zero-e913/global/instanceTemplates/default-instance-template-20231024145201766900000001"
        name                 = "default-instance-template-20231024145201766900000001"
        tags                 = []
        # (10 unchanged attributes hidden)

      ~ scheduling {
          + maintenance_interval = "PERIODIC"
            # (5 unchanged attributes hidden)
        }

        # (2 unchanged blocks hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.
google_compute_instance_template.tpl: Modifying... [id=projects/toolkit-demo-zero-e913/global/instanceTemplates/default-instance-template-20231024145201766900000001]
╷
│ Error: doesn't support update
│
│   with google_compute_instance_template.tpl,
│   on main.tf line 1, in resource "google_compute_instance_template" "tpl":
│    1: resource "google_compute_instance_template" "tpl" {
│
@tpdownes
Copy link
Author

@edwardmedia if not obvious, these are all google-beta features

@melinath
Copy link
Collaborator

It sounds like maintenance_interval is not expected to be updatable; in that case this is correctly a bug and would be resolved by setting ForceNew on the field.

The behavior of not seeing a diff when removing the scheduling block is likely due to it being Optional + Computed, which preserves values when a field is removed.

@tpdownes
Copy link
Author

tpdownes commented Oct 25, 2023

Yes, I believe instance templates do not support update for any of their properties.

https://cloud.google.com/compute/docs/reference/rest/beta/instanceTemplates

Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.