Skip to content

Commit 2f62c50

Browse files
authored
Merge pull request #1561 from tencentcloudstack/feat/clb_scf_attach_supoort_update
clb attach scf support update
2 parents 378931e + 260206a commit 2f62c50

File tree

12 files changed

+310
-16
lines changed

12 files changed

+310
-16
lines changed

.changelog/1561.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_clb_function_targets_attachment: support update function targets.
3+
```

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ require (
3232
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdn v1.0.539
3333
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfs v1.0.581
3434
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ckafka v1.0.403
35-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.591
35+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.599
3636
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.544
3737
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.412
38-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.593
38+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.599
3939
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.553
4040
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.589
4141
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.572

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ckafka v1.0.403 h1:rD9H
476476
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ckafka v1.0.403/go.mod h1:yWwwGj2gV0hRPfM9GXG4EgDee0cEWYcAwl/M8CTTvzM=
477477
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.591 h1:Rg1AD/9y3pwo7iQ//YwylFrQYsjFcYMCESA6XDkzlvI=
478478
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.591/go.mod h1:V/OfxmhJ/kic0QZzdl82fSREd2fuQ1VQqjVEYdsgQRE=
479+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.599 h1:f4EuaKvy96oL1qptD1wRtq/CW3fSU1nqqyKNRNTAn0s=
480+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.599/go.mod h1:25iHVjMmqlOBynJjf/zyV4Bub1VewvMr/QjwQUU39Pg=
479481
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.544 h1:ApY6rS7I9otgujOdAFy0+Epno1PNVCQmsOoWQxx724Y=
480482
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.544/go.mod h1:c37rIdL3LrJXYwrfp9c8L4MabTqKIZUe1xvnWhN75oc=
481483
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.412 h1:mQbC16tarrfz+ILlHTMiiA3MTUP79fSqs+KEpuL2FKE=
@@ -523,6 +525,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.591 h1:tb1w
523525
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.591/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
524526
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.593 h1:VjzQDGDVnKJDKtt/tzD4gAvzulnY3lDZqH+gOIggbu8=
525527
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.593/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
528+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.599 h1:9rMFA8++HynZHYz32gAluJ2ONtz7NjhlBaiomVHWwdw=
529+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.599/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
526530
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.553 h1:Pl1kYgFhJp0QSoVFSzRsiGk+HfEAkBTQg7+O60tytNA=
527531
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.553/go.mod h1:dnnqPxXYK+kax3e1MKo/PI3iWJtytm6ogWKQHJS7SGE=
528532
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.589 h1:LZihgirMH0vsaGScYexxwY0fTss9vHaSZs/YOQUVESg=

tencentcloud/common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ var retryableErrorCode = []string{
7373
"ClientError.NetworkError",
7474
"ClientError.HttpStatusCodeError",
7575
// common
76-
"FailedOperation",
76+
//"FailedOperation",
7777
"TradeUnknownError",
7878
"RequestLimitExceeded",
7979
"ResourceInUse",

tencentcloud/resource_tc_clb_function_targets_attachment.go

Lines changed: 93 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
344435
func resourceTencentCloudClbFunctionTargetsAttachmentDelete(d *schema.ResourceData, meta interface{}) error {
345436
defer logElapsed("resource.tencentcloud_clb_function_targets_attachment.delete")()
346437
defer inconsistentCheck(d, meta)()

tencentcloud/resource_tc_clb_function_targets_attachment_test.go

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,16 @@ func TestAccTencentCloudClbFunctionTargetsAttachmentResource_basic(t *testing.T)
1616
Steps: []resource.TestStep{
1717
{
1818
Config: testAccClbFunctionTargetsAttachment,
19-
Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_clb_function_targets_attachment.function_targets", "id")),
19+
Check: resource.ComposeTestCheckFunc(
20+
resource.TestCheckResourceAttrSet("tencentcloud_clb_function_targets_attachment.function_targets", "id"),
21+
resource.TestCheckResourceAttr("tencentcloud_clb_function_targets_attachment.function_targets", "function_targets.0.weight", "10"),
22+
),
23+
},
24+
{
25+
Config: testAccClbFunctionTargetsAttachmentUpdate,
26+
Check: resource.ComposeTestCheckFunc(
27+
resource.TestCheckResourceAttr("tencentcloud_clb_function_targets_attachment.function_targets", "function_targets.0.weight", "20"),
28+
),
2029
},
2130
{
2231
ResourceName: "tencentcloud_clb_function_targets_attachment.function_targets",
@@ -48,3 +57,25 @@ resource "tencentcloud_clb_function_targets_attachment" "function_targets" {
4857
}
4958
5059
`
60+
61+
const testAccClbFunctionTargetsAttachmentUpdate = `
62+
63+
resource "tencentcloud_clb_function_targets_attachment" "function_targets" {
64+
domain = "xxx.com"
65+
listener_id = "lbl-nonkgvc2"
66+
load_balancer_id = "lb-5dnrkgry"
67+
url = "/"
68+
69+
function_targets {
70+
weight = 20
71+
72+
function {
73+
function_name = "keep-1676351130"
74+
function_namespace = "default"
75+
function_qualifier = "$LATEST"
76+
function_qualifier_type = "VERSION"
77+
}
78+
}
79+
}
80+
81+
`

vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb/v20180317/client.go

Lines changed: 66 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)