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

Resource monitor creation fails, yet objects are created. #1754

Closed
rasmus-kristensen opened this issue Apr 25, 2023 · 6 comments
Closed

Resource monitor creation fails, yet objects are created. #1754

rasmus-kristensen opened this issue Apr 25, 2023 · 6 comments
Assignees
Labels
bug Used to mark issues with provider's incorrect behavior category:resource resource:resource_monitor Issue connected to the snowflake_resource_monitor resource

Comments

@rasmus-kristensen
Copy link

Provider Version
0.62.0

Terraform Version

1.4.5

Describe the bug

When attempting to create new resource monitor in snowflake the "terraform init" runs successfully and as expected however the apply fails, yet the objects are still created in snowflake.
When attempting to terraform apply again it now complains that the objects already exists and are not found in the state.

image

│ Error: Plugin did not respond
│ 
│   with module.snowflake_monitor["MRCH"].snowflake_resource_monitor.monitor,
│   on resource-monitor/main.tf line 17, in resource "snowflake_resource_monitor" "monitor":
│   17: resource "snowflake_resource_monitor" "monitor" {
│ 
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ReadResource call. The plugin logs may contain more
│ details.
╵

Stack trace from the terraform-provider-snowflake_v0.62.0 plugin:

panic: runtime error: index out of range [0] with length 0

goroutine 37 [running]:
github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/resources.ReadResourceMonitor(0x140008b6380, {0x102069960?, 0x140008b8b60})
        github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/resources/resource_monitor.go:322 +0x9cc
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).read(0x102094140?, {0x102094140?, 0x1400084f560?}, 0xd?, {0x102069960?, 0x140008b8b60?})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.26.1/helper/schema/resource.go:712 +0x134
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).RefreshWithoutUpgrade(0x140005bb880, {0x102094140, 0x1400084f560}, 0x140009e6410, {0x102069960, 0x140008b8b60})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.26.1/helper/schema/resource.go:1015 +0x468
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ReadResource(0x1400078eb40, {0x102094140?, 0x1400084f440?}, 0x140004aa340)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.26.1/helper/schema/grpc_provider.go:613 +0x400
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ReadResource(0x140001b10e0, {0x102094140?, 0x1400084ec90?}, 0x1400067e4e0)
        github.com/hashicorp/terraform-plugin-go@v0.14.3/tfprotov5/tf5server/server.go:748 +0x3e8
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ReadResource_Handler({0x102030900?, 0x140001b10e0}, {0x102094140, 0x1400084ec90}, 0x14000162000, 0x0)
        github.com/hashicorp/terraform-plugin-go@v0.14.3/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:349 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0x140007b2000, {0x10209a580, 0x14000502340}, 0x14000c98fc0, 0x140007ba990, 0x1029158d0, 0x0)
        google.golang.org/grpc@v1.53.0/server.go:1336 +0xb7c
google.golang.org/grpc.(*Server).handleStream(0x140007b2000, {0x10209a580, 0x14000502340}, 0x14000c98fc0, 0x0)
        google.golang.org/grpc@v1.53.0/server.go:1704 +0x82c
google.golang.org/grpc.(*Server).serveStreams.func1.2()
        google.golang.org/grpc@v1.53.0/server.go:965 +0x84
created by google.golang.org/grpc.(*Server).serveStreams.func1
        google.golang.org/grpc@v1.53.0/server.go:963 +0x290

Error: The terraform-provider-snowflake_v0.62.0 plugin crashed!

This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.

Expected behavior
terraform apply should not fails as it does actually create the objects, in version 0.61.0 this is not an issue.

Code samples and commands

resource "time_offset" "next_month" {
  offset_months = 1
}

resource "snowflake_resource_monitor" "monitor" {
  name                    = "MRCH_MONITOR"
  credit_quota            = 100
  frequency               = "MONTHLY"
  start_timestamp         = "${formatdate("YYYY-MM", time_offset.next_month.rfc3339)}-01 00:00:00"
  suspend_trigger         = 110
  warehouses              = values(merge(local.warehouses...))
}

Additional context

Add any other context about the problem here.

@rasmus-kristensen rasmus-kristensen added the bug Used to mark issues with provider's incorrect behavior label Apr 25, 2023
@tamathew
Copy link

tamathew commented May 2, 2023

I have yet another issue with resource monitor.

  • It always detects a change to datetime format and tries to apply it and when you apply it, it fails saying :
    "Must specify frequency and start time together"

Timestamp changes ->
start_timestamp :
"2023-05-03T00:00:00Z"
change to
"2023-05-03 00:00 PST"

@sfc-gh-jcieslak sfc-gh-jcieslak added category:resource resource:resource_monitor Issue connected to the snowflake_resource_monitor resource labels May 20, 2024
@sfc-gh-jcieslak
Copy link
Collaborator

Hey 👋
I'm currently working on the resource monitor as part of preparing GA objects for V1, so a lot may change, and the improvements are coming.
@rasmus-kristensen I'll investigate that error, but It seems like invalid identifier reading which is improved in the latest versions.
@tamathew You can read this thread - #1175 (comment)

@sfc-gh-jcieslak sfc-gh-jcieslak self-assigned this Sep 5, 2024
@rasmus-kristensen
Copy link
Author

@sfc-gh-jcieslak I've had this parked for a long time, now upon revisit it seems the previous error is no longer occurring, however it does in fact wish to change the monitor on each apply as it assumes the timestamp has been changed.

By specifying a resource such as the one below now creates without issues.

resource "snowflake_resource_monitor" "monitor" {
  name            = "MONITOR"
  credit_quota    = 100
  frequency       = "MONTHLY"
  start_timestamp = "${formatdate("YYYY-MM", time_offset.next_month.rfc3339)}-01 00:00 UTC"
  suspend_trigger = 110
  warehouses      = [module.dbdp_loader_xsmall_wh.name, module.dbdp_transformer_xsmall_wh.name, module.dbdp_analyst_xsmall_wh.name]
}

But upon next run it wants to change the timestamp format to 2024-10-01T02:00:00+02:00, if i specify the timestamp in that exact format it no longer triggers a change.

However the issue @tamathew mentions is still valid after the resource has been created with the "wrong" timestamp format.

Terraform will perform the following actions:

  # module.snowflake.snowflake_resource_monitor.monitor will be updated in-place
  ~ resource "snowflake_resource_monitor" "monitor" {
        id                        = "MONITOR"
        name                      = "MONITOR"
      ~ start_timestamp           = "2024-10-01T02:00:00+02:00" -> "2024-10-01T00:00:00+02:00"
        # (7 unchanged attributes hidden)
    }

Error: error updating resource monitor MONITOR 
must specify frequency and start time together

@sfc-gh-jcieslak
Copy link
Collaborator

Yeah, I've this a lot in other issues. I handled it and the timestamps shouldn't cause those issues anymore in the upcoming version. I'll also test it with this particular case, Thank You.

sfc-gh-jcieslak added a commit that referenced this issue Sep 11, 2024
## Changes
- Add ValuePresent assert to our custom assertions
- Add ToConfigValues function for every model
- Update Resource Monitor SDK + unit and integration tests
- Update Resource Monitor Resource + acc tests
- Handle issues connected to the resource monitor (mostly timestamp
format difference causing infinite plan or only trigger updates causing
SQL compilation error):
  -  #1500 
  - #1624 
  - #1716 
  - #1754 
  - #1821 
  - #1832 
  - #1990

## Next pr
- Adjust examples and update migration notes
- Data source (impl, tests, examples, migration notes)

## References
* [CREATE RESOURCE
MONITOR](https://docs.snowflake.com/en/sql-reference/sql/create-resource-monitor)
sfc-gh-fbudzynski pushed a commit that referenced this issue Sep 19, 2024
## Changes
- Add ValuePresent assert to our custom assertions
- Add ToConfigValues function for every model
- Update Resource Monitor SDK + unit and integration tests
- Update Resource Monitor Resource + acc tests
- Handle issues connected to the resource monitor (mostly timestamp
format difference causing infinite plan or only trigger updates causing
SQL compilation error):
  -  #1500 
  - #1624 
  - #1716 
  - #1754 
  - #1821 
  - #1832 
  - #1990

## Next pr
- Adjust examples and update migration notes
- Data source (impl, tests, examples, migration notes)

## References
* [CREATE RESOURCE
MONITOR](https://docs.snowflake.com/en/sql-reference/sql/create-resource-monitor)
@sfc-gh-jcieslak
Copy link
Collaborator

Hey 👋
The new and refactored resource monitor was released yesterday in version 0.96.0 of the provider. Please migrate with migration guide and let me know if the issue has been resolved so we could close the ticket. Thanks in advance 🙏.

@sfc-gh-jcieslak
Copy link
Collaborator

Closing due to long inactivity. Please, create another issue if you think the problem is still not resolved.

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 category:resource resource:resource_monitor Issue connected to the snowflake_resource_monitor resource
Projects
None yet
Development

No branches or pull requests

3 participants