Skip to content

Commit

Permalink
feat: secgroup rule supports description setting (#921)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lance52259 authored Feb 19, 2021
1 parent bc389e2 commit b24eedd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
6 changes: 6 additions & 0 deletions docs/resources/networking_secgroup_rule.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ The following arguments are supported:
type, valid values are __IPv4__ or __IPv6__.
Changing this creates a new security group rule.

* `description` - (Optional, String, ForceNew) Specifies the supplementary
information about the networking security group rule.
This parameter can contain a maximum of 255 characters and cannot contain
angle brackets (< or >).
Changing this creates a new security group rule.

* `protocol` - (Optional, String, ForceNew) Specifies the layer 4 protocol
type, valid values are following. This is required if you want to specify
a port range.
Expand Down
11 changes: 9 additions & 2 deletions huaweicloud/resource_huaweicloud_networking_secgroup_rule_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ func ResourceNetworkingSecGroupRuleV2() *schema.Resource {
"IPv4", "IPv6",
}, true),
},
"security_group_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"port_range_min": {
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -84,9 +89,9 @@ func ResourceNetworkingSecGroupRuleV2() *schema.Resource {
return strings.ToLower(v.(string))
},
},
"security_group_id": {
"description": {
Type: schema.TypeString,
Required: true,
Optional: true,
ForceNew: true,
},
"tenant_id": {
Expand Down Expand Up @@ -118,6 +123,7 @@ func resourceNetworkingSecGroupRuleV2Create(d *schema.ResourceData, meta interfa
}

opts := rules.CreateOpts{
Description: d.Get("description").(string),
SecGroupID: d.Get("security_group_id").(string),
PortRangeMin: d.Get("port_range_min").(int),
PortRangeMax: d.Get("port_range_max").(int),
Expand Down Expand Up @@ -171,6 +177,7 @@ func resourceNetworkingSecGroupRuleV2Read(d *schema.ResourceData, meta interface
}

d.Set("direction", security_group_rule.Direction)
d.Set("description", security_group_rule.Description)
d.Set("ethertype", security_group_rule.EtherType)
d.Set("protocol", security_group_rule.Protocol)
d.Set("port_range_min", security_group_rule.PortRangeMin)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func TestAccNetworkingV2SecGroupRule_basic(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckNetworkingV2SecGroupRuleExists(resourceRuleName, &secgroupRule),
resource.TestCheckResourceAttr(resourceRuleName, "direction", "ingress"),
resource.TestCheckResourceAttr(resourceRuleName, "description", "This is a basic acc test"),
resource.TestCheckResourceAttr(resourceRuleName, "port_range_min", "80"),
resource.TestCheckResourceAttr(resourceRuleName, "port_range_max", "80"),
resource.TestCheckResourceAttr(resourceRuleName, "ethertype", "IPv4"),
Expand Down Expand Up @@ -192,6 +193,7 @@ func testAccNetworkingV2SecGroupRule_basic(rName string) string {
resource "huaweicloud_networking_secgroup_rule" "secgroup_rule_test" {
direction = "ingress"
description = "This is a basic acc test"
ethertype = "IPv4"
port_range_max = 80
port_range_min = 80
Expand Down

0 comments on commit b24eedd

Please sign in to comment.