cisco-open / terraform-provider-meraki

A Terraform Provider for Cisco Meraki
Mozilla Public License 2.0
15 stars 6 forks source link

meraki_networks panics on creation if the organization id is invalid #101

Closed VenelinMartinov closed 1 month ago

VenelinMartinov commented 1 month ago

Prerequisites

Describe the bug A clear and concise description of what the bug is.

Running the example in the meraki_networks docs triggers a panic upon creation:

https://registry.terraform.io/providers/cisco-open/meraki/latest/docs/resources/networks

Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # meraki_networks.example will be created
  + resource "meraki_networks" "example" {
      + enrollment_string           = (known after apply)
      + id                          = (known after apply)
      + is_bound_to_config_template = (known after apply)
      + name                        = "Main Office"
      + network_id                  = (known after apply)
      + notes                       = "Additional description of the network"
      + organization_id             = "your_organization_id"
      + product_types               = [
          + "appliance",
          + "switch",
          + "wireless",
        ]
      + tags                        = [
          + "tag1",
          + "tag2",
        ]
      + time_zone                   = "America/Los_Angeles"
      + url                         = (known after apply)
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

yes
  Enter a value:
meraki_networks.example: Creating...
╷
│ Error: Request cancelled
│
│ The plugin6.(*GRPCProvider).ApplyResourceChange request was cancelled.
╵

Stack trace from the terraform-provider-meraki_v0.2.5-alpha plugin:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x10343f6ac]

goroutine 13 [running]:
github.com/cisco-open/terraform-provider-meraki/internal/provider.getAllItemsNetworks({{0x14000166280, 0x1400010c6c0}, 0x14000118300, 0x14000118300, 0x14000118300, 0x14000118300, 0x14000118300, 0x14000118300, 0x14000118300, 0x14000118300, ...}, ...)
    github.com/cisco-open/terraform-provider-meraki/internal/provider/resource_meraki_networks.go:521 +0x9c
github.com/cisco-open/terraform-provider-meraki/internal/provider.(*NetworksResource).Create(0x1400007a4d8, {0x104053348, 0x1400044a8a0}, {{{{0x10405af88, 0x1400020e0c0}, {0x103dd7d00, 0x1400044ba40}}, {0x10406d128, 0x14000140050}}, {{{0x10405af88, ...}, ...}, ...}, ...}, ...)
    github.com/cisco-open/terraform-provider-meraki/internal/provider/resource_meraki_networks.go:167 +0x350
github.com/hashicorp/terraform-plugin-framework/internal/fwserver.(*Server).CreateResource(0x140001e3040, {0x104053348, 0x1400044a8a0}, 0x1400017f560, 0x1400017f500)
    github.com/hashicorp/terraform-plugin-framework@v1.7.0/internal/fwserver/server_createresource.go:101 +0x41c
github.com/hashicorp/terraform-plugin-framework/internal/fwserver.(*Server).ApplyResourceChange(0x1400017f6c0?, {0x104053348, 0x1400044a8a0}, 0x140004600a0, 0x1400017f6c0)
    github.com/hashicorp/terraform-plugin-framework@v1.7.0/internal/fwserver/server_applyresourcechange.go:57 +0x380
github.com/hashicorp/terraform-plugin-framework/internal/proto6server.(*Server).ApplyResourceChange(0x140001e3040, {0x104053348?, 0x1400044a780?}, 0x14000460000)
    github.com/hashicorp/terraform-plugin-framework@v1.7.0/internal/proto6server/server_applyresourcechange.go:55 +0x314
github.com/hashicorp/terraform-plugin-go/tfprotov6/tf6server.(*server).ApplyResourceChange(0x1400022e8c0, {0x104053348?, 0x140003fdda0?}, 0x14000226310)
    github.com/hashicorp/terraform-plugin-go@v0.23.0/tfprotov6/tf6server/server.go:865 +0x2b0
github.com/hashicorp/terraform-plugin-go/tfprotov6/internal/tfplugin6._Provider_ApplyResourceChange_Handler({0x104003940?, 0x1400022e8c0}, {0x104053348, 0x140003fdda0}, 0x14000328b00, 0x0)
    github.com/hashicorp/terraform-plugin-go@v0.23.0/tfprotov6/internal/tfplugin6/tfplugin6_grpc.pb.go:518 +0x164
google.golang.org/grpc.(*Server).processUnaryRPC(0x140001ab000, {0x104053348, 0x14000417dd0}, {0x10406b618, 0x1400047a000}, 0x1400037f440, 0x140003079b0, 0x1048b83d8, 0x0)
    google.golang.org/grpc@v1.63.2/server.go:1369 +0xba0
google.golang.org/grpc.(*Server).handleStream(0x140001ab000, {0x10406b618, 0x1400047a000}, 0x1400037f440)
    google.golang.org/grpc@v1.63.2/server.go:1780 +0xc80
google.golang.org/grpc.(*Server).serveStreams.func2.1()
    google.golang.org/grpc@v1.63.2/server.go:1019 +0x8c
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 20
    google.golang.org/grpc@v1.63.2/server.go:1030 +0x150

Error: The terraform-provider-meraki_v0.2.5-alpha 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.

Error: exit status 1

Expected behavior A clear and concise description of what you expected to happen.

No panic should happen - if an error has happened it should be displayed instead.

Screenshots Please provide an screenshot of the successful API call with cuRL, Postman, etc.

Environment (please complete the following information):

Additional context Add any other context about the problem here.

fmunozmiranda commented 1 month ago

@VenelinMartinov please try it again with new version and update us.

fmunozmiranda commented 1 month ago

If we do not receive a response it will be closed in the next 24 hours.

VenelinMartinov commented 1 month ago

Yup, can confirm this is fixed. Thanks for addressing @fmunozmiranda!