hashicorp / terraform-provider-google

Terraform Provider for Google Cloud Platform
https://registry.terraform.io/providers/hashicorp/google/latest/docs
Mozilla Public License 2.0
2.29k stars 1.72k forks source link

boot_disk -> initialize_params block -> add resource_policies field #8963

Closed rkrv-capco closed 6 days ago

rkrv-capco commented 3 years ago

Community Note

Description

When a boot disk (persistent type) is created along with the VM instance, it is not possible to apply resource_policy(for example attaching snapshot_policy) to the disk resource.Currently, I have to manually configure the snapshot policy for the persistent boot disks on GCP.

Terraform Version

Terraform v0.14.8

New or Affected Resource(s)

google_compute_instance

Potential Terraform Configuration

resource "google_compute_instance" "db_server" {
  name           = "db-server"
  machine_type   = var.db_machine_type
  can_ip_forward = false
  boot_disk {
    initialize_params {
      image = var.db_image_name
      type  = var.db_disk_type  # pd-balanced
      size  = var.db_disk_size_gb
      **resource_policies = [google_compute_resource_policy.snapshot_policy.self_link]**
    }
  }
  network_interface {
    network    = google_compute_network.vpc.name
    subnetwork = google_compute_subnetwork.subnetwork.name
  }
}

References

https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_instance#initialize_params

b/359676042

osuarez84 commented 2 years ago

I am experiencing the same issue with the resource google_compute_instance_from_template and google_compute_instance_group_manager. It seems to be related to an issue with the API given back the name of the resourcePolicy instead of the complete id. This is the other issue talking about the same:

https://github.com/hashicorp/terraform-provider-google/issues/9260

Is there any workaround here to be able of attach the resource policies to the disks?

ggtisc commented 1 month ago

This is a proposal to add a new argument supported for the boot_disk to manage the resource policies

karolgorc commented 3 weeks ago

Working on a pr supporting disk resource policies on instance