@@ -5,9 +5,9 @@ Example Usage
55
66```hcl
77resource "tencentcloud_tsf_api_rate_limit_rule" "api_rate_limit_rule" {
8- api_id = ""
9- max_qps =
10- usable_status = ""
8+ api_id = "api-xxxxxx "
9+ max_qps = 10
10+ usable_status = "enable "
1111}
1212```
1313
@@ -56,10 +56,11 @@ func resourceTencentCloudTsfApiRateLimitRule() *schema.Resource {
5656 },
5757
5858 "usable_status" : {
59- Optional : true ,
60- Computed : true ,
61- Type : schema .TypeString ,
62- Description : "Enable/disable, enabled/disabled, if not passed, it is enabled by default." ,
59+ Optional : true ,
60+ Computed : true ,
61+ Type : schema .TypeString ,
62+ ValidateFunc : validateAllowedStringValue ([]string {"enabled" , "disabled" }),
63+ Description : "Enabled/disabled, enabled/disabled, if not passed, it is enabled by default." ,
6364 },
6465
6566 "rule_id" : {
@@ -114,10 +115,10 @@ func resourceTencentCloudTsfApiRateLimitRuleCreate(d *schema.ResourceData, meta
114115 logId := getLogId (contextNil )
115116
116117 var (
117- request = tsf .NewCreateApiRateLimitRuleRequest ()
118- // response = tsf.NewCreateApiRateLimitRuleResponse ()
119- apiId string
120- ruleId string
118+ request = tsf .NewCreateApiRateLimitRuleWithDetailRespRequest ()
119+ response = tsf .NewCreateApiRateLimitRuleWithDetailRespResponse ()
120+ apiId string
121+ ruleId string
121122 )
122123 if v , ok := d .GetOk ("api_id" ); ok {
123124 apiId = v .(string )
@@ -133,21 +134,21 @@ func resourceTencentCloudTsfApiRateLimitRuleCreate(d *schema.ResourceData, meta
133134 }
134135
135136 err := resource .Retry (writeRetryTimeout , func () * resource.RetryError {
136- result , e := meta .(* TencentCloudClient ).apiV3Conn .UseTsfClient ().CreateApiRateLimitRule (request )
137+ result , e := meta .(* TencentCloudClient ).apiV3Conn .UseTsfClient ().CreateApiRateLimitRuleWithDetailResp (request )
137138 if e != nil {
138139 return retryError (e )
139140 } else {
140141 log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " , logId , request .GetAction (), request .ToJsonString (), result .ToJsonString ())
141142 }
142- // response = result
143+ response = result
143144 return nil
144145 })
145146 if err != nil {
146147 log .Printf ("[CRITAL]%s create tsf apiRateLimitRule failed, reason:%+v" , logId , err )
147148 return err
148149 }
149150
150- // ruleId = *response.Response.RuleId
151+ ruleId = * response .Response . Result .RuleId
151152 d .SetId (apiId + FILED_SP + ruleId )
152153
153154 return resourceTencentCloudTsfApiRateLimitRuleRead (d , meta )
@@ -241,7 +242,7 @@ func resourceTencentCloudTsfApiRateLimitRuleUpdate(d *schema.ResourceData, meta
241242
242243 request .RuleId = & ruleId
243244
244- immutableArgs := []string {"api_id" , "max_qps" , "usable_status" , "result" }
245+ immutableArgs := []string {"api_id" }
245246
246247 for _ , v := range immutableArgs {
247248 if d .HasChange (v ) {
@@ -282,20 +283,20 @@ func resourceTencentCloudTsfApiRateLimitRuleDelete(d *schema.ResourceData, meta
282283 defer logElapsed ("resource.tencentcloud_tsf_api_rate_limit_rule.delete" )()
283284 defer inconsistentCheck (d , meta )()
284285
285- // logId := getLogId(contextNil)
286- // ctx := context.WithValue(context.TODO(), logIdKey, logId)
286+ logId := getLogId (contextNil )
287+ ctx := context .WithValue (context .TODO (), logIdKey , logId )
287288
288- // service := TsfService{client: meta.(*TencentCloudClient).apiV3Conn}
289- // idSplit := strings.Split(d.Id(), FILED_SP)
290- // if len(idSplit) != 2 {
291- // return fmt.Errorf("id is broken,%s", d.Id())
292- // }
293- // apiId := idSplit[0]
294- // ruleId := idSplit[1]
289+ service := TsfService {client : meta .(* TencentCloudClient ).apiV3Conn }
290+ idSplit := strings .Split (d .Id (), FILED_SP )
291+ if len (idSplit ) != 2 {
292+ return fmt .Errorf ("id is broken,%s" , d .Id ())
293+ }
294+ apiId := idSplit [0 ]
295+ ruleId := idSplit [1 ]
295296
296- // if err := service.DeleteTsfApiRateLimitRuleById(ctx, apiId, ruleId); err != nil {
297- // return err
298- // }
297+ if err := service .DeleteTsfApiRateLimitRuleById (ctx , apiId , ruleId ); err != nil {
298+ return err
299+ }
299300
300301 return nil
301302}
0 commit comments