Snowflake-Labs / terraform-provider-snowflake

Terraform provider for managing Snowflake accounts
https://registry.terraform.io/providers/Snowflake-Labs/snowflake/latest
MIT License
552 stars 420 forks source link

[Bug]: Terraform import snowflake_function Error: object does not exist #3094

Closed mike-soukup-vividseats closed 1 month ago

mike-soukup-vividseats commented 2 months ago

Terraform CLI Version

1.5.7

Terraform Provider Version

0.95.0

Terraform Configuration

When I follow the docs https://registry.terraform.io/providers/Snowflake-Labs/snowflake/0.95.0/docs/resources/function#import
to import a snowflake_function resource, I get an error after the Import was prepared that the object does not exist. This doesn't help resolve the issue in anyway and I am stuck. 

resource "snowflake_function" "flatten_ga_params" {
  name     = "flatten_ga_params"
  provider = snowflake.sys_admin
  database = "LANDING"
  schema   = "GA"
  arguments {
    name = "E"
    type = "VARIANT"
  }
  comment     = "Function to flatten GA4 event params"
  return_type = "VARIANT"
  language    = "javascript"
  statement   = "function code here"
}

Import statement: terraform import snowflake_function.flatten_ga_params 'LANDING.GA.flatten_ga_params(variant)'

Category

category:import

Object type(s)

No response

Expected Behavior

I expect this resource to be imported into the statefile.

Actual Behavior

Import is prepared but Error: object does not exist is returned

Steps to Reproduce

Copy the configuration and run the import provided.

How much impact is this issue causing?

Medium

Logs

No response

Additional Information

No response

Would you like to implement a fix?

sfc-gh-jmichalak commented 2 months ago

Hi @mike-soukup-vividseats 👋

I can't reproduce this issue. Could you share logs with TF_LOG=DEBUG? Also, can you confirm in Snowsight that DESCRIBE FUNCTION "LANDING"."GA"."flatten_ga_params"(VARIANT) returns the function you want to import?

mike-soukup-vividseats commented 2 months ago

Hi @sfc-gh-jmichalak I can confirm that the function does exist in Snowflake. I validated the id from an old statefile to be this: "\"LANDING\".\"GA\".\"flatten_ga_params\"(VARIANT)"

But even this throws the same error when I try to import it. Due to some sensitive info, I do not wish to share the debug logs.

Can you give more context where this error message would come from? Can you validate the terraform import syntax is correct? image image

sfc-gh-jmichalak commented 2 months ago

I think that the name in Snowflake is upper case, but you try importing with lower case (flatten_ga_params). Please try importing with upper case. In Terraform case is sensitive.

mike-soukup-vividseats commented 2 months ago

Well, I was skeptical, but that worked!

terraform import 'snowflake_function.flatten_ga_params' "\"LANDING\".\"GA\".\"FLATTEN_GA_PARAMS\"(VARIANT)"

Capitalizing the function name led to a successful import!

sfc-gh-jmichalak commented 2 months ago

Cool, can we close this issue, then?

sfc-gh-jmichalak commented 1 month ago

Closing the issue due to inactivity.