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

disk_resource_policies - not working properly #440

Open
pawelrosada opened this issue Oct 21, 2024 · 0 comments
Open

disk_resource_policies - not working properly #440

pawelrosada opened this issue Oct 21, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@pawelrosada
Copy link

TL;DR

The issue occurs when attaching a snapshot resource policy to a disk in a VM instance template using Terraform. Although the configuration specifies the snapshot policy, the disks created from the template do not get the policy applied as expected.

Expected behavior

When updating the VM instance template, the disks should automatically attach the specified snapshot resource policy, so that snapshots are managed according to the policy.

Observed behavior

The disks are created but do not have the snapshot resource policy attached, even though it is specified in the configuration. When the template is copied, the disks are visible but lack the associated snapshot policy.

Terraform Configuration

module "vm_instance_template_db" {
  source     = "terraform-google-modules/vm/google//modules/instance_template"
  version    = "12.0.0"
  project_id = var.project
  region     = var.region

  disk_labels            = {}
  source_image_project   = "debian-cloud"
  source_image           = "debian-11"
  auto_delete            = false
  disk_type              = "pd-ssd"
  disk_size_gb           = 30
  network                = module.vpc.network_name
  subnetwork             = module.vpc.subnets_names[0]
  subnetwork_project     = var.project
  tags                   = ["db"]
  machine_type           = "e2-standard-4"
  name_prefix            = "db-${var.suffix}"
  disk_resource_policies = [google_compute_resource_policy.snapshot-policy.id]

  service_account = {
    email  = google_service_account.vm.email
    scopes = ["cloud-platform"]
  }

  access_config = [{
    nat_ip       = null
    network_tier = null
  }]

  depends_on = [module.vpc]
}

resource "google_compute_resource_policy" "snapshot-policy" {
  name    = "snapshot-policy"
  region  = var.region
  project = var.project
  snapshot_schedule_policy {
    schedule {
      hourly_schedule {
        hours_in_cycle = 4
        start_time     = "23:00"
      }
    }
    retention_policy {
      max_retention_days    = 7
      on_source_disk_delete = "KEEP_AUTO_SNAPSHOTS"
    }
    snapshot_properties {
      storage_locations = ["eu"]
      guest_flush       = true
    }
  }
}

Terraform Version

v1.9.8

Additional information

No response

@pawelrosada pawelrosada added the bug Something isn't working label Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant