wasfree / terraform-provider-uptrends

Terraform Uptrends provider
Mozilla Public License 2.0
4 stars 1 forks source link

500 server error on tf apply when request_headers are changed #69

Closed rknightion closed 1 year ago

rknightion commented 1 year ago

Terraform Version

Terraform v1.5.1 on darwin_arm64

Affected Resource(s)

Terraform Configuration Files


resource "uptrends_monitor_web" "resource_name" {
  name                     = var.web-name
  type                     = "Https"
  url                      = var.web-url
  notes                    = var.default-notes

  check_interval             = var.check-interval
  alert_on_load_time_limit_1 = true
  load_time_limit_1          = var.load-time-limit-1
  alert_on_load_time_limit_2 = true
  load_time_limit_2          = var.load-time-limit-2

  alert_on_min_bytes         = var.alert-on-min-bytes
  min_bytes                  = var.min-bytes

  #expected_http_status_code = 0

  user_agent                = var.user-agent
  auth_type                 = var.auth-type
  primary_checkpoints_only  = true

  match_pattern {
    pattern = var.match-pattern
    is_positive = true
  }

  selected_checkpoints {
    exclude_locations = ["Moscow", "Novosibirsk", "Saint Petersburg"]
  }

  request_headers {
    name  = var.header-name-1
    value = var.header-value-1
  }
  request_headers {
    name  = var.header-name-2
    value = var.header-value-2
  }
}

variable "web-name" {
    description = "Name of service"
}

variable "web-url" {
    description = "URL of service to be monitored"
}

variable "default-notes" {
  description = "Description to add to web monitor"
  default     = "Managed by Terraform"
}

variable "match-pattern" {
    description = "Phrase used when scanning site to verify availability(?)"
    default     = ""
}

variable "check-interval" {
    description = "Frequency (in minutes) to poll site"
    default     = "1"
}

variable "load-time-limit-1" {
    description = "Level 1 trigger alert time (in ms)"
    default     = "10000" #10 seconds
}

variable "load-time-limit-2" {
    description = "Level 2 trigger alert time (in ms)"
    default     = "25000" #10 seconds
}

variable "alert-on-min-bytes" {
    description = "Alert when data received is less than X bytes?"
    default     = "true" 
}

variable "min-bytes" {
    description = "How many bytes minimum should be returned?"
    default     = "1024" 
}

variable "user-agent" {
    description = "What browser user agent should be used?"
    default     = "chrome108" 
}

variable "auth-type" {
    description = "Authentication needed?"
    default     = "None" 
}

variable "header-name-1" {
  default = ""
}

variable "header-name-2" {
  default = ""
}

variable "header-value-1" {
  default = ""
}

variable "header-value-2" {
  default = ""
}

 web-name                   = "API"
 web-url                        = "https://masked"

Debug Output

https://gist.github.com/rknightion/4a7fee0b05ccbe4cfdd6c5131935cf86

Expected Behavior

It removed previously added request_headers

Actual Behavior

500 sever error

Steps to Reproduce

tf apply. Is happening across all our monitors

Important Factoids

The headers were added in a previous run without issue. It's only now trying to remove them again that the error is happening

rknightion commented 1 year ago

I think the headers was a red-herring. I've removed those manually in uptrends and now get

uptrends_monitor_web.resource_name: Modifying... [id=44e9e2a6-4826-415b-a13a-afd193cbc873]
2023-06-21T17:08:54.494+0100 [INFO]  Starting apply for uptrends_monitor_web.resource_name
2023-06-21T17:08:54.494+0100 [DEBUG] uptrends_monitor_web.resource_name: applying the planned Update change
2023-06-21T17:08:54.498+0100 [DEBUG] provider.terraform-provider-uptrends_v0.2.3: panic: interface conversion: interface {} is nil, not map[string]interface {}
2023-06-21T17:08:54.498+0100 [DEBUG] provider.terraform-provider-uptrends_v0.2.3:
2023-06-21T17:08:54.498+0100 [DEBUG] provider.terraform-provider-uptrends_v0.2.3: goroutine 73 [running]:
2023-06-21T17:08:54.498+0100 [DEBUG] provider.terraform-provider-uptrends_v0.2.3: github.com/wasfree/terraform-provider-uptrends/uptrends.expandRequestHeader(...)
2023-06-21T17:08:54.498+0100 [DEBUG] provider.terraform-provider-uptrends_v0.2.3:   github.com/wasfree/terraform-provider-uptrends/uptrends/util.go:118
2023-06-21T17:08:54.498+0100 [DEBUG] provider.terraform-provider-uptrends_v0.2.3: github.com/wasfree/terraform-provider-uptrends/uptrends.buildMonitorWebStruct(0x140005b0cf8?)
2023-06-21T17:08:54.498+0100 [DEBUG] provider.terraform-provider-uptrends_v0.2.3:   github.com/wasfree/terraform-provider-uptrends/uptrends/monitor_web_resource.go:277 +0xdd4
2023-06-21T17:08:54.498+0100 [DEBUG] provider.terraform-provider-uptrends_v0.2.3: github.com/wasfree/terraform-provider-uptrends/uptrends.monitorWebUpdate({0x100c3d028, 0x14000197da0}, 0x1400050cf00, {0x100abe7a0?, 0x14000526348?})
2023-06-21T17:08:54.498+0100 [DEBUG] provider.terraform-provider-uptrends_v0.2.3:   github.com/wasfree/terraform-provider-uptrends/uptrends/monitor_web_resource.go:212 +0x13c
2023-06-21T17:08:54.498+0100 [DEBUG] provider.terraform-provider-uptrends_v0.2.3: github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).update(0x140003d6620, {0x100c3d060, 0x14000245a70}, 0xd?, {0x100abe7a0, 0x14000526348})
2023-06-21T17:08:54.498+0100 [DEBUG] provider.terraform-provider-uptrends_v0.2.3:   github.com/hashicorp/terraform-plugin-sdk/v2@v2.24.1/helper/schema/resource.go:741 +0xe8
2023-06-21T17:08:54.498+0100 [DEBUG] provider.terraform-provider-uptrends_v0.2.3: github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0x140003d6620, {0x100c3d060, 0x14000245a70}, 0x1400047a8f0, 0x1400050cd80, {0x100abe7a0, 0x14000526348})
2023-06-21T17:08:54.498+0100 [DEBUG] provider.terraform-provider-uptrends_v0.2.3:   github.com/hashicorp/terraform-plugin-sdk/v2@v2.24.1/helper/schema/resource.go:847 +0x67c
2023-06-21T17:08:54.498+0100 [DEBUG] provider.terraform-provider-uptrends_v0.2.3: github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0x14000472bb8, {0x100c3d060?, 0x14000245950?}, 0x1400005a780)
2023-06-21T17:08:54.498+0100 [DEBUG] provider.terraform-provider-uptrends_v0.2.3:   github.com/hashicorp/terraform-plugin-sdk/v2@v2.24.1/helper/schema/grpc_provider.go:1021 +0xb70
2023-06-21T17:08:54.498+0100 [DEBUG] provider.terraform-provider-uptrends_v0.2.3: github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0x140001705a0, {0x100c3d060?, 0x140002443c0?}, 0x140000da070)
2023-06-21T17:08:54.498+0100 [DEBUG] provider.terraform-provider-uptrends_v0.2.3:   github.com/hashicorp/terraform-plugin-go@v0.14.2/tfprotov5/tf5server/server.go:818 +0x3b8
2023-06-21T17:08:54.498+0100 [DEBUG] provider.terraform-provider-uptrends_v0.2.3: github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x100bf8540?, 0x140001705a0}, {0x100c3d060, 0x140002443c0}, 0x140000da000, 0x0)
2023-06-21T17:08:54.498+0100 [DEBUG] provider.terraform-provider-uptrends_v0.2.3:   github.com/hashicorp/terraform-plugin-go@v0.14.2/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:385 +0x170
2023-06-21T17:08:54.498+0100 [DEBUG] provider.terraform-provider-uptrends_v0.2.3: google.golang.org/grpc.(*Server).processUnaryRPC(0x1400048a000, {0x100c40a80, 0x140004c0340}, 0x140001aa000, 0x14000484de0, 0x10119dee0, 0x0)
2023-06-21T17:08:54.498+0100 [DEBUG] provider.terraform-provider-uptrends_v0.2.3:   google.golang.org/grpc@v1.51.0/server.go:1340 +0xb7c
2023-06-21T17:08:54.498+0100 [DEBUG] provider.terraform-provider-uptrends_v0.2.3: google.golang.org/grpc.(*Server).handleStream(0x1400048a000, {0x100c40a80, 0x140004c0340}, 0x140001aa000, 0x0)
2023-06-21T17:08:54.498+0100 [DEBUG] provider.terraform-provider-uptrends_v0.2.3:   google.golang.org/grpc@v1.51.0/server.go:1713 +0x82c
2023-06-21T17:08:54.498+0100 [DEBUG] provider.terraform-provider-uptrends_v0.2.3: google.golang.org/grpc.(*Server).serveStreams.func1.2()
2023-06-21T17:08:54.498+0100 [DEBUG] provider.terraform-provider-uptrends_v0.2.3:   google.golang.org/grpc@v1.51.0/server.go:965 +0x84
2023-06-21T17:08:54.498+0100 [DEBUG] provider.terraform-provider-uptrends_v0.2.3: created by google.golang.org/grpc.(*Server).serveStreams.func1
2023-06-21T17:08:54.498+0100 [DEBUG] provider.terraform-provider-uptrends_v0.2.3:   google.golang.org/grpc@v1.51.0/server.go:963 +0x290
2023-06-21T17:08:54.499+0100 [DEBUG] provider: plugin process exited: path=.terraform/providers/registry.terraform.io/wasfree/uptrends/0.2.3/darwin_arm64/terraform-provider-uptrends_v0.2.3 pid=74214 error="exit status 2"
2023-06-21T17:08:54.499+0100 [ERROR] plugin.(*GRPCProvider).ApplyResourceChange: error="rpc error: code = Unavailable desc = error reading from server: EOF"
2023-06-21T17:08:54.499+0100 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = error reading from server: EOF"
2023-06-21T17:08:54.499+0100 [DEBUG] State storage *remote.State declined to persist a state snapshot
2023-06-21T17:08:54.499+0100 [ERROR] vertex "uptrends_monitor_web.resource_name" error: Plugin did not respond
2023-06-21T17:08:54.499+0100 [DEBUG] states/remote: state read serial is: 13; serial is: 13
2023-06-21T17:08:54.499+0100 [DEBUG] states/remote: state read lineage is: 1a3d8530-3e43-9b1d-9caf-76d4886516f6; lineage is: 1a3d8530-3e43-9b1d-9caf-76d4886516f6
╷
│ Error: Plugin did not respond
│
│   with uptrends_monitor_web.resource_name,
│   on web-monitor.tf line 1, in resource "uptrends_monitor_web" "resource_name":
│    1: resource "uptrends_monitor_web" "resource_name" {
│
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ApplyResourceChange call. The plugin logs may contain more details.
╵
2023-06-21T17:08:54.500+0100 [DEBUG] DELETE https://gitlab.devops.pulselive.io/api/v4/projects/10/terraform/state/atp-api/lock

Stack trace from the terraform-provider-uptrends_v0.2.3 plugin:

panic: interface conversion: interface {} is nil, not map[string]interface {}

goroutine 73 [running]:
github.com/wasfree/terraform-provider-uptrends/uptrends.expandRequestHeader(...)
    github.com/wasfree/terraform-provider-uptrends/uptrends/util.go:118
github.com/wasfree/terraform-provider-uptrends/uptrends.buildMonitorWebStruct(0x140005b0cf8?)
    github.com/wasfree/terraform-provider-uptrends/uptrends/monitor_web_resource.go:277 +0xdd4
github.com/wasfree/terraform-provider-uptrends/uptrends.monitorWebUpdate({0x100c3d028, 0x14000197da0}, 0x1400050cf00, {0x100abe7a0?, 0x14000526348?})
    github.com/wasfree/terraform-provider-uptrends/uptrends/monitor_web_resource.go:212 +0x13c
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).update(0x140003d6620, {0x100c3d060, 0x14000245a70}, 0xd?, {0x100abe7a0, 0x14000526348})
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.24.1/helper/schema/resource.go:741 +0xe8
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0x140003d6620, {0x100c3d060, 0x14000245a70}, 0x1400047a8f0, 0x1400050cd80, {0x100abe7a0, 0x14000526348})
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.24.1/helper/schema/resource.go:847 +0x67c
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0x14000472bb8, {0x100c3d060?, 0x14000245950?}, 0x1400005a780)
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.24.1/helper/schema/grpc_provider.go:1021 +0xb70
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0x140001705a0, {0x100c3d060?, 0x140002443c0?}, 0x140000da070)
    github.com/hashicorp/terraform-plugin-go@v0.14.2/tfprotov5/tf5server/server.go:818 +0x3b8
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x100bf8540?, 0x140001705a0}, {0x100c3d060, 0x140002443c0}, 0x140000da000, 0x0)
    github.com/hashicorp/terraform-plugin-go@v0.14.2/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:385 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0x1400048a000, {0x100c40a80, 0x140004c0340}, 0x140001aa000, 0x14000484de0, 0x10119dee0, 0x0)
    google.golang.org/grpc@v1.51.0/server.go:1340 +0xb7c
google.golang.org/grpc.(*Server).handleStream(0x1400048a000, {0x100c40a80, 0x140004c0340}, 0x140001aa000, 0x0)
    google.golang.org/grpc@v1.51.0/server.go:1713 +0x82c
google.golang.org/grpc.(*Server).serveStreams.func1.2()
    google.golang.org/grpc@v1.51.0/server.go:965 +0x84
created by google.golang.org/grpc.(*Server).serveStreams.func1
    google.golang.org/grpc@v1.51.0/server.go:963 +0x290

Error: The terraform-provider-uptrends_v0.2.3 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.

2023-06-21T17:08:54.653+0100 [DEBUG] provider: plugin exited
rknightion commented 1 year ago

Okay it was the headers. In my web-monitor.tf I had:

  request_headers {
    name  = var.header-name-1
    value = var.header-value-1
  }
  request_headers {
    name  = var.header-name-2
    value = var.header-value-2
  }

Which did successfully provision 2 sets of headers.

I'm assuming that while that worked for the create when it came to delete it threw a server side error and when I manually removed the headers from uptrends the provider started happening.

Removing that block seemed to fix it. If the docs could advise how to create multiple headers on a resource it would be much appreciated!

rknightion commented 1 year ago

Okay chatgpt sorted it for me. https://chat.openai.com/share/3fd24c1d-dabd-4a69-94d6-14ff79e692c0