Skip to content
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

Expose source port of firewall rules #305

Merged
merged 2 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions internal/provider/resource_firewall_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ func resourceFirewallRule() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"src_port": {
Description: "The source port of the firewall rule.",
Type: schema.TypeString,
Optional: true,
ValidateFunc: validatePortRange,
},
"src_mac": {
Description: "The source MAC address of the firewall rule.",
Type: schema.TypeString,
Expand Down Expand Up @@ -257,6 +263,7 @@ func resourceFirewallRuleGetResourceData(d *schema.ResourceData) (*unifi.Firewal
SrcMACAddress: d.Get("src_mac").(string),
SrcAddress: d.Get("src_address").(string),
SrcAddressIPV6: d.Get("src_address_ipv6").(string),
SrcPort: d.Get("src_port").(string),
SrcNetworkID: d.Get("src_network_id").(string),
SrcFirewallGroupIDs: srcFirewallGroupIDs,

Expand Down Expand Up @@ -292,6 +299,7 @@ func resourceFirewallRuleSetResourceData(resp *unifi.FirewallRule, d *schema.Res
d.Set("src_address", resp.SrcAddress)
d.Set("src_address_ipv6", resp.SrcAddressIPV6)
d.Set("src_network_id", resp.SrcNetworkID)
d.Set("src_port", resp.SrcPort)

d.Set("dst_network_type", resp.DstNetworkType)
d.Set("dst_firewall_group_ids", stringSliceToSet(resp.DstFirewallGroupIDs))
Expand Down
7 changes: 6 additions & 1 deletion internal/provider/resource_firewall_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ func TestAccFirewallRule_basic(t *testing.T) {
})
}

func TestAccFirewallRule_dst_port(t *testing.T) {
func TestAccFirewallRule_port(t *testing.T) {
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { preCheck(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: testAccFirewallRuleConfigWithPort,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("unifi_firewall_rule.test", "src_port", "123"),
resource.TestCheckResourceAttr("unifi_firewall_rule.test", "dst_port", "53"),
),
},
importStep("unifi_firewall_rule.test"),
},
Expand Down Expand Up @@ -159,6 +163,7 @@ resource "unifi_firewall_rule" "test" {
protocol = "tcp"

src_address = "192.168.3.3"
src_port = 123
dst_address = "192.168.1.1"
dst_port = 53
}
Expand Down