Skip to content

Commit 8f37062

Browse files
authored
Resolve Issue #278 and #279 (#281)
1 parent fdbdb59 commit 8f37062

6 files changed

+43
-12
lines changed

docs/data-sources/zone_based_firewall_policy_definition.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ Read-Only:
6969
Read-Only:
7070

7171
- `policy_id` (String) policy id for selected match entry
72+
- `protocol_type` (String) Should be included with additionally entries for `destinationPort` and `protocol` whenever the type `protocolName` is used.
7273
- `type` (String) Type of match entry
7374
- `value` (String) value for selected match entry
7475
- `value_variable` (String) variable value for selected match entry if it has variable option (sourceIp & destinationIp)

docs/resources/zone_based_firewall_policy_definition.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,22 @@ Required:
8080

8181
- `base_action` (String) Base action
8282
- Choices: `pass`, `drop`, `inspect`
83-
- `match_entries` (Attributes List) List of match entries (see [below for nested schema](#nestedatt--rules--match_entries))
8483
- `rule_name` (String) Rule name
8584
- `rule_order` (Number) Rule
8685

8786
Optional:
8887

8988
- `action_entries` (Attributes List) List of actions entries (see [below for nested schema](#nestedatt--rules--action_entries))
89+
- `match_entries` (Attributes List) List of match entries (see [below for nested schema](#nestedatt--rules--match_entries))
90+
91+
<a id="nestedatt--rules--action_entries"></a>
92+
### Nested Schema for `rules.action_entries`
93+
94+
Optional:
95+
96+
- `type` (String) Type of action entry
97+
- Choices: `log`, `connectionEvents`
98+
9099

91100
<a id="nestedatt--rules--match_entries"></a>
92101
### Nested Schema for `rules.match_entries`
@@ -99,18 +108,10 @@ Required:
99108
Optional:
100109

101110
- `policy_id` (String) policy id for selected match entry
111+
- `protocol_type` (String) Should be included with additionally entries for `destinationPort` and `protocol` whenever the type `protocolName` is used.
102112
- `value` (String) value for selected match entry
103113
- `value_variable` (String) variable value for selected match entry if it has variable option (sourceIp & destinationIp)
104114

105-
106-
<a id="nestedatt--rules--action_entries"></a>
107-
### Nested Schema for `rules.action_entries`
108-
109-
Optional:
110-
111-
- `type` (String) Type of action entry
112-
- Choices: `log`, `connectionEvents`
113-
114115
## Import
115116

116117
Import is supported using the following syntax:

gen/definitions/generic/zone_based_firewall_policy_definition.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ attributes:
8585
tf_name: match_entries
8686
data_path: [match]
8787
type: List
88-
mandatory: true
8988
min_list: 1
9089
description: List of match entries
9190
attributes:
@@ -109,6 +108,12 @@ attributes:
109108
description: value for selected match entry
110109
exclude_test: true
111110
example: 2
111+
- model_name: app
112+
tf_name: protocol_type
113+
type: String
114+
description: Should be included with additionally entries for `destinationPort` and `protocol` whenever the type `protocolName` is used.
115+
exclude_test: true
116+
example: dns
112117
- model_name: vipVariableName
113118
tf_name: value_variable
114119
type: String
@@ -118,6 +123,7 @@ attributes:
118123
- model_name: actions
119124
tf_name: action_entries
120125
type: List
126+
min_list: 1
121127
description: List of actions entries
122128
attributes:
123129
- model_name: type

internal/provider/data_source_sdwan_zone_based_firewall_policy_definition.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ func (d *ZoneBasedFirewallPolicyDefinitionDataSource) Schema(ctx context.Context
131131
MarkdownDescription: "value for selected match entry",
132132
Computed: true,
133133
},
134+
"protocol_type": schema.StringAttribute{
135+
MarkdownDescription: "Should be included with additionally entries for `destinationPort` and `protocol` whenever the type `protocolName` is used.",
136+
Computed: true,
137+
},
134138
"value_variable": schema.StringAttribute{
135139
MarkdownDescription: "variable value for selected match entry if it has variable option (sourceIp & destinationIp)",
136140
Computed: true,

internal/provider/model_sdwan_zone_based_firewall_policy_definition.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ type ZoneBasedFirewallPolicyDefinitionRulesMatchEntries struct {
5757
Type types.String `tfsdk:"type"`
5858
PolicyId types.String `tfsdk:"policy_id"`
5959
Value types.String `tfsdk:"value"`
60+
ProtocolType types.String `tfsdk:"protocol_type"`
6061
ValueVariable types.String `tfsdk:"value_variable"`
6162
}
6263
type ZoneBasedFirewallPolicyDefinitionRulesActionEntries struct {
@@ -132,6 +133,9 @@ func (data ZoneBasedFirewallPolicyDefinition) toBody(ctx context.Context) string
132133
if !childItem.Value.IsNull() {
133134
itemChildBody, _ = sjson.Set(itemChildBody, "value", childItem.Value.ValueString())
134135
}
136+
if !childItem.ProtocolType.IsNull() {
137+
itemChildBody, _ = sjson.Set(itemChildBody, "app", childItem.ProtocolType.ValueString())
138+
}
135139
if !childItem.ValueVariable.IsNull() {
136140
itemChildBody, _ = sjson.Set(itemChildBody, "vipVariableName", childItem.ValueVariable.ValueString())
137141
}
@@ -238,6 +242,11 @@ func (data *ZoneBasedFirewallPolicyDefinition) fromBody(ctx context.Context, res
238242
} else {
239243
cItem.Value = types.StringNull()
240244
}
245+
if ccValue := cv.Get("app"); ccValue.Exists() {
246+
cItem.ProtocolType = types.StringValue(ccValue.String())
247+
} else {
248+
cItem.ProtocolType = types.StringNull()
249+
}
241250
if ccValue := cv.Get("vipVariableName"); ccValue.Exists() {
242251
cItem.ValueVariable = types.StringValue(ccValue.String())
243252
} else {
@@ -333,6 +342,9 @@ func (data *ZoneBasedFirewallPolicyDefinition) hasChanges(ctx context.Context, s
333342
if !data.Rules[i].MatchEntries[ii].Value.Equal(state.Rules[i].MatchEntries[ii].Value) {
334343
hasChanges = true
335344
}
345+
if !data.Rules[i].MatchEntries[ii].ProtocolType.Equal(state.Rules[i].MatchEntries[ii].ProtocolType) {
346+
hasChanges = true
347+
}
336348
if !data.Rules[i].MatchEntries[ii].ValueVariable.Equal(state.Rules[i].MatchEntries[ii].ValueVariable) {
337349
hasChanges = true
338350
}

internal/provider/resource_sdwan_zone_based_firewall_policy_definition.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func (r *ZoneBasedFirewallPolicyDefinitionResource) Schema(ctx context.Context,
140140
},
141141
"match_entries": schema.ListNestedAttribute{
142142
MarkdownDescription: helpers.NewAttributeDescription("List of match entries").String,
143-
Required: true,
143+
Optional: true,
144144
NestedObject: schema.NestedAttributeObject{
145145
Attributes: map[string]schema.Attribute{
146146
"type": schema.StringAttribute{
@@ -158,6 +158,10 @@ func (r *ZoneBasedFirewallPolicyDefinitionResource) Schema(ctx context.Context,
158158
MarkdownDescription: helpers.NewAttributeDescription("value for selected match entry").String,
159159
Optional: true,
160160
},
161+
"protocol_type": schema.StringAttribute{
162+
MarkdownDescription: helpers.NewAttributeDescription("Should be included with additionally entries for `destinationPort` and `protocol` whenever the type `protocolName` is used.").String,
163+
Optional: true,
164+
},
161165
"value_variable": schema.StringAttribute{
162166
MarkdownDescription: helpers.NewAttributeDescription("variable value for selected match entry if it has variable option (sourceIp & destinationIp)").String,
163167
Optional: true,
@@ -182,6 +186,9 @@ func (r *ZoneBasedFirewallPolicyDefinitionResource) Schema(ctx context.Context,
182186
},
183187
},
184188
},
189+
Validators: []validator.List{
190+
listvalidator.SizeAtLeast(1),
191+
},
185192
},
186193
},
187194
},

0 commit comments

Comments
 (0)