Skip to content

add support for enabling delete protection#268

Open
Curverneur wants to merge 6 commits intoapache:mainfrom
Curverneur:feature/add-resource-protection-support
Open

add support for enabling delete protection#268
Curverneur wants to merge 6 commits intoapache:mainfrom
Curverneur:feature/add-resource-protection-support

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.

Curverneur and others added 4 commits December 16, 2025 14:20
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@Curverneur
Copy link
Author

looks like some checks failed due to connection issues. could you check and trigger them again, please?

Copy link
Member

@vishesh92 vishesh92 left a comment

Choose a reason for hiding this comment

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

@Curverneur Thansk for the PR. It looks mostly good. Can you check the comments? It would be great if you can add some tests here as well.

@Curverneur
Copy link
Author

Hi @vishesh92, thanks for the feedback. Changes commited as requested. Does the test meet the requirements? Do you have any suggestions for changes?

@Curverneur
Copy link
Author

Hi @vishesh92, the deleteprotection parameter has been added to the api in version 4.20. Testing with older versions of cloudstack-simulator, e.g. 4.19.3, just won't configure deleteprotection for instances or disks and logs:

WARN  [c.c.a.d.ParamGenericValidationWorker] (qtp2068388745-328:ctx-e860b95a ctx-604302c4 ctx-94a7892a) (logid:8565d729) Received unknown parameters for command updateVirtualMachine. Unknown parameters : deleteprotection

Well, using ExpectError might not be the best approach as indicated in testing.go. Do you have any other ideas? How could I properly test this feature and ensure the test is successful? Had the idea to check the api version and skip the check if the version is older than 4.20, but still not sure where I could get it from.

	// ExpectError allows the construction of test cases that we expect to fail
	// with an error. The specified regexp must match against the error for the
	// test to pass.
	//
	// This functionality is only intended for provider-controlled error
	// messaging. While in certain scenarios this can also catch testing logic
	// error messages, those messages are not protected by compatibility
	// promises.
	ExpectError *regexp.Regexp

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.

3 participants