fortinetdev / terraform-provider-fortiswitch

Mozilla Public License 2.0
0 stars 0 forks source link

False positive client errors managing `fortiswitch_systemdhcp_server` resources #2

Closed amilstead closed 6 months ago

amilstead commented 8 months ago

Describe the bug

Running terraform apply with a fortiswitch_systemdhcp_server (imported) succeeds but emits the following terraform failure on the first pass:

fortiswitch_systemdhcp_server.main: Modifying... [id=1]
╷
│ Error: Plugin did not respond
│ 
│   with fortiswitch_systemdhcp_server.main,
│   on example.tf line 26, in resource "fortiswitch_systemdhcp_server" "main":
│   26: resource "fortiswitch_systemdhcp_server" "main" {
│ 
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ApplyResourceChange call. The plugin logs may contain more details.
╵

Stack trace from the terraform-provider-fortiswitch_v1.1.1 plugin:

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

goroutine 67 [running]:
github.com/terraform-providers/terraform-provider-fortiswitch/fortiswitch.resourceSystemDhcpServerUpdate(0xc0001e9700, {0xe68fa0?, 0xc000122338})
    github.com/terraform-providers/terraform-provider-fortiswitch/fortiswitch/resource_systemdhcp_server.go:404 +0x2de
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).update(0x111cf00?, {0x111cf00?, 0xc000852060?}, 0xd?, {0xe68fa0?, 0xc000122338?})
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.29.0/helper/schema/resource.go:800 +0x178
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc000608620, {0x111cf00, 0xc000852060}, 0xc000ab0270, 0xc0001e9500, {0xe68fa0, 0xc000122338})
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.29.0/helper/schema/resource.go:919 +0x83a
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc00044a3a8, {0x111cf00?, 0xc00017df20?}, 0xc0000cbef0)
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.29.0/helper/schema/grpc_provider.go:1060 +0xe8d
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0xc0002e2000, {0x111cf00?, 0xc00017cea0?}, 0xc000a90380)
    github.com/hashicorp/terraform-plugin-go@v0.19.0/tfprotov5/tf5server/server.go:859 +0x574
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0xf6dbc0?, 0xc0002e2000}, {0x111cf00, 0xc00017cea0}, 0xc000a90310, 0x0)
    github.com/hashicorp/terraform-plugin-go@v0.19.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:467 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc000464000, {0x1120ac0, 0xc000007380}, 0xc0008d18c0, 0xc000450810, 0x16bce18, 0x0)
    google.golang.org/grpc@v1.57.0/server.go:1360 +0xe23
google.golang.org/grpc.(*Server).handleStream(0xc000464000, {0x1120ac0, 0xc000007380}, 0xc0008d18c0, 0x0)
    google.golang.org/grpc@v1.57.0/server.go:1737 +0xa2f
google.golang.org/grpc.(*Server).serveStreams.func1.1()
    google.golang.org/grpc@v1.57.0/server.go:982 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
    google.golang.org/grpc@v1.57.0/server.go:980 +0x18c

Error: The terraform-provider-fortiswitch_v1.1.1 plugin crashed!

To Reproduce

Create a simple configuration to manage a Fortiswitch DHCP server, such as:

provider "fortiswitch" {
  hostname = "hostname"
  username = "admin"
  password = "password"
}

resource "fortiswitch_systemdhcp_server" "main" {
  ...

  ip_range {
    id       = "1"
    end_ip   = "<end ip>"
    start_ip = "<start ip>"
  }
  ...
}

Import the resource with:

terraform import fortiswitch_systemdhcp_server.main <id>

Make any arbitrary edit to the resource that would produce an update that should be applied, then terraform apply.

Note that the first attempt to terraform apply will actually update the resource but the terraform CLI/client will panic due to an invalid type conversion error (in the "Describe the bug" section above). Successful resource update on the Switch side can be verified using Fortiswitch CLI or UI.

Next, run terraform apply (or terraform plan) once more. Observe there is no diff to apply.

Expected behavior

terraform apply works successfully on the first pass (without a plugin failure) when updating a fortiswitch_systemdhcp_server resource.

Versions

Additional context

FWIW, I think I have tracked this bug down to this line of the provider implementation. In terraform log output (TF_LOG=1) I see "mkey" exists in the response payload and appears to be a string representation of a simple integer.

MaxxLiu22 commented 8 months ago

Hi @amilstead ,

Thank you for raising this issue, I can reproduce it, it looks like something around block configuration, have reported it to the development team for fixing.

Thanks, Maxx

JieX19 commented 8 months ago

Hi @amilstead

Thanks for the detailed info! We've fixed the issue and it will be updated in the next release.

amilstead commented 8 months ago

Great news, thanks!

amilstead commented 7 months ago

@JieX19 Any timeline for when we can expect the next release? Thanks!

MaxxLiu22 commented 6 months ago

Hi @amilstead

The issue has been fixed in Terraform FSW 1.1.2. Please upgrade to this version and give it a try. I will proceed to close this case. Feel free to reopen it if the issue persists.

Thanks, Maxx