Skip to content

Commit d632d66

Browse files
tongyimingmikatong
andauthored
fix: vpc_sg_rule support policy_index (#1208)
Co-authored-by: mikatong <[email protected]>
1 parent ed16d39 commit d632d66

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

tencentcloud/resource_tc_security_group_rule.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,12 @@ func resourceTencentCloudSecurityGroupRule() *schema.Resource {
140140
ValidateFunc: validateAllowedStringValueIgnoreCase([]string{"ACCEPT", "DROP"}),
141141
Description: "Rule policy of security group. Valid values: `ACCEPT` and `DROP`.",
142142
},
143+
"policy_index": {
144+
Type: schema.TypeInt,
145+
Optional: true,
146+
Computed: true,
147+
Description: "The security group rule index number, the value of which dynamically changes as the security group rule changes.",
148+
},
143149
"source_sgid": {
144150
Type: schema.TypeString,
145151
Optional: true,
@@ -304,7 +310,10 @@ func resourceTencentCloudSecurityGroupRuleCreate(d *schema.ResourceData, m inter
304310
return errors.New("when ip_protocol is ICMP, can't set port_range")
305311
}
306312
}
307-
313+
var policyIndex int64
314+
if v, ok := d.GetOk("policy_index"); ok {
315+
policyIndex = v.(int64)
316+
}
308317
info := securityGroupRuleBasicInfo{
309318
SgId: sgId,
310319
Action: action,
@@ -318,6 +327,7 @@ func resourceTencentCloudSecurityGroupRuleCreate(d *schema.ResourceData, m inter
318327
AddressTemplateGroupId: addressTemplateGroupId,
319328
ProtocolTemplateId: protocolTemplateId,
320329
ProtocolTemplateGroupId: protocolTemplateGroupId,
330+
PolicyIndex: policyIndex,
321331
}
322332

323333
ruleId, err := service.CreateSecurityGroupPolicy(ctx, info)
@@ -402,7 +412,9 @@ func resourceTencentCloudSecurityGroupRuleRead(d *schema.ResourceData, m interfa
402412
}
403413
_ = d.Set("ip_protocol", inputProtocol)
404414
}
405-
415+
if policy.PolicyIndex != nil {
416+
_ = d.Set("policy_index", *policy.PolicyIndex)
417+
}
406418
if policy.Port != nil && *policy.Port != "" {
407419
_ = d.Set("port_range", *policy.Port)
408420
}

tencentcloud/resource_tc_security_group_rule_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func TestAccTencentCloudSecurityGroupRule_basic(t *testing.T) {
2727
resource.TestCheckResourceAttr("tencentcloud_security_group_rule.http-in", "ip_protocol", "tcp"),
2828
resource.TestCheckResourceAttr("tencentcloud_security_group_rule.http-in", "description", ""),
2929
resource.TestCheckResourceAttr("tencentcloud_security_group_rule.http-in", "type", "ingress"),
30+
resource.TestCheckResourceAttr("tencentcloud_security_group_rule.http-in", "policy_index", "0"),
3031
resource.TestCheckNoResourceAttr("tencentcloud_security_group_rule.http-in", "source_sgid"),
3132
),
3233
},
@@ -251,6 +252,7 @@ resource "tencentcloud_security_group_rule" "http-in" {
251252
ip_protocol = "tcp"
252253
port_range = "80,8080"
253254
policy = "accept"
255+
policy_index = 0
254256
}
255257
`
256258

tencentcloud/service_tencentcloud_vpc.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1285,7 +1285,9 @@ func (me *VpcService) CreateSecurityGroupPolicy(ctx context.Context, info securi
12851285
if info.Protocol != nil {
12861286
policy.Protocol = common.StringPtr(strings.ToUpper(*info.Protocol))
12871287
}
1288-
1288+
if policy.PolicyIndex != nil {
1289+
policy.PolicyIndex = helper.Int64(info.PolicyIndex)
1290+
}
12891291
policy.Port = info.PortRange
12901292
policy.PolicyDescription = info.Description
12911293
policy.Action = common.StringPtr(strings.ToUpper(info.Action))
@@ -1751,6 +1753,7 @@ type securityGroupRuleBasicInfo struct {
17511753
AddressTemplateGroupId *string `json:"address_template_group_id,omitempty"`
17521754
ProtocolTemplateId *string `json:"protocol_template_id,omitempty"`
17531755
ProtocolTemplateGroupId *string `json:"protocol_template_group_id,omitempty"`
1756+
PolicyIndex int64 `json:"policy_index"`
17541757
}
17551758

17561759
// Build an ID for a Security Group Rule (new version)

website/docs/r/security_group_rule.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ The following arguments are supported:
7070
* `cidr_ip` - (Optional, String, ForceNew) An IP address network or segment, and conflict with `source_sgid` and `address_template`.
7171
* `description` - (Optional, String, ForceNew) Description of the security group rule.
7272
* `ip_protocol` - (Optional, String, ForceNew) Type of IP protocol. Valid values: `TCP`, `UDP` and `ICMP`. Default to all types protocol, and conflicts with `protocol_template`.
73+
* `policy_index` - (Optional, Int) The security group rule index number, the value of which dynamically changes as the security group rule changes.
7374
* `port_range` - (Optional, String, ForceNew) Range of the port. The available value can be one, multiple or one segment. E.g. `80`, `80,90` and `80-90`. Default to all ports, and confilicts with `protocol_template`.
7475
* `protocol_template` - (Optional, List, ForceNew) ID of the address template, and conflict with `ip_protocol`, `port_range`.
7576
* `source_sgid` - (Optional, String, ForceNew) ID of the nested security group, and conflicts with `cidr_ip` and `address_template`.

0 commit comments

Comments
 (0)