Skip to content

Commit

Permalink
Delete rules when destroying the resource
Browse files Browse the repository at this point in the history
  • Loading branch information
danischm committed Feb 9, 2025
1 parent 88098f9 commit 2d36355
Show file tree
Hide file tree
Showing 167 changed files with 1,364 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.5 (unreleased)

- Delete all rules when destroying `meraki_appliance_cellular_firewall_rules`, `meraki_appliance_inbound_cellular_firewall_rules`, `meraki_appliance_inbound_firewall_rules`, `meraki_appliance_l3_firewall_rules`, `meraki_appliance_l7_firewall_rules`, `meraki_appliance_one_to_many_nat_rules`, `meraki_appliance_one_to_one_nat_rules`, `meraki_appliance_port_forwarding_rules`, `meraki_appliance_traffic_shaping_rules`, `meraki_appliance_vpn_firewall_rules`, `meraki_wireless_ssid_l3_firewall_rules`, `meraki_wireless_ssid_l7_firewall_rules`, `meraki_wireless_ssid_traffic_shaping_rules` resources

## 0.1.4

- Add `ip_version` attribute to `meraki_wireless_ssid_l3_firewall_rules` resource and data source
Expand Down
4 changes: 4 additions & 0 deletions docs/guides/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ description: |-

# Changelog

## 0.1.5 (unreleased)

- Delete all rules when destroying `meraki_appliance_cellular_firewall_rules`, `meraki_appliance_inbound_cellular_firewall_rules`, `meraki_appliance_inbound_firewall_rules`, `meraki_appliance_l3_firewall_rules`, `meraki_appliance_l7_firewall_rules`, `meraki_appliance_one_to_many_nat_rules`, `meraki_appliance_one_to_one_nat_rules`, `meraki_appliance_port_forwarding_rules`, `meraki_appliance_traffic_shaping_rules`, `meraki_appliance_vpn_firewall_rules`, `meraki_wireless_ssid_l3_firewall_rules`, `meraki_wireless_ssid_l7_firewall_rules`, `meraki_wireless_ssid_traffic_shaping_rules` resources

## 0.1.4

- Add `ip_version` attribute to `meraki_wireless_ssid_l3_firewall_rules` resource and data source
Expand Down
1 change: 1 addition & 0 deletions gen/definitions/appliance_cellular_firewall_rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ attributes:
allow_import_changes: true
description: An ordered array of the firewall rules (not including the default rule)
ordered_list: true
destroy_value: '[]interface{}{}'
attributes:
- model_name: comment
type: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ attributes:
allow_import_changes: true
description: An ordered array of the firewall rules (not including the default rule)
ordered_list: true
destroy_value: '[]interface{}{}'
attributes:
- model_name: comment
type: String
Expand Down
1 change: 1 addition & 0 deletions gen/definitions/appliance_inbound_firewall_rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ attributes:
allow_import_changes: true
description: An ordered array of the firewall rules (not including the default rule)
ordered_list: true
destroy_value: '[]interface{}{}'
attributes:
- model_name: comment
type: String
Expand Down
1 change: 1 addition & 0 deletions gen/definitions/appliance_l3_firewall_rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ attributes:
allow_import_changes: true
description: An ordered array of the firewall rules (not including the default rule)
ordered_list: true
destroy_value: '[]interface{}{}'
attributes:
- model_name: comment
type: String
Expand Down
1 change: 1 addition & 0 deletions gen/definitions/appliance_l7_firewall_rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ attributes:
mandatory: true
description: An ordered array of the MX L7 firewall rules
ordered_list: true
destroy_value: '[]interface{}{}'
attributes:
- model_name: policy
type: String
Expand Down
1 change: 1 addition & 0 deletions gen/definitions/appliance_one_to_many_nat_rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ attributes:
type: List
mandatory: true
description: An array of 1:Many nat rules
destroy_value: '[]interface{}{}'
attributes:
- model_name: publicIp
type: String
Expand Down
1 change: 1 addition & 0 deletions gen/definitions/appliance_one_to_one_nat_rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ attributes:
type: List
mandatory: true
description: An array of 1:1 nat rules
destroy_value: '[]interface{}{}'
attributes:
- model_name: lanIp
type: String
Expand Down
1 change: 1 addition & 0 deletions gen/definitions/appliance_port_forwarding_rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ attributes:
type: List
mandatory: true
description: An array of port forwarding params
destroy_value: '[]interface{}{}'
attributes:
- model_name: lanIp
type: String
Expand Down
1 change: 1 addition & 0 deletions gen/definitions/appliance_traffic_shaping_rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ attributes:
type: List
description: An array of traffic shaping rules. Rules are applied in the order that they are specified in. An empty list (or null) means no rules. Note that you are allowed a maximum of 8 rules.
ordered_list: true
destroy_value: '[]interface{}{}'
attributes:
- model_name: dscpTagValue
type: Int64
Expand Down
1 change: 1 addition & 0 deletions gen/definitions/appliance_vpn_firewall_rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ attributes:
allow_import_changes: true
description: An ordered array of the firewall rules (not including the default rule)
ordered_list: true
destroy_value: '[]interface{}{}'
attributes:
- model_name: comment
type: String
Expand Down
1 change: 1 addition & 0 deletions gen/definitions/wireless_ssid_l3_firewall_rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ attributes:
allow_import_changes: true
description: An ordered array of the firewall rules for this SSID (not including the local LAN access rule or the default rule).
ordered_list: true
destroy_value: '[]interface{}{}'
attributes:
- model_name: comment
type: String
Expand Down
1 change: 1 addition & 0 deletions gen/definitions/wireless_ssid_l7_firewall_rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ attributes:
type: List
description: An array of L7 firewall rules for this SSID. Rules will get applied in the same order user has specified in request. Empty array will clear the L7 firewall rule configuration.
ordered_list: true
destroy_value: '[]interface{}{}'
attributes:
- model_name: policy
type: String
Expand Down
1 change: 1 addition & 0 deletions gen/definitions/wireless_ssid_traffic_shaping_rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ attributes:
type: List
description: An array of traffic shaping rules. Rules are applied in the order that they are specified in. An empty list (or null) means no rules. Note that you are allowed a maximum of 8 rules.
ordered_list: true
destroy_value: '[]interface{}{}'
attributes:
- model_name: dscpTagValue
type: Int64
Expand Down
1 change: 1 addition & 0 deletions gen/schema/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@ attribute:
value: any(str(), int(), bool(), required=False) # Hardcoded value for the attribute
test_value: str(required=False) # Value used for acceptance test
minimum_test_value: str(required=False) # Value used for "minimum" resource acceptance test
destroy_value: str(required=False) # Value used when destroying resource using PUT
test_tags: list(str(), required=False) # List of test tags, attribute is only included in acceptance tests if an environment variable with one of these tags is configured
attributes: list(include('attribute'), required=False) # List of attributes, only relevant if type is "List" or "Set"
14 changes: 14 additions & 0 deletions gen/templates/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,20 @@ func (data *{{camelCase .Name}}) fromBodyUnknowns(ctx context.Context, res merak

// End of section. //template:end fromBodyUnknowns

// Section below is generated&owned by "gen/generator.go". //template:begin toDestroyBody

func (data {{camelCase .Name}}) toDestroyBody(ctx context.Context) string {
body := ""
{{- range .Attributes}}
{{- if .DestroyValue}}
body, _ = sjson.Set(body, "{{getFullModelName .}}", {{.DestroyValue}})
{{- end}}
{{- end}}
return body
}

// End of section. //template:end toDestroyBody

{{- range .Attributes}}
{{- range .Attributes}}
{{- if .OrderedList }}
Expand Down
9 changes: 8 additions & 1 deletion gen/templates/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,14 @@ func (r *{{camelCase .Name}}Resource) Delete(ctx context.Context, req resource.D

tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Delete", state.Id.ValueString()))

{{- if not .NoDelete}}
{{- if hasDestroyValues .Attributes}}
body := state.toDestroyBody(ctx)
res, err := r.client.Put(state.getPath(), body)
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (PUT), got error: %s, %s", err, res.String()))
return
}
{{- else if not .NoDelete}}
res, err := r.client.Delete(state.getPath() + "/" + url.QueryEscape(state.Id.ValueString()))
if err != nil && !strings.Contains(err.Error(), "StatusCode 404") {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to delete object (DELETE), got error: %s, %s", err, res.String()))
Expand Down
19 changes: 19 additions & 0 deletions gen/yamlconfig/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ type YamlConfigAttribute struct {
Value string `yaml:"value,omitempty"`
TestValue string `yaml:"test_value,omitempty"`
MinimumTestValue string `yaml:"minimum_test_value,omitempty"`
DestroyValue string `yaml:"destroy_value,omitempty"`
TestTags []string `yaml:"test_tags,omitempty,flow"`
Attributes []YamlConfigAttribute `yaml:"attributes,omitempty"`
GoTypeName string `yaml:"gotypename,omitempty"`
Expand Down Expand Up @@ -149,6 +150,7 @@ type YamlConfigAttributeP struct {
Value *string `yaml:"value,omitempty"`
TestValue *string `yaml:"test_value,omitempty"`
MinimumTestValue *string `yaml:"minimum_test_value,omitempty"`
DestroyValue *string `yaml:"destroy_value,omitempty"`
TestTags *[]string `yaml:"test_tags,omitempty,flow"`
Attributes *[]YamlConfigAttributeP `yaml:"attributes,omitempty"`
GoTypeName *string `yaml:"gotypename,omitempty"`
Expand Down Expand Up @@ -410,6 +412,19 @@ func BuildTestPath(attr ...YamlConfigAttribute) string {
return strings.Join(path, ".") + "."
}

// HasDestroyValues returns true if any attributes have explicit destroy values
func HasDestroyValues(attributes []YamlConfigAttribute) bool {
for _, attr := range attributes {
if attr.DestroyValue != "" {
return true
}
if len(attr.Attributes) > 0 && HasDestroyValues(attr.Attributes) {
return true
}
}
return false
}

// Map of templating functions
var Functions = template.FuncMap{
"toGoName": ToGoName,
Expand Down Expand Up @@ -439,6 +454,7 @@ var Functions = template.FuncMap{
"getFullModelName": GetFullModelName,
"hasComputedAttributes": HasComputedAttributes,
"buildTestPath": BuildTestPath,
"hasDestroyValues": HasDestroyValues,
}

var matchFirstCap = regexp.MustCompile("(.)([A-Z][a-z]+)")
Expand Down Expand Up @@ -795,6 +811,9 @@ func MergeYamlConfigAttribute(existing *YamlConfigAttributeP, new *YamlConfigAtt
if existing.MinimumTestValue != nil {
new.MinimumTestValue = existing.MinimumTestValue
}
if existing.DestroyValue != nil {
new.DestroyValue = existing.DestroyValue
}
if existing.TestTags != nil {
new.TestTags = existing.TestTags
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,13 @@ func (data *ApplianceCellularFirewallRules) fromBodyUnknowns(ctx context.Context
}

// End of section. //template:end fromBodyUnknowns

// Section below is generated&owned by "gen/generator.go". //template:begin toDestroyBody

func (data ApplianceCellularFirewallRules) toDestroyBody(ctx context.Context) string {
body := ""
body, _ = sjson.Set(body, "rules", []interface{}{})
return body
}

// End of section. //template:end toDestroyBody
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,12 @@ func (data *ApplianceConnectivityMonitoringDestinations) fromBodyUnknowns(ctx co
}

// End of section. //template:end fromBodyUnknowns

// Section below is generated&owned by "gen/generator.go". //template:begin toDestroyBody

func (data ApplianceConnectivityMonitoringDestinations) toDestroyBody(ctx context.Context) string {
body := ""
return body
}

// End of section. //template:end toDestroyBody
9 changes: 9 additions & 0 deletions internal/provider/model_meraki_appliance_content_filtering.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,12 @@ func (data *ApplianceContentFiltering) fromBodyUnknowns(ctx context.Context, res
}

// End of section. //template:end fromBodyUnknowns

// Section below is generated&owned by "gen/generator.go". //template:begin toDestroyBody

func (data ApplianceContentFiltering) toDestroyBody(ctx context.Context) string {
body := ""
return body
}

// End of section. //template:end toDestroyBody
9 changes: 9 additions & 0 deletions internal/provider/model_meraki_appliance_firewall_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,12 @@ func (data *ApplianceFirewallSettings) fromBodyUnknowns(ctx context.Context, res
}

// End of section. //template:end fromBodyUnknowns

// Section below is generated&owned by "gen/generator.go". //template:begin toDestroyBody

func (data ApplianceFirewallSettings) toDestroyBody(ctx context.Context) string {
body := ""
return body
}

// End of section. //template:end toDestroyBody
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,12 @@ func (data *ApplianceFirewalledService) fromBodyUnknowns(ctx context.Context, re
}

// End of section. //template:end fromBodyUnknowns

// Section below is generated&owned by "gen/generator.go". //template:begin toDestroyBody

func (data ApplianceFirewalledService) toDestroyBody(ctx context.Context) string {
body := ""
return body
}

// End of section. //template:end toDestroyBody
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,13 @@ func (data *ApplianceInboundCellularFirewallRules) fromBodyUnknowns(ctx context.
}

// End of section. //template:end fromBodyUnknowns

// Section below is generated&owned by "gen/generator.go". //template:begin toDestroyBody

func (data ApplianceInboundCellularFirewallRules) toDestroyBody(ctx context.Context) string {
body := ""
body, _ = sjson.Set(body, "rules", []interface{}{})
return body
}

// End of section. //template:end toDestroyBody
10 changes: 10 additions & 0 deletions internal/provider/model_meraki_appliance_inbound_firewall_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,13 @@ func (data *ApplianceInboundFirewallRules) fromBodyUnknowns(ctx context.Context,
}

// End of section. //template:end fromBodyUnknowns

// Section below is generated&owned by "gen/generator.go". //template:begin toDestroyBody

func (data ApplianceInboundFirewallRules) toDestroyBody(ctx context.Context) string {
body := ""
body, _ = sjson.Set(body, "rules", []interface{}{})
return body
}

// End of section. //template:end toDestroyBody
10 changes: 10 additions & 0 deletions internal/provider/model_meraki_appliance_l3_firewall_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,13 @@ func (data *ApplianceL3FirewallRules) fromBodyUnknowns(ctx context.Context, res
}

// End of section. //template:end fromBodyUnknowns

// Section below is generated&owned by "gen/generator.go". //template:begin toDestroyBody

func (data ApplianceL3FirewallRules) toDestroyBody(ctx context.Context) string {
body := ""
body, _ = sjson.Set(body, "rules", []interface{}{})
return body
}

// End of section. //template:end toDestroyBody
10 changes: 10 additions & 0 deletions internal/provider/model_meraki_appliance_l7_firewall_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,13 @@ func (data *ApplianceL7FirewallRules) fromBodyUnknowns(ctx context.Context, res
}

// End of section. //template:end fromBodyUnknowns

// Section below is generated&owned by "gen/generator.go". //template:begin toDestroyBody

func (data ApplianceL7FirewallRules) toDestroyBody(ctx context.Context) string {
body := ""
body, _ = sjson.Set(body, "rules", []interface{}{})
return body
}

// End of section. //template:end toDestroyBody
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,12 @@ func (data *ApplianceNetworkSecurityIntrusion) fromBodyUnknowns(ctx context.Cont
}

// End of section. //template:end fromBodyUnknowns

// Section below is generated&owned by "gen/generator.go". //template:begin toDestroyBody

func (data ApplianceNetworkSecurityIntrusion) toDestroyBody(ctx context.Context) string {
body := ""
return body
}

// End of section. //template:end toDestroyBody
10 changes: 10 additions & 0 deletions internal/provider/model_meraki_appliance_one_to_many_nat_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,13 @@ func (data *ApplianceOneToManyNATRules) fromBodyUnknowns(ctx context.Context, re
}

// End of section. //template:end fromBodyUnknowns

// Section below is generated&owned by "gen/generator.go". //template:begin toDestroyBody

func (data ApplianceOneToManyNATRules) toDestroyBody(ctx context.Context) string {
body := ""
body, _ = sjson.Set(body, "rules", []interface{}{})
return body
}

// End of section. //template:end toDestroyBody
10 changes: 10 additions & 0 deletions internal/provider/model_meraki_appliance_one_to_one_nat_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,13 @@ func (data *ApplianceOneToOneNATRules) fromBodyUnknowns(ctx context.Context, res
}

// End of section. //template:end fromBodyUnknowns

// Section below is generated&owned by "gen/generator.go". //template:begin toDestroyBody

func (data ApplianceOneToOneNATRules) toDestroyBody(ctx context.Context) string {
body := ""
body, _ = sjson.Set(body, "rules", []interface{}{})
return body
}

// End of section. //template:end toDestroyBody
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,12 @@ func (data *ApplianceOrganizationSecurityIntrusion) fromBodyUnknowns(ctx context
}

// End of section. //template:end fromBodyUnknowns

// Section below is generated&owned by "gen/generator.go". //template:begin toDestroyBody

func (data ApplianceOrganizationSecurityIntrusion) toDestroyBody(ctx context.Context) string {
body := ""
return body
}

// End of section. //template:end toDestroyBody
Loading

0 comments on commit 2d36355

Please sign in to comment.