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.36k stars 1.75k forks source link

Since provider 6.3.0 boot_disk.initialize_params.resource_policies is available and force rebuilt #19735

Open mldmld68 opened 1 month ago

mldmld68 commented 1 month ago

Community Note

We deployed since years a Cloud Function to automatically associate a snapshot schedule each time a GCE is started in our GCP organzation. Whatever the way : console or terraform. It appears the associated schedule is setup in the resource_policies field of the GCE.

With this new feature, all our GCE are planed to be rebuilt because our existing code do not manage it (normal, it was not availabled before) and the property is not empty on all our GCEs.

Terraform Version & Provider Version(s)

Terraform v1.7.2 on x86

Affected Resource(s)

google_compute_instance

Terraform Configuration

Debug Output

    # (8 unchanged attributes hidden)
  ~ boot_disk {
      ~ device_name                = "persistent-disk-0" -> (known after apply)
      + disk_encryption_key_sha256 = (known after apply)
 .....
          - resource_policies           = [ # forces replacement
              - "https://www.googleapis.com/compute/v1/projects/<projectID>/regions/europe-west1/resourcePolicies/<projectID>-europe-west1",
            ] -> null

Expected Behavior

The GCE should not be rebuilt with such parameter change. In particular for a snapshot schedule setting

Actual Behavior

The GCE are rebuilt

Steps to reproduce

  1. terraform apply

Important Factoids

We deployed since year a Cloud Function to automatically associate a snapshot schedule each time a GCE is started in our GCP organzation. Whatever the way : console, gcloud or terraform. It appears the associated schedule is setup in the resource_policies field of the GCE.

With this new feature, all our GCE are planed to be rebuilt because our existing code do not manage it (normal, it was not availabled before) and the property is not empty on all our GCEs.

References

No response

b/372018525

slevenick commented 1 month ago

I don't think there's anything we can do on the provider side here. This is just how Terraform works. As new fields are added to Terraform they are tracked by the resource, so Terraform will start to manage them.

You can add ignore_changes to prevent this for specific fields: lifecycle { ignore_changes = [boot_disk.initialize_params.resource_policies] }

mldmld68 commented 1 month ago

Yes, terraform start to manage them, but I would like the resource not being rebuilt for a change of this field

slevenick commented 1 month ago

Adding this as an enhancement rather than a bug then

SarahFrench commented 1 month ago

Closed by https://github.com/GoogleCloudPlatform/magic-modules/pull/11753

SarahFrench commented 1 month ago

Reopening as not wanting permadiff =/= not wanting a force new

SarahFrench commented 1 month ago

Note from triage: Initially we thought that it's valid to have initialize_params for boot_disk force resources to be recreated when they change, as the initialize params arguments control when a resource is first made. Changing those values implies wanting to recreate a resource using new inputs. However if these values are being impacted by using snapshots with the disk we'd like the service team to investigate further.