IBM-Cloud / terraform-provider-ibm

https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs
Mozilla Public License 2.0
341 stars 669 forks source link

Add deletion_protection argument to database resource #5534

Closed andrei-pirciu closed 1 month ago

andrei-pirciu commented 3 months ago

Community Note

Description

At the moment, the only way to prevent terraform from destroying a database is to use the prevent destroy lifecycle. This has limitations because variables cannot be used inside the lifecycle block. A solution would be to include an argument that controls whether Terraform can destroy the database.

New or Affected Resource(s)

Potential Terraform Configuration

resource "ibm_database" "test_acc" {
  resource_group_id                    = data.ibm_resource_group.group.id
  name                                 = "<your_database_name>"
  service                              = "databases-for-postgresql"
  plan                                 = "standard"
  location                             = "eu-gb"

  deletion_protection = var.enable_deletion_protection  # <----
}

References

Google implementation example: deletion_protection - (Optional) Whether Terraform will be prevented from destroying the instance. When the field is set to true or unset in Terraform state, a terraform apply or terraform destroy that would delete the instance will fail. When the field is set to false, deleting the instance is allowed.

https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/version_5_upgrade#cluster-deletion-now-prevented-by-default-with-deletion_protection

AWS implementation example: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/db_instance#deletion_protection

dpittner commented 2 months ago

@andrei-pirciu can you take a look at the PR I proposed and comment on if it would address the scenario you have in mind?