Skip to content

Commit f475d7d

Browse files
Fix autofilling values in initialize_params.resource_policies causing instance to recreate (#12552) (#20764)
[upstream:78bb3b5df95ac87ff1e82ba4e12624eedd4f951e] Signed-off-by: Modular Magician <[email protected]>
1 parent 0394577 commit f475d7d

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

.changelog/12552.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
compute: Setting resource policies for `google_compute_instance` outside of terraform or using `google_compute_disk_resource_policy_attachment` will no longer affect the `boot_disk.initialize_params.resource_policies` field
3+
```

google/services/compute/resource_compute_instance.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3078,6 +3078,13 @@ func flattenBootDisk(d *schema.ResourceData, disk *compute.AttachedDisk, config
30783078
}
30793079

30803080
diskDetails, err := getDisk(disk.Source, d, config)
3081+
3082+
// Resource policies can get autofilled from the API and on this field and this will cause the instance to recreate
3083+
// This overrides any value set by the API not to cause a diff when the user didn't set this in their config.
3084+
if d.Get("boot_disk.0.initialize_params.0.resource_policies.0") == nil || d.Get("boot_disk.0.initialize_params.0.resource_policies") == nil {
3085+
diskDetails.ResourcePolicies = nil
3086+
}
3087+
30813088
if err != nil {
30823089
log.Printf("[WARN] Cannot retrieve boot disk details: %s", err)
30833090

website/docs/r/compute_instance.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ is desired, you will need to modify your state file manually using
305305

306306
* `resource_manager_tags` - (Optional) A tag is a key-value pair that can be attached to a Google Cloud resource. You can use tags to conditionally allow or deny policies based on whether a resource has a specific tag. This value is not returned by the API. In Terraform, this value cannot be updated and changing it will recreate the resource.
307307

308-
* `resource_policies` - (Optional) A list of self_links of resource policies to attach to the instance's boot disk. Modifying this list will cause the instance to recreate. Currently a max of 1 resource policy is supported.
308+
* `resource_policies` - (Optional) A list of self_links of resource policies to attach to the instance's boot disk. Modifying this list will cause the instance to recreate, so any external values are not set until the user specifies this field. Currently a max of 1 resource policy is supported.
309309

310310
* `provisioned_iops` - (Optional) Indicates how many IOPS to provision for the disk.
311311
This sets the number of I/O operations per second that the disk can handle.

0 commit comments

Comments
 (0)