Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Error: no schema available for snowflake_function.money_to_decimal while reading state; this is a bug in Terraform and should be reported" #3295

Open
1 task
liamjamesfoley opened this issue Dec 16, 2024 · 3 comments
Assignees
Labels
category:migration Issues connected with migration to v1.0.0. general-usage General help/usage questions resource:function_sql

Comments

@liamjamesfoley
Copy link
Contributor

liamjamesfoley commented Dec 16, 2024

Terraform CLI Version

1.7.1

Terraform Provider Version

1.0.0

Company Name

No response

Terraform Configuration

Attempting to upgrade to v.1.0.0 and getting this error:

Error: no schema available for snowflake_function.parse_money while reading state; this is a bug in Terraform and should be reported

TF plan log:

Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  + create
-/+ destroy and then create replacement

Terraform planned the following actions, but then encountered a problem:

  # snowflake_function_sql.money_to_decimal will be created
  + resource "snowflake_function_sql" "money_to_decimal" {
      + comment               = "Converts the protobuf google.type.Money representations into a decimal.  Note that this drops the Currency component.  Emits NULL if neither units or nanos is supplied."
      + database              = "FINPLAT_DB"
      + enable_console_output = (known after apply)
      + fully_qualified_name  = (known after apply)
      + function_definition   = "IFF(MONEY:units IS NULL AND MONEY:nanos IS NULL, null, coalesce(MONEY:units::DECIMAL, 0) + (coalesce(money:nanos::DECIMAL, 0) * 1e-09))"
      + function_language     = (known after apply)
      + id                    = (known after apply)
      + is_secure             = "default"
      + log_level             = (known after apply)
      + metric_level          = (known after apply)
      + name                  = "MONEY_TO_DECIMAL"
      + parameters            = (known after apply)
      + return_type           = "NUMBER(38,9)"
      + schema                = "PUBLIC"
      + show_output           = (known after apply)
      + trace_level           = (known after apply)

      + arguments {
          + arg_data_type = "VARIANT"
          + arg_name      = "MONEY"
        }
    }

  # snowflake_function_sql.parse_money will be created
  + resource "snowflake_function_sql" "parse_money" {
      + comment               = "Converts the protobuf google.type.Money representations into a decimal.  Note that this drops the Currency component.  Emits ZERO if null or missing units/nanos."
      + database              = "FINPLAT_DB"
      + enable_console_output = (known after apply)
      + fully_qualified_name  = (known after apply)
      + function_definition   = "IFF(MONEY:units IS NULL AND MONEY:nanos IS NULL, 0, coalesce(MONEY:units::DECIMAL, 0) + (coalesce(money:nanos::DECIMAL, 0) * 1e-09))"
      + function_language     = (known after apply)
      + id                    = (known after apply)
      + is_secure             = "default"
      + log_level             = (known after apply)
      + metric_level          = (known after apply)
      + name                  = "PARSE_MONEY"
      + parameters            = (known after apply)
      + return_type           = "NUMBER(38,9)"
      + schema                = "PUBLIC"
      + show_output           = (known after apply)
      + trace_level           = (known after apply)

      + arguments {
          + arg_data_type = "VARIANT"
          + arg_name      = "MONEY"
        }
    }

  # module.payday_latitude_and_longitude_policy.snowflake_masking_policy.masking_policy must be replaced
-/+ resource "snowflake_masking_policy" "masking_policy" {
      ~ describe_output       = [
          - {
              - body        = "case when current_role() in ('SYSADMIN','ACCOUNTADMIN', 'SNOWFLAKE_PROD_ACCOUNTADMIN_ROLE_OKTA', 'PAYDAY_ROLE','GLUE_ETL_EDW_ROLE') then val else null end"
              - name        = "PAYDAY_LATITUDE_AND_LONGITUDE_MASKING"
              - return_type = "NUMBER"
              - signature   = [
                  - {
                      - name = "VAL"
                      - type = "NUMBER"
                    },
                ]
            },
        ] -> (known after apply)
      ~ fully_qualified_name  = "\"OPERATION_DB\".\"SECURITY\".\"PAYDAY_LATITUDE_AND_LONGITUDE_MASKING\"" -> (known after apply)
      ~ id                    = "\"OPERATION_DB\".\"SECURITY\".\"PAYDAY_LATITUDE_AND_LONGITUDE_MASKING\"" -> (known after apply)
        name                  = "PAYDAY_LATITUDE_AND_LONGITUDE_MASKING"
      ~ return_data_type      = "NUMBER" -> "NUMBER(10,6)" # forces replacement
      ~ show_output           = [
          - {
              - comment               = "Managed by Terraform"
              - created_on            = "2024-12-16 13:39:36.885 +0000 UTC"
              - database_name         = "OPERATION_DB"
              - exempt_other_policies = false
              - kind                  = "MASKING_POLICY"
              - name                  = "PAYDAY_LATITUDE_AND_LONGITUDE_MASKING"
              - owner                 = "TERRAFORM_ROLE"
              - owner_role_type       = "ROLE"
              - schema_name           = "SECURITY"
            },
        ] -> (known after apply)
        # (5 unchanged attributes hidden)

      ~ argument {
            name = "VAL"
          ~ type = "NUMBER" -> "NUMBER(10,6)" # forces replacement
        }
    }

Plan: 3 to add, 0 to change, 1 to destroy.
╷
│ Error: no schema available for snowflake_function.money_to_decimal while reading state; this is a bug in Terraform and should be reported
│ 
│ 
╵
╷
│ Error: no schema available for snowflake_function.parse_money while reading state; this is a bug in Terraform and should be reported
│ 
│ 
╵
╷
│ Error: snowflake_current_account_datasource is currently a preview feature, and must be enabled by adding snowflake_current_account_datasource to `preview_features_enabled` in Terraform configuration.
│ 
│   with data.snowflake_current_account.current,
│   on main.tf line 1, in data "snowflake_current_account" "current":
│    1: data "snowflake_current_account" "current" {}
│

Category

category:resource

Object type(s)

resource:function

Expected Behavior

No errors!

Actual Behavior

Errors!

Steps to Reproduce

upgrade from 0.100.0 -> 1.0.0 and change snowflake_function -> snowflake_function_sql for these two resources:

resource "snowflake_function_sql" "money_to_decimal" {
  name     = "MONEY_TO_DECIMAL"
  database = "FINPLAT_DB"
  schema   = "PUBLIC"
  arguments {
    arg_name      = "MONEY"
    arg_data_type = "VARIANT"
  }
  comment             = "Converts the protobuf google.type.Money representations into a decimal.  Note that this drops the Currency component.  Emits NULL if neither units or nanos is supplied."
  return_type         = "NUMBER(38,9)"
  function_definition = "IFF(MONEY:units IS NULL AND MONEY:nanos IS NULL, null, coalesce(MONEY:units::DECIMAL, 0) + (coalesce(money:nanos::DECIMAL, 0) * 1e-09))"
}

resource "snowflake_function_sql" "parse_money" {
  name     = "PARSE_MONEY"
  database = "FINPLAT_DB"
  schema   = "PUBLIC"
  arguments {
    arg_name      = "MONEY"
    arg_data_type = "VARIANT"
  }
  comment             = "Converts the protobuf google.type.Money representations into a decimal.  Note that this drops the Currency component.  Emits ZERO if null or missing units/nanos."
  return_type         = "NUMBER(38,9)"
  function_definition = "IFF(MONEY:units IS NULL AND MONEY:nanos IS NULL, 0, coalesce(MONEY:units::DECIMAL, 0) + (coalesce(money:nanos::DECIMAL, 0) * 1e-09))"
}

How much impact is this issue causing?

Low

Logs

No response

Additional Information

No response

Would you like to implement a fix?

  • Yeah, I'll take it 😎
@liamjamesfoley liamjamesfoley added the bug Used to mark issues with provider's incorrect behavior label Dec 16, 2024
@sfc-gh-jmichalak
Copy link
Collaborator

Hi @liamjamesfoley 👋

The resources must be migrated from using a version where they are available (v0.100.0 in this case). Unfortunately, in the Terraform SDK there is no simple way to migrate between different resource types. I suggest that:

  1. On v0.100.0, import with the function terraform import snowflake_function_sql.money_to_decimal 'FINPLAT_DB.PUBLIC.MONEY_TO_DECIMAL(variant)'
  2. Remove the old function from the config and from the state with the state rm command.
  3. Upgrade to v1.0.0

In general, please first migrate from deprecated resources (read our docs), and then upgrade to v1.0.0 where all of the deprecated resources are removed.

@liamjamesfoley
Copy link
Contributor Author

Hi @sfc-gh-jmichalak, yea fully understand that I can't migrate between resources and I plan to use import removed blocks, but I'm not sure I udnestand your comment here?

The resources must be migrated from using a version where they are available (v0.100.0 in this case)
I'm on v0.100 and trying to move to 1.0.

@sfc-gh-jmichalak
Copy link
Collaborator

It means that before upgrading to v1.0.0 you shouldn't have any deprecated snowflake_function resource in your state and config. Please first migrate from snowflake_function to snowflake_function_sql, make sure you don't have snowflake_function, and then upgrade to v1.0.0.

Based on the logs, you have upgraded to v1.0.0, but snowflake_function is still present in the state, which causes this error.

@sfc-gh-jmichalak sfc-gh-jmichalak self-assigned this Dec 17, 2024
@sfc-gh-asawicki sfc-gh-asawicki added category:migration Issues connected with migration to v1.0.0. general-usage General help/usage questions resource:function_sql and removed bug Used to mark issues with provider's incorrect behavior labels Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:migration Issues connected with migration to v1.0.0. general-usage General help/usage questions resource:function_sql
Projects
None yet
Development

No branches or pull requests

3 participants