Skip to content

Conversation

@Curverneur
Copy link

Description

Add support for enabling the delete protection for instances (virtual machines) and volumes (disks).

Reason

This feature allows users to enable the delete protection for certain resources to prevent accidental deletion.

References

Changes

Added deleteprotection option to cloudstack_instance and cloudstack_disk resource and updated the corresponding documentation pages.

  • modified cloudstack/resource_cloudstack_instance.go
  • modified cloudstack/resource_cloudstack_disk.go
  • modified website/docs/r/instance.html.markdown
  • modified website/docs/r/disk.html.markdown

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds delete protection support for CloudStack instances (virtual machines) and volumes (disks) by introducing a new deleteprotection boolean field to both the cloudstack_instance and cloudstack_disk resources. The feature integrates with CloudStack's API updateVirtualMachine and updateVolume endpoints to enable protection against accidental deletion.

Key Changes:

  • Added deleteprotection optional boolean field to instance and disk resource schemas
  • Implemented delete protection setting via CloudStack update APIs after resource creation
  • Updated documentation for both resources with usage notes about limitations when resources are managed by other services

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
cloudstack/resource_cloudstack_instance.go Added deleteprotection schema field and implementation to set/update protection via UpdateVirtualMachine API
cloudstack/resource_cloudstack_disk.go Added deleteprotection schema field and implementation to set/update protection via UpdateVolume API
website/docs/r/instance.html.markdown Documented deleteprotection parameter with usage notes and reformatted userdata_id/userdata_details entries
website/docs/r/disk.html.markdown Documented deleteprotection parameter with usage notes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

// Set deleteprotection using UpdateVolume
if v, ok := d.GetOk("deleteprotection"); ok {
// p_update := cs.Volume.NewUpdateVolumeParams()
// p_update.SetDeleteprotection(v.(bool))
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented-out code should be removed. If this code is not needed, it should be deleted rather than left as a comment.

Suggested change
// p_update.SetDeleteprotection(v.(bool))

Copilot uses AI. Check for mistakes.
* `reattach_on_change` - (Optional) Determines whether or not to detach the disk volume
from the virtual machine on disk offering or size change.

* `deleteprotection` - (Optional) Set delete protection for the volume. If true, The volume will be protected from deletion.
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capitalization inconsistency: "The" should be lowercase as it continues from "If true,".

Suggested change
* `deleteprotection` - (Optional) Set delete protection for the volume. If true, The volume will be protected from deletion.
* `deleteprotection` - (Optional) Set delete protection for the volume. If true, the volume will be protected from deletion.

Copilot uses AI. Check for mistakes.

"deleteprotection": {
Type: schema.TypeBool,
Optional: true,
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deleteprotection field should be marked as Computed: true in addition to Optional: true. This allows Terraform to properly track the value when it's read back from the API, ensuring state synchronization and preventing unnecessary diffs.

Similar to the attach field (lines 47-51), update the schema to:

"deleteprotection": {
    Type:     schema.TypeBool,
    Optional: true,
    Computed: true,
},
Suggested change
Optional: true,
Optional: true,
Computed: true,

Copilot uses AI. Check for mistakes.

"deleteprotection": {
Type: schema.TypeBool,
Optional: true,
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deleteprotection field should be marked as Computed: true in addition to Optional: true. This allows Terraform to properly track the value when it's read back from the API, ensuring state synchronization and preventing unnecessary diffs.

Update the schema to:

"deleteprotection": {
    Type:     schema.TypeBool,
    Optional: true,
    Computed: true,
},
Suggested change
Optional: true,
Optional: true,
Computed: true,

Copilot uses AI. Check for mistakes.
// Set deleteprotection using UpdateVirtualMachine
if v, ok := d.GetOk("deleteprotection"); ok {
// p_update := cs.VirtualMachine.NewUpdateVirtualMachineParams(r.Id)
// p_update.SetDeleteprotection(v.(bool))
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented-out code should be removed. If this code is not needed, it should be deleted rather than left as a comment.

Suggested change
// p_update.SetDeleteprotection(v.(bool))

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant