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

0.86.0 - snowflake_external_function creation - Root resource was present, but now absent. #2528

Closed
flocknroll opened this issue Feb 20, 2024 · 7 comments · Fixed by #2513
Closed
Labels
bug Used to mark issues with provider's incorrect behavior

Comments

@flocknroll
Copy link

Terraform CLI and Provider Versions

  • Running Terraform in Docker: hashicorp/terraform:1.3.9
  • Snowflake-Labs/snowflake: 0.86.0

Terraform Configuration

resource "snowflake_external_function" "lambda_notifier" {
  name = "LAMBDA_NOTIFIER"
  database = var.database 
  schema   = var.schema_name
  arg {
    name = "SNS_NOTIF"
    type = "OBJECT"
  }
  return_type = "VARIANT"
  return_behavior = "VOLATILE"
  api_integration = var.devint_api_integration_name
  url_of_proxy_and_resource = "${var.devint_proxy_url_gw_sf}api/v1/trigger_json_processing"
}

Expected Behavior

The external function should be created and added to the state.

Worked with provider versions <= 0.85.0

Actual Behavior

Error at the end of the apply:

╷
│ Error: Provider produced inconsistent result after apply
│ 
│ When applying changes to
│ module.staging.snowflake_external_function.lambda_notifier,
│ provider "provider[\"registry.terraform.io/snowflake-labs/snowflake\"]"
│ produced an unexpected new value: Root resource was present, but now
│ absent.
│ 
│ This is a bug in the provider, which should be reported in the provider's
│ own issue tracker.
╵

The external function is actually created but not added to the state.

The next plan will mark the resource as to be created.

Steps to Reproduce

  1. terraform apply

How much impact is this issue causing?

Low

Logs

No response

Additional Information

Plan output was correct:

  + resource "snowflake_external_function" "lambda_notifier" {
      + api_integration           = "API_GW_INTEGRATION"
      + comment                   = "user-defined function"
      + compression               = "AUTO"
      + created_on                = (known after apply)
      + database                  = "SNOWFLAKE_FEATURE"
      + id                        = (known after apply)
      + name                      = "LAMBDA_NOTIFIER"
      + null_input_behavior       = "CALLED ON NULL INPUT"
      + return_behavior           = "VOLATILE"
      + return_null_allowed       = true
      + return_type               = "VARIANT"
      + schema                    = "STAGING"
      + url_of_proxy_and_resource = "https://***.execute-api.eu-west-1.amazonaws.com/devint/api/v1/trigger"
      + arg {
          + name = "SNS_NOTIF"
          + type = "OBJECT"
        }
    }
@flocknroll flocknroll added the bug Used to mark issues with provider's incorrect behavior label Feb 20, 2024
@sfc-gh-asawicki
Copy link
Collaborator

Hey @flocknroll. Thanks for reaching out to us.

We are not able to reproduce this behavior (#2531). We tried also running a similar config locally and it was successful too. Can you provide more logs (you can run terraform with TF_LOG=DEBUG flag)?

@flocknroll
Copy link
Author

flocknroll commented Feb 20, 2024

hello @sfc-gh-asawicki,

I tried extracting relevant information from the DEBUG logs, hope this is enough:

2024-02-20T15:41:45.941+0100 [WARN]  Provider "registry.terraform.io/snowflake-labs/snowflake" produced an invalid plan for module.staging.snowflake_external_function.lambda_notifier, but we are tolerating it because it is using the legacy plugin SDK.
    The following problems may be the cause of any confusing errors from downstream operations:
      - .comment: planned value cty.StringVal("user-defined function") for a non-computed attribute
      - .return_null_allowed: planned value cty.True for a non-computed attribute
      - .null_input_behavior: planned value cty.StringVal("CALLED ON NULL INPUT") for a non-computed attribute
      - .compression: planned value cty.StringVal("AUTO") for a non-computed attribute
2024-02-20T15:41:46.011+0100 [DEBUG] provider.terraform-provider-snowflake_v0.86.0: 2024/02/20 15:41:46 [DEBUG] sql-conn-exec: [query CREATE EXTERNAL FUNCTION "SNOWFLAKE_FEATURE"."STAGING"."LAMBDA_NOTIFIER" (SNS_NOTIF OBJECT) RETURNS VARIANT NULL CALLED ON NULL INPUT VOLATILE COMMENT = 'user-defined function' API_INTEGRATION = "API_GW_INTEGRATION" COMPRESSION = AUTO AS 'https://***.execute-api.eu-west-1.amazonaws.com/devint/api/v1/trigger' err <nil> duration 70.689314ms args {}] ()
2024-02-20T15:41:46.671+0100 [DEBUG] provider.terraform-provider-snowflake_v0.86.0: 2024/02/20 15:41:46 [DEBUG] sql-conn-query: [query SHOW EXTERNAL FUNCTIONS LIKE 'LAMBDA_NOTIFIER' err <nil> duration 525.008526ms args {}] ()
2024-02-20T15:41:46.690+0100 [ERROR] vertex "module.staging.snowflake_external_function.lambda_notifier" error: Provider produced inconsistent result after apply

Please note that I deploy the same external function to multiple databases and multiple schemas. So the SHOW query will return multiple lines for the same function name. That may generate an inconsistency depending on how the provider handles the result.

@sfc-gh-asawicki
Copy link
Collaborator

Thanks @flocknroll. I will check the behavior with multiple functions named the same because this may be the source of inconsistency. I will get back to you with the results.

@sfc-gh-asawicki
Copy link
Collaborator

@flocknroll I have confirmed that the same name is the problem. The reason is how we handle read operations in the resource. Documentation https://docs.snowflake.com/en/sql-reference/sql/show-external-functions seems to be incorrect (no possibility to filter by db/schema, like e.g. https://docs.snowflake.com/en/sql-reference/sql/show-user-functions). It seems to be working, though (I checked manually). I have to confirm internally that this is the intended behavior, and if so, the fix will be straightforward.

@flocknroll
Copy link
Author

Indeed,

SHOW EXTERNAL FUNCTIONS LIKE 'LAMBDA_NOTIFIER' IN SCHEMA SNOWFLAKE_FEATURE.STAGING;

seems to work fine in my context.

To be more robust, filtering on the function signature may also be a good idea. But you would have to use the information schema FUNCTIONS view or filter the current SHOW command output in the code.

sfc-gh-asawicki added a commit that referenced this issue Feb 26, 2024
- Fix show by id for external functions.
- Correction to the documentation
(https://docs.snowflake.com/en/sql-reference/sql/show-external-functions#syntax)
requested internally.

References: #2528
sfc-gh-jcieslak pushed a commit that referenced this issue Feb 28, 2024
🤖 I have created a release *beep* *boop*
---


##
[0.87.0](v0.86.0...v0.87.0)
(2024-02-28)


### 🎉 **What's new:**

* Add network rule to the sdk
([#2526](#2526))
([b379565](b379565))
* supports collation of table column
([#2496](#2496))
([56771f1](56771f1))


### 🔧 **Misc**

* Clean up environment variables in tests and on CI
([#2543](#2543))
([9a10cb1](9a10cb1))
* replace warning in new grant resources with info log
([#2521](#2521))
([c3014b9](c3014b9))


### 🐛 **Bug fixes:**

* data retention days follow up
([#2566](#2566))
([7aba384](7aba384))
* data retention time parameters
([#2502](#2502))
([76abf21](76abf21))
* data retention time parameters follow-up
([#2530](#2530))
([5544544](5544544))
* Demote warning to info and set volatility for procedures and functions
([#2567](#2567))
([abaad7c](abaad7c)),
closes
[#2536](#2536)
* Fix ACCOUNT PARAMETERS option failover group resource
([#2522](#2522))
([61883f3](61883f3)),
closes
[#2517](#2517)
* Fix failover group alter syntax and suppression for pipe statement
([#2562](#2562))
([24d76c3](24d76c3))
* Fix few tests
([#2515](#2515))
([a523a6b](a523a6b))
* Fix provider config hierarchy
([#2551](#2551))
([677a12b](677a12b))
* Fix query_results in unsafe_execute resource
([#2512](#2512))
([94ca158](94ca158)),
closes
[#2491](#2491)
* Fix replication for database resource
([#2524](#2524))
([767fbce](767fbce)),
closes
[#2021](#2021)
* Fix show by id for external functions
([#2531](#2531))
([d910a84](d910a84)),
closes
[#2528](#2528)
* Fix various small problems
([#2552](#2552))
([f558ce6](f558ce6))
* Granting database roles
([#2511](#2511))
([dc27d64](dc27d64)),
closes
[#2402](#2402)
* grants on external volumes
([#2538](#2538))
([1de9a29](1de9a29))
* Handle old reference for table_id in table constraint resource
([#2558](#2558))
([d1e8912](d1e8912)),
closes
[#2535](#2535)
* loosen identifier field validation for account object identifiers
([#2564](#2564))
([a5ed8cd](a5ed8cd))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: snowflake-release-please[bot] <105954990+snowflake-release-please[bot]@users.noreply.github.com>
@sfc-gh-asawicki
Copy link
Collaborator

Hey @flocknroll. We have released the fix as part of v0.87.0 release. Please follow the migration guide during the update. Please confirm that the issue is resolved in the newest version. Thanks!

@flocknroll
Copy link
Author

hi @sfc-gh-asawicki, works fine now, thanks for your reactivity!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Used to mark issues with provider's incorrect behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants