terraform-provider-snowflake icon indicating copy to clipboard operation
terraform-provider-snowflake copied to clipboard

DROP IF EXISTS support

Open funes79 opened this issue 3 years ago • 2 comments

Is your feature request related to a problem? Please describe.

I would like to run separate states where one state I would like to have databases and in the other schemas related to that db. In this case the apply order is from DB to SCHEMA (so first databases are created and then schemas). But in case of destroy the order should be reversed (so destroy schema and then db). I have my reason why to keep the two states separate, but the order of apply execution can be just one, so first DB and then SCHEMA. This works fine in case of adding or updating resources. However the destroy fails: the first apply drop the DB but the second apply against schemas tries to drop the schema, what does not exists.

Describe the solution you'd like

There are possibly multiple workaround for this, but of a nice feature would be to enable DROP IF EXISTS for resources, so that the terraform apply in the second stage will not fail if in the time of the resource removal the resource does not exists any more in Snowflake. Maybe a env variable or a resource flag, to ignore if not exists would be a nice solution.

Describe alternatives you've considered

I am also thinking about manually adjusting the state, but that looks more challenging.

Additional context

Add any other context or screenshots about the feature request here.

funes79 avatar Mar 26 '21 08:03 funes79

Old one, but I'd like to see this feature supported specifically for dropping a default schema generated when creating a database, like the PUBLIC schema

AndrewKlimovski avatar Feb 23 '24 05:02 AndrewKlimovski

Hey @funes79 👋 As we are currently working on https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/ROADMAP.md#preparing-essential-ga-objects-for-the-provider-v1 resources. The drop if exists will be applied to every refactored resource.

sfc-gh-jcieslak avatar Jun 07 '24 12:06 sfc-gh-jcieslak

Hey @funes79 👋 The new version (v0.93.0) contains refactored (and new) database resources that use DROP IF EXISTS when they're removed from the state. Closing the ticket as DROP IF EXSITS will be added in every newly refactored resource (refactored schema should be added most likely in the next release, so stay tuned). Thank You for your suggestions!

sfc-gh-jcieslak avatar Jul 11 '24 09:07 sfc-gh-jcieslak