Skip to content

Fix deletion for single-array-only resources #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

vozhyk-
Copy link
Collaborator

@vozhyk- vozhyk- commented May 28, 2025

Singleton resources (ones without a DELETE endpoint) don't do anything on delete,
leaving the infrastructure still configured.
Aside from being unexpected,
this also sometimes blocks deletion of other resources (like in #82).

Some resources (mostly ones with a single "rules" list attribute) were changed to instead do a PUT with an empty list, fixing the issue for those resources.

Do that for the rest of such resources
(ones with a single attribute that is a list of maps).

Note that 79 resources that do nothing on delete
still remain after this change.
The issue will have to be documented
and the resources fixed manually on a case-by-case basis by inferring the expected behavior from the UI.

TODO: Test this.
TODO Make an issue with the rest of the resources listed.

Singleton resources (ones without a DELETE endpoint)
don't do anything on delete,
leaving the infrastructure still configured.
Aside from being unexpected,
this also sometimes blocks deletion of other resources
(like in CiscoDevNet#82).

Some resources (mostly ones with a single "rules" list attribute)
were changed to instead do a PUT with an empty list,
fixing the issue for those resources.

Do that for the rest of such resources
(ones with a single attribute that is a list of maps).

Note that 79 resources that do nothing on delete
still remain after this change.
The issue will have to be documented
and the resources fixed manually on a case-by-case basis
by inferring the expected behavior from the UI.
@jon-humphries
Copy link

Please could we also evaluate the following to this PR for consideration:

I don't believe any special handiling is required other than return an empty list.

gen/definitions/appliance_static_route.yaml

gen/definitions/appliance_traffic_shaping_custom_performance_class.yaml - When we create a custom class.
gen/definitions/appliance_traffic_shaping_uplink_selection.yaml
gen/definitions/appliance_traffic_shaping_vpn_exclusions.yaml

@vozhyk-
Copy link
Collaborator Author

vozhyk- commented May 29, 2025

Please could we also evaluate the following to this PR for consideration:

I don't believe any special handiling is required other than return an empty list.

gen/definitions/appliance_static_route.yaml

This is not a singleton resource, so deletes happen normally for it:
the definition doesn't have a no_delete: true, and indeed the generated internal/provider/resource_meraki_appliance_static_route.go does an r.client.Delete() on delete - is there anything to fix here?

gen/definitions/appliance_traffic_shaping_custom_performance_class.yaml - When we create a custom class.

As above - this is not a singleton resource and handles Delete normally.

gen/definitions/appliance_traffic_shaping_uplink_selection.yaml

This does have 2 lists-of-maps ({vpn,wan}_traffic_uplink_preferences) which we can set to [] on deletion, but what should we set the other fields to?

gen/definitions/appliance_traffic_shaping_vpn_exclusions.yaml

This has 2 lists-of-maps (custom and major_applications) and nothing else. Setting both to [] on deletion would work. Is that what you mean?

@jon-humphries
Copy link

gen/definitions/appliance_traffic_shaping_uplink_selection.yaml

This does have 2 lists-of-maps ({vpn,wan}_traffic_uplink_preferences) which we can set to [] on >deletion, but what should we set the other fields to?

I think just an empty list for ({vpn,wan}_traffic_uplink_preferences) would remove any of the other fields ?

gen/definitions/appliance_traffic_shaping_vpn_exclusions.yaml

This has 2 lists-of-maps (custom and major_applications) and nothing else. Setting both to [] on

deletion would work. Is that what you mean?

Yes for custom and major_apps. There is a potential for other configuration deployed by another resource to cause an issue if this isnt deleted.

@vozhyk-
Copy link
Collaborator Author

vozhyk- commented May 29, 2025

I think just an empty list for ({vpn,wan}_traffic_uplink_preferences) would remove any of the other fields ?

I don't think so, but I can test.

Yes for custom and major_apps. There is a potential for other configuration deployed by another resource to cause an issue if this isnt deleted.

I'll do this in this PR.

Do a PUT with all fields ("custom" and "majorApplications") set to `[]`.
@vozhyk-
Copy link
Collaborator Author

vozhyk- commented May 29, 2025

About ...uplink_selection - turns out doing a PUT with the 2 empty lists (not included in this PR yet) does not result in them becoming empty in the GET response / the UI.

2025-05-29T17:16:40.295+0200 [DEBUG] provider.terraform-provider-meraki: 2025/05/29 17:16:40 REQUEST --------------------------
2025-05-29T17:16:40.295+0200 [DEBUG] provider.terraform-provider-meraki: 2025/05/29 17:16:40 PUT https://api.meraki.com/api/v1/networks/L_4005951868546057037/appliance/trafficShaping/uplinkSelection
2025-05-29T17:16:40.295+0200 [DEBUG] provider.terraform-provider-meraki: 2025/05/29 17:16:40 Accept: [application/json]
2025-05-29T17:16:40.295+0200 [DEBUG] provider.terraform-provider-meraki: 2025/05/29 17:16:40 Authorization: ****
2025-05-29T17:16:40.295+0200 [DEBUG] provider.terraform-provider-meraki: 2025/05/29 17:16:40 User-Agent: [go-meraki netascode]
2025-05-29T17:16:40.295+0200 [DEBUG] provider.terraform-provider-meraki: 2025/05/29 17:16:40 Content-Type: [application/json]
2025-05-29T17:16:40.295+0200 [DEBUG] provider.terraform-provider-meraki: 2025/05/29 17:16:40 --------------------------
2025-05-29T17:16:40.295+0200 [DEBUG] provider.terraform-provider-meraki: 2025/05/29 17:16:40 {
2025-05-29T17:16:40.295+0200 [DEBUG] provider.terraform-provider-meraki: 2025/05/29 17:16:40   "vpnTrafficUplinkPreferences": [],
2025-05-29T17:16:40.295+0200 [DEBUG] provider.terraform-provider-meraki: 2025/05/29 17:16:40   "wanTrafficUplinkPreferences": []
2025-05-29T17:16:40.295+0200 [DEBUG] provider.terraform-provider-meraki: 2025/05/29 17:16:40 }
2025-05-29T17:16:40.318+0200 [DEBUG] State storage *statemgr.Filesystem declined to persist a state snapshot
2025-05-29T17:16:40.660+0200 [DEBUG] provider.terraform-provider-meraki: 2025/05/29 17:16:40 RESPONSE 200 --------------------------
module.meraki.meraki_appliance_traffic_shaping_uplink_selection.networks_appliance_traffic_shaping_uplink_selection["EMEA/Dev-WB/netascode-network-01"]: Destruction complete after 1s
% curl -L --request GET \
--url https://api.meraki.com/api/v1/networks/"$api_network_id"/appliance/trafficShaping/uplinkSelection \
--header 'Authorization: Bearer '"$MERAKI_API_KEY" \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' | jq .
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   844    0   844    0     0   2104      0 --:--:-- --:--:-- --:--:--  2110
{
  "activeActiveAutoVpnEnabled": false,
  "defaultUplink": "wan1",
  "loadBalancingEnabled": false,
  "wanTrafficUplinkPreferences": [
    {
      "trafficFilters": [
        {
          "type": "custom",
          "value": {
            "protocol": "tcp",
            "source": {
              "port": "1-1024",
              "cidr": "any"
            },
            "destination": {
              "applications": null,
              "cidr": "any",
              "port": "any"
            }
          }
        }
      ],
      "preferredUplink": "wan1",
      "failOverCriterion": "poorPerformance",
      "performanceClass": {
        "type": null,
        "builtinPerformanceClassName": null,
        "customPerformanceClassId": null
      }
    },
    {
      "trafficFilters": [
        {
          "type": "custom",
          "value": {
            "protocol": "tcp",
            "source": {
              "port": "any",
              "cidr": "192.168.20.0/24"
            },
            "destination": {
              "applications": null,
              "cidr": "any",
              "port": "443"
            }
          }
        }
      ],
      "preferredUplink": "wan1",
      "failOverCriterion": "poorPerformance",
      "performanceClass": {
        "type": null,
        "builtinPerformanceClassName": null,
        "customPerformanceClassId": null
      }
    }
  ],
  "failoverAndFailback": {
    "immediate": {
      "enabled": true
    }
  }
}

I haven't tested the others to confirm they work yet.

@jon-humphries
Copy link

jon-humphries commented May 30, 2025

Ok, for now please attempt to only pass empty list to traffic filters only nested under each parent ({vpn,wan}_traffic_uplink_preferences) as these are the Lists that are causing the errors.

We may also require handiling of performanceClass to ensure it is removed but will check this once you are able to delete traffic_filters.

"performanceClass": { "type": custom, "customPerformanceClassId": 123456 }

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

Successfully merging this pull request may close these issues.

2 participants