shebang-labs / terraform-provider-postmark

Terraform Provider for postmark
https://postmarkapp.com/
MIT License
13 stars 3 forks source link

Crash when applying server creation #3

Closed phillipuniverse closed 1 year ago

phillipuniverse commented 1 year ago

When applying a plan with this terraform:

variable "postmark_account_token" {
  description = "Account token for Postmark"
}

provider "postmark" {
  account_token = var.postmark_account_token
}

resource "postmark_server" "someserver" {
  name = "someserver-${var.environment}"
}

I get this:

+ terraform apply -input=false dev.tfplan
[0mpostmark_server.someserver: Creating...
[31m╷
[31m│ Error: Plugin did not respond
[31m│ 
[31m│   with postmark_server.someserver,
[31m│   on postmark.tf line 10, in resource "postmark_server" "someserver":
[31m│   10: resource "postmark_server" "someserver" {
[31m│ 
[31m│ The plugin encountered an error, and failed to respond to the
[31m│ plugin.(*GRPCProvider).ApplyResourceChange call. The plugin logs may
[31m│ contain more details.
[31m╵

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

panic: interface conversion: interface {} is nil, not string

goroutine 87 [running]:
terraform-provider-postmark/postmark.resourceServerCreate({0xd40e20?, 0xc0004723c0?}, 0x0?, {0xc094a0?, 0xc00022df80})
    terraform-provider-postmark/postmark/resource_server.go:86 +0xc86
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0xc0000e88c0, {0xd40e20, 0xc0004723c0}, 0xd?, {0xc094a0, 0xc00022df80})
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.23.0/helper/schema/resource.go:707 +0x12e
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc0000e88c0, {0xd40e20, 0xc0004723c0}, 0xc0000a6410, 0xc000468e00, {0xc094a0, 0xc00022df80})
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.23.0/helper/schema/resource.go:837 +0xa85
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc0003ffd70, {0xd40e20?, 0xc0004722a0?}, 0xc0002aaff0)
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.23.0/helper/schema/grpc_provider.go:1021 +0xe8d
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0xc000224960, {0xd40e20?, 0xc000323320?}, 0xc00018a2a0)
    github.com/hashicorp/terraform-plugin-go@v0.14.0/tfprotov5/tf5server/server.go:818 +0x574
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0xbedc20?, 0xc000224960}, {0xd40e20, 0xc000323320}, 0xc00018a230, 0x0)
    github.com/hashicorp/terraform-plugin-go@v0.14.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:385 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc00022e1e0, {0xd448e0, 0xc000102d00}, 0xc00046b7a0, 0xc000323fb0, 0x11c28c0, 0x0)
    google.golang.org/grpc@v1.48.0/server.go:1295 +0xb2b
google.golang.org/grpc.(*Server).handleStream(0xc00022e1e0, {0xd448e0, 0xc000102d00}, 0xc00046b7a0, 0x0)
    google.golang.org/grpc@v1.48.0/server.go:1636 +0xa2f
google.golang.org/grpc.(*Server).serveStreams.func1.2()
    google.golang.org/grpc@v1.48.0/server.go:932 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
    google.golang.org/grpc@v1.48.0/server.go:930 +0x28a

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

Same result with Terraform 1.1.5 and 1.3.9.

phillipuniverse commented 1 year ago

This appears to be a problem with attempting to retrieve the DeliveryType as implemented in 43e5b15371552acd3978b56ea247b5652f2d9b3c. If I try to add a delivery_type I get this on a terraform plan:

 Error: Unsupported argument
│
│   on postmark.tf line 13, in resource "postmark_server" "someserver":
│   13:   delivery_type = "live"
│
│ An argument named "delivery_type" is not expected here.

I suspect that 43e5b15371552acd3978b56ea247b5652f2d9b3c is incomplete and a delivery_type needs to be added to this schema:

https://github.com/shebang-labs/terraform-provider-postmark/blob/db02ababa834ba80720185fd66573dfb27abc1fd/postmark/resource_server.go#L23-L48

phillipuniverse commented 1 year ago

Reverted back to 0.2.1 and that allowed me to apply the plan.

MuhammeedAlaa commented 1 year ago

@phillipuniverse Thank you for reporting the issue, we will look into it

MuhammeedAlaa commented 1 year ago

@phillipuniverse fixed in version 0.2.4

phillipuniverse commented 1 year ago

@MuhammeedAlaa thanks for the quick response!! Confirmed this now applies successfully with 0.2.4, fixed by 0fec098c58e4f4555b20a993189c2ceba62ec2de.

resource "postmark_server" "someserver" {
  name  = "someserver-${var.environment}"
  delivery_type = var.environment == "prod" ? "live" : "Sandbox"
}