@@ -40,6 +40,7 @@ import (
4040 "errors"
4141 "fmt"
4242 "regexp"
43+ "strings"
4344
4445 "github.com/hashicorp/terraform-plugin-sdk/helper/schema"
4546)
@@ -64,15 +65,13 @@ func resourceTencentCloudGaapSecurityRule() *schema.Resource {
6465 "cidr_ip" : {
6566 Type : schema .TypeString ,
6667 Required : true ,
67- ForceNew : true ,
6868 ValidateFunc : validateCidrIp ,
6969 Description : "A network address block of the request source." ,
7070 },
7171 "action" : {
7272 Type : schema .TypeString ,
7373 Required : true ,
7474 ValidateFunc : validateAllowedStringValue ([]string {"ACCEPT" , "DROP" }),
75- ForceNew : true ,
7675 Description : "Policy of the rule. Valid value: `ACCEPT` and `DROP`." ,
7776 },
7877 "name" : {
@@ -87,14 +86,12 @@ func resourceTencentCloudGaapSecurityRule() *schema.Resource {
8786 Optional : true ,
8887 Default : "ALL" ,
8988 ValidateFunc : validateAllowedStringValue ([]string {"ALL" , "TCP" , "UDP" }),
90- ForceNew : true ,
9189 Description : "Protocol of the security policy rule. Default value is `ALL`. Valid value: `TCP`, `UDP` and `ALL`." ,
9290 },
9391 "port" : {
9492 Type : schema .TypeString ,
9593 Optional : true ,
9694 Default : "ALL" ,
97- ForceNew : true ,
9895 ValidateFunc : func (v interface {}, k string ) (ws []string , errors []error ) {
9996 value := v .(string )
10097 if value == "ALL" {
@@ -162,7 +159,20 @@ func resourceTencentCloudGaapSecurityRuleRead(d *schema.ResourceData, m interfac
162159 }
163160
164161 _ = d .Set ("policy_id" , rule .PolicyId )
165- _ = d .Set ("cidr_ip" , rule .SourceCidr )
162+
163+ cidrIp := * rule .SourceCidr
164+ // fix when cidr is "x.x.x.x/32", because return will remove /32
165+ if v , ok := d .GetOk ("cidr_ip" ); ok {
166+ getCidrIp := v .(string )
167+ splits := strings .Split (getCidrIp , "/" )
168+ if len (splits ) > 1 {
169+ if splits [1 ] == "32" && cidrIp == splits [0 ] {
170+ cidrIp = fmt .Sprintf ("%s/32" , cidrIp )
171+ }
172+ }
173+ }
174+
175+ _ = d .Set ("cidr_ip" , cidrIp )
166176 _ = d .Set ("action" , rule .Action )
167177 _ = d .Set ("name" , rule .AliasName )
168178 _ = d .Set ("protocol" , rule .Protocol )
@@ -181,15 +191,15 @@ func resourceTencentCloudGaapSecurityRuleUpdate(d *schema.ResourceData, m interf
181191
182192 id := d .Id ()
183193 policyId := d .Get ("policy_id" ).(string )
194+ cidrIp := d .Get ("cidr_ip" ).(string )
195+ action := d .Get ("action" ).(string )
196+ port := d .Get ("port" ).(string )
197+ protocol := d .Get ("protocol" ).(string )
184198 name := d .Get ("name" ).(string )
185199
186- if name == "" {
187- return errors .New ("new name can't be empty" )
188- }
189-
190200 service := GaapService {client : m .(* TencentCloudClient ).apiV3Conn }
191201
192- if err := service .ModifySecurityRuleName (ctx , policyId , id , name ); err != nil {
202+ if err := service .ModifySecurityRule (ctx , policyId , id , cidrIp , action , port , protocol , name ); err != nil {
193203 return err
194204 }
195205
0 commit comments