Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
If you are interested in working on this issue or have submitted a pull request, please leave a comment
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)
ibm_database
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.
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
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
0000