@@ -50,6 +50,7 @@ func resourceTencentCloudClbFunctionTargetsAttachment() *schema.Resource {
5050 return & schema.Resource {
5151 Create : resourceTencentCloudClbFunctionTargetsAttachmentCreate ,
5252 Read : resourceTencentCloudClbFunctionTargetsAttachmentRead ,
53+ Update : resourceTencentCloudClbFunctionTargetsAttachmentUpdate ,
5354 Delete : resourceTencentCloudClbFunctionTargetsAttachmentDelete ,
5455 Importer : & schema.ResourceImporter {
5556 State : schema .ImportStatePassthrough ,
@@ -71,7 +72,6 @@ func resourceTencentCloudClbFunctionTargetsAttachment() *schema.Resource {
7172
7273 "function_targets" : {
7374 Required : true ,
74- ForceNew : true ,
7575 MaxItems : 1 ,
7676 Type : schema .TypeList ,
7777 Description : "List of cloud functions to be bound." ,
@@ -81,7 +81,7 @@ func resourceTencentCloudClbFunctionTargetsAttachment() *schema.Resource {
8181 Type : schema .TypeList ,
8282 MaxItems : 1 ,
8383 Required : true ,
84- Description : "Information about cloud functions." Note: This field may return null, indicating that no valid value can be obtained." ,
84+ Description : "Information about cloud functions.Note: This field may return null, indicating that no valid value can be obtained." ,
8585 Elem : & schema.Resource {
8686 Schema : map [string ]* schema.Schema {
8787 "function_namespace" : {
@@ -341,6 +341,97 @@ func resourceTencentCloudClbFunctionTargetsAttachmentRead(d *schema.ResourceData
341341 return nil
342342}
343343
344+ func resourceTencentCloudClbFunctionTargetsAttachmentUpdate (d * schema.ResourceData , meta interface {}) error {
345+ defer logElapsed ("resource.tencentcloud_clb_function_targets_attachment.update" )()
346+ defer inconsistentCheck (d , meta )()
347+
348+ logId := getLogId (contextNil )
349+
350+ idSplit := strings .Split (d .Id (), FILED_SP )
351+ var (
352+ request = clb .NewModifyFunctionTargetsRequest ()
353+ loadBalancerId string
354+ listenerId string
355+ locationId string
356+ domain string
357+ url string
358+ )
359+
360+ if len (idSplit ) == 3 {
361+ loadBalancerId = idSplit [0 ]
362+ listenerId = idSplit [1 ]
363+ locationId = idSplit [2 ]
364+ } else if len (idSplit ) == 4 {
365+ loadBalancerId = idSplit [0 ]
366+ listenerId = idSplit [1 ]
367+ domain = idSplit [2 ]
368+ url = idSplit [3 ]
369+ } else {
370+ return fmt .Errorf ("id is broken,%s" , d .Id ())
371+ }
372+
373+ request .LoadBalancerId = helper .String (loadBalancerId )
374+ request .ListenerId = helper .String (listenerId )
375+
376+ if locationId != "" {
377+ request .LocationId = helper .String (locationId )
378+ } else {
379+ request .Url = helper .String (url )
380+ request .Domain = helper .String (domain )
381+ }
382+
383+ if d .HasChange ("function_targets" ) {
384+
385+ if v , ok := d .GetOk ("function_targets" ); ok {
386+ for _ , item := range v .([]interface {}) {
387+ dMap := item .(map [string ]interface {})
388+ functionTarget := clb.FunctionTarget {}
389+ if functionMap , ok := helper .InterfaceToMap (dMap , "function" ); ok {
390+ functionInfo := clb.FunctionInfo {}
391+ if v , ok := functionMap ["function_namespace" ]; ok {
392+ functionInfo .FunctionNamespace = helper .String (v .(string ))
393+ }
394+ if v , ok := functionMap ["function_name" ]; ok {
395+ functionInfo .FunctionName = helper .String (v .(string ))
396+ }
397+ if v , ok := functionMap ["function_qualifier" ]; ok {
398+ functionInfo .FunctionQualifier = helper .String (v .(string ))
399+ }
400+ if v , ok := functionMap ["function_qualifier_type" ]; ok {
401+ functionInfo .FunctionQualifierType = helper .String (v .(string ))
402+ }
403+ functionTarget .Function = & functionInfo
404+ }
405+ if v , ok := dMap ["weight" ]; ok {
406+ functionTarget .Weight = helper .IntUint64 (v .(int ))
407+ }
408+ request .FunctionTargets = append (request .FunctionTargets , & functionTarget )
409+ }
410+ }
411+ }
412+
413+ err := resource .Retry (writeRetryTimeout , func () * resource.RetryError {
414+ result , e := meta .(* TencentCloudClient ).apiV3Conn .UseClbClient ().ModifyFunctionTargets (request )
415+ if e != nil {
416+ return retryError (e )
417+ } else {
418+ log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " , logId , request .GetAction (), request .ToJsonString (), result .ToJsonString ())
419+ requestId := * result .Response .RequestId
420+ retryErr := waitForTaskFinish (requestId , meta .(* TencentCloudClient ).apiV3Conn .UseClbClient ())
421+ if retryErr != nil {
422+ return resource .NonRetryableError (errors .WithStack (retryErr ))
423+ }
424+ }
425+ return nil
426+ })
427+ if err != nil {
428+ log .Printf ("[CRITAL]%s update clb functionTargetsAttachment failed, reason:%+v" , logId , err )
429+ return err
430+ }
431+
432+ return resourceTencentCloudClbFunctionTargetsAttachmentRead (d , meta )
433+ }
434+
344435func resourceTencentCloudClbFunctionTargetsAttachmentDelete (d * schema.ResourceData , meta interface {}) error {
345436 defer logElapsed ("resource.tencentcloud_clb_function_targets_attachment.delete" )()
346437 defer inconsistentCheck (d , meta )()
0 commit comments