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

Fix autofilling values in initialize_params.resource_policies causing instance to recreate #8959

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/12552.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
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
```
7 changes: 7 additions & 0 deletions google-beta/services/compute/resource_compute_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -3209,6 +3209,13 @@ func flattenBootDisk(d *schema.ResourceData, disk *compute.AttachedDisk, config
}

diskDetails, err := getDisk(disk.Source, d, config)

// Resource policies can get autofilled from the API and on this field and this will cause the instance to recreate
// This overrides any value set by the API not to cause a diff when the user didn't set this in their config.
if d.Get("boot_disk.0.initialize_params.0.resource_policies.0") == nil || d.Get("boot_disk.0.initialize_params.0.resource_policies") == nil {
diskDetails.ResourcePolicies = nil
}

if err != nil {
log.Printf("[WARN] Cannot retrieve boot disk details: %s", err)

Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/compute_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ is desired, you will need to modify your state file manually using

* `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.

* `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.
* `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.

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