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]: snowflake_task resource error_integration got unconvertible type 'sdk.AccountObjectIdentifier' #3136

Open FrelliBB opened 1 month ago

FrelliBB commented 1 month ago

Terraform CLI Version

1.9.6

Terraform Provider Version

0.97.0

Terraform Configuration

data "aws_caller_identity" "current" {}

resource "snowflake_task" "this" {
  name      = upper(var.name)
  comment   = var.comment
  database  = var.database
  schema    = var.schema
  warehouse = var.warehouse

  sql_statement        = var.sql_statement
  schedule             = var.schedule
  user_task_timeout_ms = var.user_task_timeout_ms

  enabled = var.enabled

  error_integration = "MARSHMALLOW_ERROR_NOTIFICATION_${data.aws_caller_identity.current.account_id}"

  lifecycle {
    ignore_changes = [
      session_parameters,
    ]
  }
}

variable "name" {
  type        = string
  description = "The identifier (i.e. name) for the task; must be unique for the schema in which the task is created"
}

variable "comment" {
  type        = string
  description = "Specifies a comment for the task"
  default     = ""
}

variable "schema" {
  type        = string
  description = "Name of the schema in which the task will reside"
}

variable "database" {
  type        = string
  description = "Name of the database in which the task will reside"
}

variable "warehouse" {
  type        = string
  description = "Specifies the virtual warehouse that is used to execute the task"
}

variable "sql_statement" {
  type        = string
  description = "Any single SQL statement, or a call to a stored procedure, executed when the task runs"
}

variable "schedule" {
  type        = string
  description = "Specifies the schedule for periodically running the task"
}

variable "user_task_timeout_ms" {
  type        = number
  description = "Specifies the time limit on a single run of the task before it times out (in milliseconds)"
  default     = 600000
}

variable "enabled" {
  type        = bool
  description = "Specifies if the task should be started (enabled) after creation or should remain suspended (default)"
  default     = true
}

Category

category:resource

Object type(s)

resource:task

Expected Behavior

Resource is created normally.

Actual Behavior

Terraform plan fails with.

│ Error: error_integration: '' expected type 'string', got unconvertible type 'sdk.AccountObjectIdentifier', value: '&{MARSHMALLOW_ERROR_NOTIFICATION_********}'
│ 
│   with module.module_name.snowflake_task.this,
│   on .terraform/modules/module_name/snowflake/modules/task/main.tf line 10, in resource "snowflake_task" "this":
│   10: resource "snowflake_task" "this" {

Steps to Reproduce

Use the configuration and run Terraform apply.

How much impact is this issue causing?

Medium

Logs

No response

Additional Information

It looks like it might be related to https://github.com/Snowflake-Labs/terraform-provider-snowflake/pull/3086/files#diff-cb7f0da2beafb1e661c9b5cfd7df2f625e57b4e8af1aa913257fa4901bfd9846R466. I checked the migration guide but didn't see anything about this change in it.

Would you like to implement a fix?

sfc-gh-jcieslak commented 1 month ago

Hey @FrelliBB 👋 I'm currently refactoring tasks, do you have any special characters (spaces, dots, quotes, parentheses, etc.) in the hidden value (here: ${data.aws_caller_identity.current.account_id})? It would help me test the tasks to track the error and test it with the previous / current implementation.

FrelliBB commented 1 month ago

Thanks for the quick reply. data.aws_caller_identity.current.account_id is an AWS account id so it's just a 12 digit number. Didn't share our actual value for security reasons but it would be something like 987654321000.

https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity.html#account_id

sfc-gh-jcieslak commented 1 month ago

Just confirmed that the error occurs in the "old" version and the current refactored version works. I'll try to see if there's any workaround for this in the older version (If I won't find it today, I'll check tomorrow).

sfc-gh-jcieslak commented 1 month ago

The following workarounds for now:

FrelliBB commented 1 month ago

We are happy to skip the upgrade 0.97.0 and wait for a correct fix. Would that be possible or would the fix be targeting GA and require a longer wait? For context we spotted this issue on automated dependabot upgrades from 0.96.0 to 0.97.0, so we can skip this version for now.

sfc-gh-jcieslak commented 1 month ago

Ok 👍 the fix should be a part of 0.98.0 or 0.99.0, but it will most likely come with additional changes (e.g. field renames, etc.) that have to be migrated. That's because the refactor of tasks is done as part of preparing GA objects for v1, and all the changes will be listed in the migration guide.

cyclonstep commented 3 weeks ago

Hello, I also have the same problem with @FrelliBB with the version 0.97.0. Thanks for this now I can understand why my imports are failing. Will wait for the refactor for the task 👍