Skip to content
This repository has been archived by the owner on Jul 14, 2023. It is now read-only.

iosxe_restconf does not seem to support empty json #104

Open
mobig opened this issue Apr 20, 2023 · 3 comments
Open

iosxe_restconf does not seem to support empty json #104

mobig opened this issue Apr 20, 2023 · 3 comments

Comments

@mobig
Copy link

mobig commented Apr 20, 2023

when you enable static route redistribution on an IOSXE device, the REST ends up looking like so:

{
    "Cisco-IOS-XE-bgp:bgp": [
        {
            "id": 65000,
            "bgp": {
                "log-neighbor-changes": true
            },
            "neighbor": [
                {
                    "id": "192.168.0.153",
                    "remote-as": 65000,
                    "description": "BGP Neighbor 1"
                }
            ],
            "address-family": {
                "no-vrf": {
                    "ipv4": [
                        {
                            "af-name": "unicast",
                            "ipv4-unicast": {
                                "neighbor": [
                                    {
                                        "id": "192.168.0.153",
                                        "activate": [
                                            null
                                        ],
                                        "route-map": [
                                            {
                                                "inout": "in",
                                                "route-map-name": "RM1"
                                            }
                                        ],
                                        "route-reflector-client": [
                                            null
                                        ]
                                    }
                                ],
                                "redistribute": {
                                    "static": {}
                                }
                            }
                        }
                    ]
                }
            }
        }
    ]
}

the issue is i have not found a way to pass an empty json "{}" using iosxe_restconf resource (which is what the routers seems to expect). this is what i'm trying

# BGP static redistribution
resource "iosxe_restconf" "bgp_redistribution" {
  for_each   = {for bgp in local.router_bgp : bgp.key => bgp}
  device     = each.key
  path       = "Cisco-IOS-XE-native:native/router/Cisco-IOS-XE-bgp:bgp=${each.value.asn}/address-family/no-vrf/ipv4=unicast/ipv4-unicast/redistribute/static"
  attributes = {
    "Cisco-IOS-XE-bgp:static" = "{}"
  }
}

when running this, i get the following error:

Stack trace from the terraform-provider-iosxe_v0.1.15.exe plugin:

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x1 addr=0x8 pc=0x111f8be]

goroutine 72 [running]:
github.com/netascode/go-restconf.(*Client).Discovery(0x0, {0xb430e5?, 0x1bdaa00?, 0x1?})
        github.com/netascode/[email protected]/client.go:395 +0x3e
github.com/netascode/go-restconf.(*Client).PatchData(0x0?, {0xc0004c4600, 0x80}, {0xc000428240, 0x3c}, {0x0, 0x0, _})
        github.com/netascode/[email protected]/client.go:510 +0x9f
github.com/netascode/terraform-provider-iosxe/internal/provider.(*RestconfResource).Create(0xc00000a7d0, {0x16df320, 0xc000078ea0}, {{{{0x16e4190, 0xc0000c4c00}, {0x143ea20, 0xc0000c4120}}, {0x16e64e8, 0xc0000adef0}}, {{{0x16e4190, ...}, ...}, ...}, ...}, ...)
        google.golang.org/[email protected]/server.go:966 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
        google.golang.org/[email protected]/server.go:964 +0x28a

Error: The terraform-provider-iosxe_v0.1.15.exe 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.

any idea how this would be done?

@danischm
Copy link
Member

Can you try this?

resource "iosxe_restconf" "bgp_redistribution" {
  for_each   = {for bgp in local.router_bgp : bgp.key => bgp}
  device     = each.key
  path       = "Cisco-IOS-XE-native:native/router/Cisco-IOS-XE-bgp:bgp=${each.value.asn}/address-family/no-vrf/ipv4=unicast/ipv4-unicast/redistribute"
  attributes = {
    "static" = ""
  }
}

@mobig
Copy link
Author

mobig commented Apr 20, 2023

with the HCL you provided, i'm still getting the error:

iosxe_restconf.bgp_redistribution["Site-02-65000"]: Creating...
╷
│ Error: Plugin did not respond
│
│ The plugin encountered an error, and failed to respond to the plugin6.(*GRPCProvider).ApplyResourceChange call. The plugin logs may contain more details.
╵
╷
│ Error: Plugin did not respond
│
│ The plugin encountered an error, and failed to respond to the plugin6.(*GRPCProvider).ApplyResourceChange call. The plugin logs may contain more details.
╵

Stack trace from the terraform-provider-iosxe_v0.1.15.exe plugin:

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x1 addr=0x8 pc=0xf9f8be]

goroutine 130 [running]:
github.com/netascode/go-restconf.(*Client).Discovery(0x0, {0x9c30e5?, 0x1a5aa00?, 0x1?})
        github.com/netascode/[email protected]/client.go:395 +0x3e
github.com/netascode/go-restconf.(*Client).PatchData(0x0?, {0xc0000e8580, 0x79}, {0xc000031170, 0x2f}, {0x0, 0x0, _})
        github.com/netascode/[email protected]/client.go:510 +0x9f
github.com/netascode/terraform-provider-iosxe/internal/provider.(*RestconfResource).Create(0xc000408668, {0x155f320, 0xc000595890}, {{{{0x1564190, 0xc0005a35f0}, {0x12bea20, 0xc0005a2b10}}, {0x15664e8, 0xc00033ad20}}, {{{0x1564190, ...}, ...}, ...}, ...}, ...)
        github.com/netascode/terraform-provider-iosxe/internal/provider/resource_iosxe_restconf.go:132 +0x41f
github.com/hashicorp/terraform-plugin-framework/internal/fwserver.(*Server).CreateResource(0xc000231340, {0x155f320, 0xc000595890}, 0xc000831360, 0xc000831300)
        github.com/hashicorp/[email protected]/internal/fwserver/server_createresource.go:97 +0x5b8
github.com/hashicorp/terraform-plugin-framework/internal/fwserver.(*Server).ApplyResourceChange(0x155f320?, {0x155f320, 0xc000595890}, 0xc0008f9e50, 0xc0008314d0)
        github.com/hashicorp/[email protected]/internal/fwserver/server_applyresourcechange.go:54 +0x4a8
github.com/hashicorp/terraform-plugin-framework/internal/proto6server.(*Server).ApplyResourceChange(0xc000231340, {0x155f320?, 0xc000595740?}, 0xc0008f9e00)
        github.com/hashicorp/[email protected]/internal/proto6server/server_applyresourcechange.go:52 +0x27b
github.com/hashicorp/terraform-plugin-go/tfprotov6/tf6server.(*server).ApplyResourceChange(0xc00022d0e0, {0x155f320?, 0xc000594d80?}, 0xc00073bd50)
        github.com/hashicorp/[email protected]/tfprotov6/tf6server/server.go:816 +0x574
github.com/hashicorp/terraform-plugin-go/tfprotov6/internal/tfplugin6._Provider_ApplyResourceChange_Handler({0x137bb40?, 0xc00022d0e0}, {0x155f320, 0xc000594d80}, 0xc00073bce0, 0x0)
        github.com/hashicorp/[email protected]/tfprotov6/internal/tfplugin6/tfplugin6_grpc.pb.go:419 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc00028c1e0, {0x1564a78, 0xc00029d520}, 0xc0009ebb00, 0xc0003ec000, 0x1a4d920, 0x0)
        google.golang.org/[email protected]/server.go:1345 +0xdf0
google.golang.org/grpc.(*Server).handleStream(0xc00028c1e0, {0x1564a78, 0xc00029d520}, 0xc0009ebb00, 0x0)
        google.golang.org/[email protected]/server.go:1722 +0xa2f
google.golang.org/grpc.(*Server).serveStreams.func1.2()
        google.golang.org/[email protected]/server.go:966 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
        google.golang.org/[email protected]/server.go:964 +0x28a

Error: The terraform-provider-iosxe_v0.1.15.exe 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.

@danischm
Copy link
Member

Is that maybe the same issue as in the other thread, where device is not a name but rather a URL?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants