Skip to content

Add lock checks in delete functions of disk and config resources#2237

Open
zliang-akamai wants to merge 5 commits intolinode:devfrom
zliang-akamai:zhiwei/instance-disk-config-check-lock-before-deletion
Open

Add lock checks in delete functions of disk and config resources#2237
zliang-akamai wants to merge 5 commits intolinode:devfrom
zliang-akamai:zhiwei/instance-disk-config-check-lock-before-deletion

Conversation

@zliang-akamai
Copy link
Member

@zliang-akamai zliang-akamai commented Jan 23, 2026

📝 Description

Add checks for disks and config to prevent a locked Linode from being in an undesired state (shutdown) during deletion attempts

✔️ How to Test

Replace all tofu commands with terraform if you are using Terraform rather than OpenTofu

Applying Config with Instance, Disk, Config, and Lock

tofu apply --auto-approve

With the following TF config:

provider "linode" {}

resource "linode_instance_config" "my-config" {
  linode_id = linode_instance.my-instance.id
  label = "my-config"

  device {
    device_name = "sda"
    disk_id = linode_instance_disk.boot.id
  }
  booted = true
}

resource "linode_instance_disk" "boot" {
  label = "boot"
  linode_id = linode_instance.my-instance.id
  size = linode_instance.my-instance.specs.0.disk

  image = "linode/debian13"
  root_pass = "change-me-to-a-secure-password!!"
}

resource "linode_instance" "my-instance" {
  label = "my-instance"
  type = "g6-standard-1"
  region = "us-central"
  firewall_id = 12345 // change to your firewall
}

resource "linode_lock" "my-lock" {
  entity_id   = linode_instance.my-instance.id
  entity_type = "linode"
  lock_type   = "cannot_delete_with_subresources"
}

Remove the Lock from TF State and Config

This is necessary to test how TF reacts when attempting to delete a Linode config/disk locked by an external lock not managed by the TF.

Removing Lock from State

tofu state rm linode_lock.my-lock

Removing Lock in TF Config

provider "linode" {}

resource "linode_instance_config" "my-config" {
  linode_id = linode_instance.my-instance.id
  label = "my-config"

  device {
    device_name = "sda"
    disk_id = linode_instance_disk.boot.id
  }
  booted = true
}

resource "linode_instance_disk" "boot" {
  label = "boot"
  linode_id = linode_instance.my-instance.id
  size = linode_instance.my-instance.specs.0.disk

  image = "linode/debian13"
  root_pass = "change-me-to-a-secure-password!!"
}

resource "linode_instance" "my-instance" {
  label = "my-instance"
  type = "g6-standard-1"
  region = "us-central"
  firewall_id = 1629606
}

// The lock has been removed here

Check plan to ensure plan is empty

tofu plan

Attempt Deletion

tofu destroy --auto-approve

Verify an error similar to this appears:

╷
│ Error: can't delete config 93998593 in Linode 90484452: the resource lock on the Linode prohibits deletion of its subresources, which includes this config
│ 
│ 
╵

Also check cloud manager and verify the Linode is still in running state and wasn't powered off or shutting down

… in an undesired state (shutdown) during deletion attempts
@zliang-akamai zliang-akamai requested a review from a team as a code owner January 23, 2026 23:06
@zliang-akamai zliang-akamai requested review from psnoch-akamai and vshanthe and removed request for a team January 23, 2026 23:06
@vshanthe vshanthe requested a review from Copilot January 27, 2026 07:48
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 PR adds lock validation to prevent deletion of disks and configs when their parent Linode instance has a cannot_delete_with_subresources lock. The changes ensure that locked Linodes remain in their current state and prevent unintended shutdowns during deletion attempts.

Changes:

  • Added lock checks in disk and config deletion workflows to validate against cannot_delete_with_subresources lock type
  • Introduced a helper function to check if a Linode has the cannot_delete_with_subresources lock
  • Added clear error messages when deletion is blocked due to resource locks

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
linode/instancedisk/framework_resource.go Added lock validation before disk deletion to prevent deletion when parent Linode is locked
linode/instanceconfig/resource.go Added lock validation before config deletion to prevent deletion when parent Linode is locked
linode/helper/instance.go Introduced helper function to check for cannot_delete_with_subresources lock on Linode instances

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

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@vshanthe vshanthe requested a review from Copilot January 30, 2026 08:44
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

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.


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

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@zliang-akamai zliang-akamai added the bugfix for any bug fixes in the changelog. label Jan 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix for any bug fixes in the changelog.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant