terraform-provider-google icon indicating copy to clipboard operation
terraform-provider-google copied to clipboard

Altering Snapshot Schedule should edit, NOT destroy Snapshot schedule

Open JakeCooper opened this issue 1 year ago • 3 comments

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 avatar Apr 17 '24 02:04 JakeCooper

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

ggtisc avatar Apr 17 '24 22:04 ggtisc

Sounds good! Apologies if I added the wrong label

Enhancement makes sense given my understanding of the terraform state machine

JakeCooper avatar Apr 18 '24 00:04 JakeCooper

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 avatar Jun 28 '24 17:06 JakeCooper

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

JakeCooper avatar Jul 02 '24 17:07 JakeCooper

This should be resolved with https://github.com/GoogleCloudPlatform/magic-modules/pull/11091

harshulsoni avatar Jul 08 '24 23:07 harshulsoni