cisco-open / terraform-provider-meraki

A Terraform Provider for Cisco Meraki
Mozilla Public License 2.0
17 stars 7 forks source link

meraki_networks_group_policies - crash #148

Closed mcparaf closed 1 month ago

mcparaf commented 2 months ago

Describe the bug This happens when trying to create group policies.

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

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

goroutine 260 [running]:
github.com/cisco-open/terraform-provider-meraki/internal/provider.(*NetworksGroupPoliciesRs).toSdkApiRequestUpdate(0x1400066cea0, {0x1041a0ee8, 0x140006e0b40})
    github.com/cisco-open/terraform-provider-meraki/internal/provider/resource_meraki_networks_group_policies.go:1827 +0x13a0
github.com/cisco-open/terraform-provider-meraki/internal/provider.(*NetworksGroupPoliciesResource).Create(0x140001864a0, {0x1041a0ee8, 0x140006e0b40}, {{{{0x1041a8ce8, 0x1400063d1a0}, {0x103f20940, 0x140008b2f90}}, {0x1041bae88, 0x140006ae780}}, {{{0x1041a8ce8, ...}, ...}, ...}, ...}, ...)
    github.com/cisco-open/terraform-provider-meraki/internal/provider/resource_meraki_networks_group_policies.go:954 +0x504
github.com/hashicorp/terraform-plugin-framework/internal/fwserver.(*Server).CreateResource(0x140002a41e0, {0x1041a0ee8, 0x140006e0b40}, 0x140003dd560, 0x140003dd500)
    github.com/hashicorp/terraform-plugin-framework@v1.11.0/internal/fwserver/server_createresource.go:101 +0x41c
github.com/hashicorp/terraform-plugin-framework/internal/fwserver.(*Server).ApplyResourceChange(0x140008af6c0?, {0x1041a0ee8, 0x140006e0b40}, 0x140006e41e0, 0x140003dd6c0)
    github.com/hashicorp/terraform-plugin-framework@v1.11.0/internal/fwserver/server_applyresourcechange.go:57 +0x380
github.com/hashicorp/terraform-plugin-framework/internal/proto6server.(*Server).ApplyResourceChange(0x140002a41e0, {0x1041a0ee8?, 0x140006e0a20?}, 0x140006e4140)
    github.com/hashicorp/terraform-plugin-framework@v1.11.0/internal/proto6server/server_applyresourcechange.go:55 +0x314
github.com/hashicorp/terraform-plugin-go/tfprotov6/tf6server.(*server).ApplyResourceChange(0x140002aea00, {0x1041a0ee8?, 0x140006e0210?}, 0x140002a6000)
    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({0x1041511e0?, 0x140002aea00}, {0x1041a0ee8, 0x140006e0210}, 0x14000130000, 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(0x14000227000, {0x1041a0ee8, 0x140006e0180}, {0x1041b9370, 0x14000488000}, 0x14000880000, 0x1400038b950, 0x104a143f8, 0x0)
    google.golang.org/grpc@v1.63.2/server.go:1369 +0xba0
google.golang.org/grpc.(*Server).handleStream(0x14000227000, {0x1041b9370, 0x14000488000}, 0x14000880000)
    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 36
    google.golang.org/grpc@v1.63.2/server.go:1030 +0x150

Error: The terraform-provider-meraki_v0.2.11-alpha plugin crashed!

Terraform resource:

locals {
  networks_group_policies = flatten([
    for domain in try(local.meraki.domains, []) : [
      for org in try(domain.organizations, []) : [
        for network in try(org.networks, []) : [
          for group_policy in try(network.group_policies, []) : {
            network_id = meraki_networks.networks["${domain.name}/${org.name}/${network.name}"].id
            data       = group_policy
          }
        ] if try(network.group_policies, null) != null
      ]
    ]
  ])
}

resource "meraki_networks_group_policies" "net_group_policies" {
  for_each                     = { for i, v in local.networks_group_policies : i => v }
  network_id                   = each.value.network_id
  bandwidth                    = try(each.value.data.bandwidth, local.defaults.meraki.networks.group_policies.bandwidth, null)
  bonjour_forwarding           = try(each.value.data.bonjour_forwarding, local.defaults.meraki.networks.group_policies.bonjour_forwarding, null)
  content_filtering            = try(each.value.data.content_filtering, local.defaults.meraki.networks.group_policies.content_filtering, null)
  firewall_and_traffic_shaping = try(each.value.data.firewall_and_traffic_shaping, local.defaults.meraki.networks.group_policies.firewall_and_traffic_shaping, null)
  name                         = try(each.value.data.name, local.defaults.meraki.networks.group_policies.name, null)
  scheduling                   = try(each.value.data.scheduling, local.defaults.meraki.networks.group_policies.scheduling, null)
  splash_auth_settings         = try(each.value.data.splash_auth_settings, local.defaults.meraki.networks.group_policies.splash_auth_settings, null)
  vlan_tagging                 = try(each.value.data.vlan_tagging, local.defaults.meraki.networks.group_policies.vlan_tagging, null)
}

Relevant YAML data:

                group_policies:
                -   name: IOT
                    scheduling:
                        enabled: true
                        monday:
                            active: true
                            from: 00:00
                            to: '24:00'
                        tuesday:
                            active: true
                            from: 00:00
                            to: '24:00'
                        wednesday:
                            active: true
                            from: 00:00
                            to: '24:00'
                        thursday:
                            active: true
                            from: 00:00
                            to: '24:00'
                        friday:
                            active: true
                            from: 00:00
                            to: '24:00'
                        saturday:
                            active: true
                            from: 00:00
                            to: '24:00'
                        sunday:
                            active: true
                            from: 00:00
                            to: '24:00'
                    bandwidth:
                        settings: network default
                    firewall_and_traffic_shaping:
                        settings: custom
                    splash_auth_settings: network default
                    vlan_tagging:
                        settings: custom
                        vlan_id: 30
                    bonjour_forwarding:
                        settings: network default
                -   name: Guest
                    scheduling:
                        enabled: false
                        monday:
                            active: true
                            from: 00:00
                            to: '24:00'
                        tuesday:
                            active: true
                            from: 00:00
                            to: '24:00'
                        wednesday:
                            active: true
                            from: 00:00
                            to: '24:00'
                        thursday:
                            active: true
                            from: 00:00
                            to: '24:00'
                        friday:
                            active: true
                            from: 00:00
                            to: '24:00'
                        saturday:
                            active: true
                            from: 00:00
                            to: '24:00'
                        sunday:
                            active: true
                            from: 00:00
                            to: '24:00'
                    bandwidth:
                        settings: network default
                    firewall_and_traffic_shaping:
                        settings: custom
                    splash_auth_settings: network default
                    vlan_tagging:
                        settings: custom
                        vlan_id: 40
                    bonjour_forwarding:
                        settings: network default
                -   name: BMS
                    scheduling:
                        enabled: false
                        monday:
                            active: true
                            from: 00:00
                            to: '24:00'
                        tuesday:
                            active: true
                            from: 00:00
                            to: '24:00'
                        wednesday:
                            active: true
                            from: 00:00
                            to: '24:00'
                        thursday:
                            active: true
                            from: 00:00
                            to: '24:00'
                        friday:
                            active: true
                            from: 00:00
                            to: '24:00'
                        saturday:
                            active: true
                            from: 00:00
                            to: '24:00'
                        sunday:
                            active: true
                            from: 00:00
                            to: '24:00'
                    bandwidth:
                        settings: network default
                    firewall_and_traffic_shaping:
                        settings: custom
                    splash_auth_settings: network default
                    vlan_tagging:
                        settings: custom
                        vlan_id: 20
                    bonjour_forwarding:
                        settings: network default
                -   name: CORP
                    scheduling:
                        enabled: false
                        monday:
                            active: true
                            from: 00:00
                            to: '24:00'
                        tuesday:
                            active: true
                            from: 00:00
                            to: '24:00'
                        wednesday:
                            active: true
                            from: 00:00
                            to: '24:00'
                        thursday:
                            active: true
                            from: 00:00
                            to: '24:00'
                        friday:
                            active: true
                            from: 00:00
                            to: '24:00'
                        saturday:
                            active: true
                            from: 00:00
                            to: '24:00'
                        sunday:
                            active: true
                            from: 00:00
                            to: '24:00'
                    bandwidth:
                        settings: network default
                    firewall_and_traffic_shaping:
                        settings: custom
                    splash_auth_settings: network default
                    vlan_tagging:
                        settings: custom
                        vlan_id: 10
                    bonjour_forwarding:
                        settings: network default
finkjordanj commented 2 months ago

I believe this is similar to the issue I had in this issue https://github.com/cisco-open/terraform-provider-meraki/issues/36

The workaround was having to build in the dependency to the previous resource call so that state refresh stayed consistent. I believe this is due to the get action only returning ALL group policies vs just the single one being updated so the state lookup isn't built to match out and the loop breaks down.

The errors aren't exactly the same but knowing how the API response for group policies is always the full list of policies I'm guessing its related to that.

fmunozmiranda commented 1 month ago

Please try it with new version and update us.

fmunozmiranda commented 1 month ago

If we don´t get answer in next 24 hours, issue will be closed.