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

Altering Snapshot Schedule should edit, NOT destroy Snapshot schedule #17880

Open
JakeCooper opened this issue Apr 17, 2024 · 5 comments
Open

Comments

@JakeCooper
Copy link

JakeCooper commented Apr 17, 2024

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 a user, that user is claiming responsibility for the issue.
  • Customers working with a Google Technical Account Manager or Customer Engineer can ask them to reach out internally to expedite investigation and resolution of this issue.

Terraform Version

1.8

Affected Resource(s)

google_compute_resource_policy

Terraform Configuration

resource "google_compute_resource_policy" "stacker_volumes_disk_backup" {
  name    = "${var.environment}-stacker-volumes-disk-backup-${var.region}"
  project = var.project
  region  = var.region
  snapshot_schedule_policy {
    schedule {
      hourly_schedule {
        hours_in_cycle = 2
        start_time     = "05:00"
      }
    }

    retention_policy {
      max_retention_days    = 3
      on_source_disk_delete = "APPLY_RETENTION_POLICY"
    }

    snapshot_properties {
      storage_locations = [var.region]
    }
  }
}

Debug Output

  # module.stacker_us-west1-b.google_compute_resource_policy.stacker_volumes_disk_backup must be replaced
-/+ resource "google_compute_resource_policy" "stacker_volumes_disk_backup" {
      ~ id        = "projects/railway-infra/regions/us-west1/resourcePolicies/production-stacker-volumes-disk-backup-us-west1" -> (known after apply)
        name      = "production-stacker-volumes-disk-backup-us-west1"
      ~ region    = "https://www.googleapis.com/compute/v1/projects/railway-infra/regions/us-west1" -> "us-west1"
      ~ self_link = "https://www.googleapis.com/compute/v1/projects/railway-infra/regions/us-west1/resourcePolicies/production-stacker-volumes-disk-backup-us-west1" -> (known after apply)
        # (1 unchanged attribute hidden)

      ~ snapshot_schedule_policy {
          ~ schedule {
              - daily_schedule { # forces replacement
                  - days_in_cycle = 1 -> null # forces replacement
                  - start_time    = "05:00" -> null # forces replacement
                }
              + hourly_schedule { # forces replacement
                  + hours_in_cycle = 2 # forces replacement
                  + start_time     = "05:00" # forces replacement
                }
            }
          ~ snapshot_properties {
              - guest_flush       = false -> null
              - labels            = {} -> null
                # (1 unchanged attribute hidden)
            }

            # (1 unchanged block hidden)
        }
    }

Expected Behavior

Since the Google Cloud UI allows you to edit snapshot schedules and change the timeframe (days, weeks, etc), it SHOULD edit the policy not destroy it

Actual Behavior

The policy is destroyed and recreated

Steps to reproduce

  1. terraform apply

Important Factoids

Normally this wouldn't be an issue, but, if you recreate a snapshot policy, it'll orphan any old snapshots created by it (NOT remove them)

Which means Google will keep around a range of snapshots for every lifecycle change that forces a replacement. Example: You change the policy 2x, it'll keep 3 "generations" of snapshots around (and charge you 3x for it)

This is a 200k bug for us at @railwayapp :/.

References

No response

b/335507340

@JakeCooper JakeCooper added the bug label Apr 17, 2024
@github-actions github-actions bot added forward/review In review; remove label to forward service/compute-instances labels Apr 17, 2024
@ggtisc ggtisc self-assigned this Apr 17, 2024
@ggtisc ggtisc added enhancement and removed bug labels Apr 17, 2024
@ggtisc ggtisc removed their assignment Apr 17, 2024
@ggtisc ggtisc removed the forward/review In review; remove label to forward label Apr 17, 2024
@ggtisc
Copy link
Collaborator

ggtisc commented Apr 17, 2024

This scenario was detected as a possible enhancement not as a bug, so it was forwarded to take in consideration for the future

@JakeCooper
Copy link
Author

Sounds good! Apologies if I added the wrong label

Enhancement makes sense given my understanding of the terraform state machine

@melinath melinath added this to the Goals milestone Apr 22, 2024
@JakeCooper
Copy link
Author

To clarify, this isn't an enhancement in relation to the provider itself.

Updating a snapshot policy in the console does not recreate it.

This is a bug in relation to Google's API and Product definition

@JakeCooper
Copy link
Author

JakeCooper commented Jul 2, 2024

According to the Google Cloud Docs, this behavior does not match the stated behavior for Google Cloud and is thus a bug, not an enhancement

image

https://cloud.google.com/compute/docs/disks/manage-snapshot-schedules#change_snapshot_schedule

@harshulsoni
Copy link

harshulsoni commented Jul 8, 2024

This should be resolved with GoogleCloudPlatform/magic-modules#11091

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants