Setting lifecycle { prevent_destroy = true } causes Terraform to reject any plan that would destroy that resource, with Instance cannot be destroyed. It does not exclude the resource and continue with the rest.
This makes it a guard rather than a filter. A terraform destroy of an environment containing one protected database fails entirely and destroys nothing, which is usually the point. But it also means an unrelated change that forces replacement of the protected resource blocks the whole apply until the flag is removed, and removing it requires a code change and review.
The flag's value must be a literal; it cannot reference a variable, because Terraform evaluates the lifecycle block before variables in some contexts. That restriction is documented and is why environment-conditional protection has to be expressed by different module inputs producing different resources rather than by a computed flag. Note also that prevent_destroy does not protect against destruction from outside Terraform, nor against a state removal followed by a destroy.