Skip to content

Commit

Permalink
Merge pull request #37 from browningluke/fix_firewall_port_type
Browse files Browse the repository at this point in the history
Change os-firewall port type from int to string
  • Loading branch information
browningluke authored Oct 27, 2023
2 parents 4d33b0b + d5976db commit 61a96b3
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 66 deletions.
4 changes: 2 additions & 2 deletions docs/data-sources/firewall_filter.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Read-Only:

- `invert` (Boolean) Use this option to invert the sense of the match.
- `net` (String) Specify the IP address, CIDR or alias for the destination of the packet for this mapping.
- `port` (Number) Specify the port for the destination of the packet for this mapping.
- `port` (String) Specify the port for the destination of the packet for this mapping.


<a id="nestedatt--source"></a>
Expand All @@ -51,5 +51,5 @@ Read-Only:

- `invert` (Boolean) Use this option to invert the sense of the match.
- `net` (String) Specify the IP address, CIDR or alias for the source of the packet for this mapping.
- `port` (Number) Specify the source port for this rule. This is usually random and almost never equal to the destination port range (and should usually be `-1`).
- `port` (String) Specify the source port for this rule. This is usually random and almost never equal to the destination port range (and should usually be `""`).

6 changes: 3 additions & 3 deletions docs/data-sources/firewall_nat.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Read-Only:

- `invert` (Boolean) Use this option to invert the sense of the match.
- `net` (String) Specify the IP address, CIDR or alias for the destination of the packet for this mapping.
- `port` (Number) Specify the port for the destination of the packet for this mapping.
- `port` (String) Specify the port for the destination of the packet for this mapping.


<a id="nestedatt--source"></a>
Expand All @@ -49,7 +49,7 @@ Read-Only:

- `invert` (Boolean) Use this option to invert the sense of the match.
- `net` (String) Specify the IP address, CIDR or alias for the source of the packet for this mapping.
- `port` (Number) Specify the source port for this rule. This is usually random and almost never equal to the destination port range (and should usually be `-1`).
- `port` (String) Specify the source port for this rule. This is usually random and almost never equal to the destination port range (and should usually be `""`).


<a id="nestedatt--target"></a>
Expand All @@ -58,5 +58,5 @@ Read-Only:
Read-Only:

- `ip` (String) Specify the IP address or alias for the packets to be mapped to.
- `port` (Number) Destination port number or well known name (imap, imaps, http, https, ...), for ranges use a dash.
- `port` (String) Destination port number or well known name (imap, imaps, http, https, ...), for ranges use a dash.

10 changes: 5 additions & 5 deletions docs/resources/firewall_filter.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ resource "opnsense_firewall_filter" "example_one" {
destination = {
net = "examplealias"
port = 443
port = "https"
}
log = false
Expand All @@ -59,7 +59,7 @@ resource "opnsense_firewall_filter" "example_two" {
destination = {
net = "10.8.0.1"
port = 443
port = "443"
}
description = "example rule"
Expand All @@ -80,7 +80,7 @@ resource "opnsense_firewall_filter" "example_three" {
destination = {
net = "wanip" # This is equiv. to WAN Address
port = 443
port = "80-443"
}
description = "example rule"
Expand Down Expand Up @@ -121,7 +121,7 @@ Optional:

- `invert` (Boolean) Use this option to invert the sense of the match. Defaults to `false`.
- `net` (String) Specify the IP address, CIDR or alias for the destination of the packet for this mapping. For `<INT> net`, enter `<int>` (e.g. `lan`). For `<INT> address`, enter `<int>ip` (e.g. `lanip`). Defaults to `any`.
- `port` (Number) Destination port number or well known name (imap, imaps, http, https, ...), for ranges use a dash. Defaults to `-1`.
- `port` (String) Destination port number or well known name (imap, imaps, http, https, ...), for ranges use a dash. Defaults to `""`.


<a id="nestedatt--source"></a>
Expand All @@ -131,5 +131,5 @@ Optional:

- `invert` (Boolean) Use this option to invert the sense of the match. Defaults to `false`.
- `net` (String) Specify the IP address, CIDR or alias for the source of the packet for this mapping. For `<INT> net`, enter `<int>` (e.g. `lan`). For `<INT> address`, enter `<int>ip` (e.g. `lanip`). Defaults to `any`.
- `port` (Number) Specify the source port for this rule. This is usually random and almost never equal to the destination port range (and should usually be `-1`). Defaults to `-1`.
- `port` (String) Specify the source port for this rule. This is usually random and almost never equal to the destination port range (and should usually be `""`). Defaults to `""`.

14 changes: 7 additions & 7 deletions docs/resources/firewall_nat.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ resource "opnsense_firewall_nat" "example_two" {
destination = {
net = "10.8.0.1"
port = 443
port = "443"
}
target = {
ip = "wanip"
port = 80
port = "http"
}
log = true
Expand All @@ -63,12 +63,12 @@ resource "opnsense_firewall_nat" "example_three" {
destination = {
net = "examplealias"
port = 443
port = "80-443"
}
target = {
ip = "wanip"
port = 443
port = "443"
}
description = "Example"
Expand Down Expand Up @@ -108,7 +108,7 @@ Required:

Optional:

- `port` (Number) Destination port number or well known name (imap, imaps, http, https, ...), for ranges use a dash. Defaults to `-1`.
- `port` (String) Destination port number or well known name (imap, imaps, http, https, ...), for ranges use a dash. Defaults to `""`.


<a id="nestedatt--destination"></a>
Expand All @@ -118,7 +118,7 @@ Optional:

- `invert` (Boolean) Use this option to invert the sense of the match. Defaults to `false`.
- `net` (String) Specify the IP address, CIDR or alias for the destination of the packet for this mapping. For `<INT> net`, enter `<int>` (e.g. `lan`). For `<INT> address`, enter `<int>ip` (e.g. `lanip`). Defaults to `any`.
- `port` (Number) Destination port number or well known name (imap, imaps, http, https, ...), for ranges use a dash. Defaults to `-1`.
- `port` (String) Destination port number or well known name (imap, imaps, http, https, ...), for ranges use a dash. Defaults to `""`.


<a id="nestedatt--source"></a>
Expand All @@ -128,5 +128,5 @@ Optional:

- `invert` (Boolean) Use this option to invert the sense of the match. Defaults to `false`.
- `net` (String) Specify the IP address, CIDR or alias for the source of the packet for this mapping. For `<INT> net`, enter `<int>` (e.g. `lan`). For `<INT> address`, enter `<int>ip` (e.g. `lanip`). Defaults to `any`.
- `port` (Number) Specify the source port for this rule. This is usually random and almost never equal to the destination port range (and should usually be `-1`). Defaults to `-1`.
- `port` (String) Specify the source port for this rule. This is usually random and almost never equal to the destination port range (and should usually be `""`). Defaults to `""`.

6 changes: 3 additions & 3 deletions examples/resources/opnsense_firewall_filter/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ resource "opnsense_firewall_filter" "example_one" {

destination = {
net = "examplealias"
port = 443
port = "https"
}

log = false
Expand All @@ -43,7 +43,7 @@ resource "opnsense_firewall_filter" "example_two" {

destination = {
net = "10.8.0.1"
port = 443
port = "443"
}

description = "example rule"
Expand All @@ -64,7 +64,7 @@ resource "opnsense_firewall_filter" "example_three" {

destination = {
net = "wanip" # This is equiv. to WAN Address
port = 443
port = "80-443"
}

description = "example rule"
Expand Down
8 changes: 4 additions & 4 deletions examples/resources/opnsense_firewall_nat/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ resource "opnsense_firewall_nat" "example_two" {

destination = {
net = "10.8.0.1"
port = 443
port = "443"
}

target = {
ip = "wanip"
port = 80
port = "http"
}

log = true
Expand All @@ -47,12 +47,12 @@ resource "opnsense_firewall_nat" "example_three" {

destination = {
net = "examplealias"
port = 443
port = "80-443"
}

target = {
ip = "wanip"
port = 443
port = "443"
}

description = "Example"
Expand Down
44 changes: 26 additions & 18 deletions internal/service/firewall_filter_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

type firewallLocation struct {
Net types.String `tfsdk:"net"`
Port types.Int64 `tfsdk:"port"`
Port types.String `tfsdk:"port"`
Invert types.Bool `tfsdk:"invert"`
}

Expand Down Expand Up @@ -117,12 +117,12 @@ func FirewallFilterResourceSchema() schema.Schema {
types.ObjectValueMust(
map[string]attr.Type{
"net": types.StringType,
"port": types.Int64Type,
"port": types.StringType,
"invert": types.BoolType,
},
map[string]attr.Value{
"net": types.StringValue("any"),
"port": types.Int64Value(-1),
"port": types.StringValue(""),
"invert": types.BoolValue(false),
},
),
Expand All @@ -134,11 +134,15 @@ func FirewallFilterResourceSchema() schema.Schema {
Computed: true,
Default: stringdefault.StaticString("any"),
},
"port": schema.Int64Attribute{
MarkdownDescription: "Specify the source port for this rule. This is usually random and almost never equal to the destination port range (and should usually be `-1`). Defaults to `-1`.",
"port": schema.StringAttribute{
MarkdownDescription: "Specify the source port for this rule. This is usually random and almost never equal to the destination port range (and should usually be `\"\"`). Defaults to `\"\"`.",
Optional: true,
Computed: true,
Default: int64default.StaticInt64(-1),
Default: stringdefault.StaticString(""),
Validators: []validator.String{
stringvalidator.RegexMatches(regexp.MustCompile("^(\\d|-)+$|^([a-z])+$"),
"must be number (80), range (80-443) or well known name (http)"),
},
},
"invert": schema.BoolAttribute{
MarkdownDescription: "Use this option to invert the sense of the match. Defaults to `false`.",
Expand All @@ -155,12 +159,12 @@ func FirewallFilterResourceSchema() schema.Schema {
types.ObjectValueMust(
map[string]attr.Type{
"net": types.StringType,
"port": types.Int64Type,
"port": types.StringType,
"invert": types.BoolType,
},
map[string]attr.Value{
"net": types.StringValue("any"),
"port": types.Int64Value(-1),
"port": types.StringValue(""),
"invert": types.BoolValue(false),
},
),
Expand All @@ -172,11 +176,15 @@ func FirewallFilterResourceSchema() schema.Schema {
Computed: true,
Default: stringdefault.StaticString("any"),
},
"port": schema.Int64Attribute{
MarkdownDescription: "Destination port number or well known name (imap, imaps, http, https, ...), for ranges use a dash. Defaults to `-1`.",
"port": schema.StringAttribute{
MarkdownDescription: "Destination port number or well known name (imap, imaps, http, https, ...), for ranges use a dash. Defaults to `\"\"`.",
Optional: true,
Computed: true,
Default: int64default.StaticInt64(-1),
Default: stringdefault.StaticString(""),
Validators: []validator.String{
stringvalidator.RegexMatches(regexp.MustCompile("^(\\d|-)+$|^([a-z])+$"),
"must be number (80), range (80-443) or well known name (http)"),
},
},
"invert": schema.BoolAttribute{
MarkdownDescription: "Use this option to invert the sense of the match. Defaults to `false`.",
Expand Down Expand Up @@ -262,8 +270,8 @@ func FirewallFilterDataSourceSchema() dschema.Schema {
MarkdownDescription: "Specify the IP address, CIDR or alias for the source of the packet for this mapping.",
Computed: true,
},
"port": dschema.Int64Attribute{
MarkdownDescription: "Specify the source port for this rule. This is usually random and almost never equal to the destination port range (and should usually be `-1`).",
"port": dschema.StringAttribute{
MarkdownDescription: "Specify the source port for this rule. This is usually random and almost never equal to the destination port range (and should usually be `\"\"`).",
Computed: true,
},
"invert": dschema.BoolAttribute{
Expand All @@ -279,7 +287,7 @@ func FirewallFilterDataSourceSchema() dschema.Schema {
MarkdownDescription: "Specify the IP address, CIDR or alias for the destination of the packet for this mapping.",
Computed: true,
},
"port": dschema.Int64Attribute{
"port": dschema.StringAttribute{
MarkdownDescription: "Specify the port for the destination of the packet for this mapping.",
Computed: true,
},
Expand Down Expand Up @@ -327,10 +335,10 @@ func convertFirewallFilterSchemaToStruct(d *FirewallFilterResourceModel) (*firew
IPProtocol: api.SelectedMap(d.IPProtocol.ValueString()),
Protocol: api.SelectedMap(d.Protocol.ValueString()),
SourceNet: d.Source.Net.ValueString(),
SourcePort: tools.Int64ToStringNegative(d.Source.Port.ValueInt64()),
SourcePort: d.Source.Port.ValueString(),
SourceInvert: tools.BoolToString(d.Source.Invert.ValueBool()),
DestinationNet: d.Destination.Net.ValueString(),
DestinationPort: tools.Int64ToStringNegative(d.Destination.Port.ValueInt64()),
DestinationPort: d.Destination.Port.ValueString(),
DestinationInvert: tools.BoolToString(d.Destination.Invert.ValueBool()),
Gateway: api.SelectedMap(d.Gateway.ValueString()),
Log: tools.BoolToString(d.Log.ValueBool()),
Expand All @@ -350,12 +358,12 @@ func convertFirewallFilterStructToSchema(d *firewall.Filter) (*FirewallFilterRes
Protocol: types.StringValue(d.Protocol.String()),
Source: &firewallLocation{
Net: types.StringValue(d.SourceNet),
Port: types.Int64Value(tools.StringToInt64(d.SourcePort)),
Port: types.StringValue(d.SourcePort),
Invert: types.BoolValue(tools.StringToBool(d.SourceInvert)),
},
Destination: &firewallLocation{
Net: types.StringValue(d.DestinationNet),
Port: types.Int64Value(tools.StringToInt64(d.DestinationPort)),
Port: types.StringValue(d.DestinationPort),
Invert: types.BoolValue(tools.StringToBool(d.DestinationInvert)),
},
Gateway: types.StringValue(d.Gateway.String()),
Expand Down
Loading

0 comments on commit 61a96b3

Please sign in to comment.