Skip to content

Commit 4791add

Browse files
sumanbasireddysankhsin
authored andcommitted
Bug Fix : Fixing tunnel inspection and nat rules names for herds reset export resources failure.
1 parent e4b2e22 commit 4791add

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

internal/service/network_firewall/network_firewall_export.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,22 +127,35 @@ func getNetworkFirewallNetworkFirewallPolicyDecryptionProfileId(resource *tf_exp
127127
}
128128

129129
func getNetworkFirewallNetworkFirewallPolicyTunnelInspectionRuleId(resource *tf_export.OCIResource) (string, error) {
130-
131130
networkFirewallPolicyId := resource.Parent.Id
132-
tunnelInspectionRuleName, ok := resource.SourceAttributes["tunnel_inspection_rule_name"].(string)
133-
if !ok {
131+
// Try to get rule name from "name"
132+
var tunnelInspectionRuleName string
133+
if val, ok := resource.SourceAttributes["name"].(string); ok && val != "" {
134+
tunnelInspectionRuleName = val
135+
} else if val, ok := resource.SourceAttributes["tunnel_inspection_rule_name"].(string); ok && val != "" {
136+
// Fallback for backward compatibility
137+
tunnelInspectionRuleName = val
138+
} else {
134139
return "", fmt.Errorf("[ERROR] unable to find tunnelInspectionRuleName for NetworkFirewall NetworkFirewallPolicyTunnelInspectionRule")
135140
}
141+
136142
return GetNetworkFirewallPolicyTunnelInspectionRuleCompositeId(networkFirewallPolicyId, tunnelInspectionRuleName), nil
137143
}
138144

139145
func getNetworkFirewallNetworkFirewallPolicyNatRuleId(resource *tf_export.OCIResource) (string, error) {
146+
networkFirewallPolicyId := resource.Parent.Id
140147

141-
natRuleName, ok := resource.SourceAttributes["nat_rule_name"].(string)
142-
if !ok {
148+
// Try to get NAT rule name
149+
var natRuleName string
150+
if val, ok := resource.SourceAttributes["name"].(string); ok && val != "" {
151+
natRuleName = val
152+
} else if val, ok := resource.SourceAttributes["nat_rule_name"].(string); ok && val != "" {
153+
// Fallback for backward compatibility
154+
natRuleName = val
155+
} else {
143156
return "", fmt.Errorf("[ERROR] unable to find natRuleName for NetworkFirewall NetworkFirewallPolicyNatRule")
144157
}
145-
networkFirewallPolicyId := resource.Parent.Id
158+
146159
return GetNetworkFirewallPolicyNatRuleCompositeId(natRuleName, networkFirewallPolicyId), nil
147160
}
148161

internal/service/network_firewall/network_firewall_network_firewall_policy_nat_rule_data_source.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ func (s *NetworkFirewallNetworkFirewallPolicyNatRuleDataSourceCrud) SetData() er
9494

9595
if v.Name != nil {
9696
s.D.Set("name", *v.Name)
97+
s.D.Set("nat_rule_name", *v.Name)
9798
}
9899

99100
if v.ParentResourceId != nil {

internal/service/network_firewall/network_firewall_network_firewall_policy_nat_rule_resource.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,13 +391,26 @@ func NatRuleSummaryToMap(obj oci_network_firewall.NatRuleSummary) map[string]int
391391
result := map[string]interface{}{}
392392
switch v := (obj).(type) {
393393
case oci_network_firewall.NatV4NatSummary:
394+
if v.Name != nil {
395+
result["name"] = string(*v.Name)
396+
}
397+
394398
result["type"] = "NATV4"
395399

396400
result["action"] = string(v.Action)
397401

402+
if v.ParentResourceId != nil {
403+
result["parent_resource_id"] = string(*v.ParentResourceId)
404+
}
405+
398406
if v.Condition != nil {
399407
result["condition"] = []interface{}{NatRuleMatchCriteriaToMap(v.Condition)}
400408
}
409+
410+
if v.PriorityOrder != nil {
411+
result["priority_order"] = strconv.FormatInt(*v.PriorityOrder, 10)
412+
}
413+
401414
default:
402415
log.Printf("[WARN] Received 'type' of unknown type %v", obj)
403416
return nil

0 commit comments

Comments
 (0)