Skip to content

Commit 3f7123c

Browse files
author
mikatong
committed
support clb create topic
1 parent a4d56a9 commit 3f7123c

File tree

5 files changed

+145
-0
lines changed

5 files changed

+145
-0
lines changed

tencentcloud/provider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ Cloud Load Balancer(CLB)
206206
207207
Resource
208208
tencentcloud_clb_instance
209+
tencentcloud_clb_instance_topic
209210
tencentcloud_clb_listener
210211
tencentcloud_clb_listener_rule
211212
tencentcloud_clb_attachment
@@ -859,6 +860,7 @@ func Provider() terraform.ResourceProvider {
859860
"tencentcloud_lb": resourceTencentCloudLB(),
860861
"tencentcloud_alb_server_attachment": resourceTencentCloudAlbServerAttachment(),
861862
"tencentcloud_clb_instance": resourceTencentCloudClbInstance(),
863+
"tencentcloud_clb_instance_topic": resourceTencentCloudClbInstanceTopic(),
862864
"tencentcloud_clb_listener": resourceTencentCloudClbListener(),
863865
"tencentcloud_clb_listener_rule": resourceTencentCloudClbListenerRule(),
864866
"tencentcloud_clb_attachment": resourceTencentCloudClbServerAttachment(),
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
Provides a resource to create a CLB instance topic.
3+
4+
Example Usage
5+
6+
```hcl
7+
resource "tencentcloud_clb_instances_topic" "topic" {
8+
topic_name="clb-topic"
9+
partition_count=3
10+
}
11+
```
12+
*/
13+
package tencentcloud
14+
15+
import (
16+
"context"
17+
"log"
18+
19+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
20+
)
21+
22+
func resourceTencentCloudClbInstanceTopic() *schema.Resource {
23+
return &schema.Resource{
24+
Create: resourceTencentCloudClbInstanceTopicCreate,
25+
Read: resourceTencentCloudClbInstanceTopicRead,
26+
Update: resourceTencentCloudClbInstanceTopicUpdate,
27+
Delete: resourceTencentCloudClbInstanceTopicDelete,
28+
Importer: &schema.ResourceImporter{
29+
State: schema.ImportStatePassthrough,
30+
},
31+
32+
Schema: map[string]*schema.Schema{
33+
"topic_name": {
34+
Type: schema.TypeString,
35+
Required: true,
36+
Description: "Log topic of CLB instance.",
37+
},
38+
"partition_count": {
39+
Type: schema.TypeInt,
40+
Optional: true,
41+
ValidateFunc: validateIntegerInRange(1, 10),
42+
Description: "Topic partition count of CLB instance.(Default 1).",
43+
},
44+
},
45+
}
46+
}
47+
48+
func resourceTencentCloudClbInstanceTopicRead(d *schema.ResourceData, meta interface{}) error {
49+
return nil
50+
}
51+
func resourceTencentCloudClbInstanceTopicUpdate(d *schema.ResourceData, meta interface{}) error {
52+
return nil
53+
}
54+
func resourceTencentCloudClbInstanceTopicDelete(d *schema.ResourceData, meta interface{}) error {
55+
return nil
56+
}
57+
func resourceTencentCloudClbInstanceTopicCreate(d *schema.ResourceData, meta interface{}) error {
58+
59+
logId := getLogId(contextNil)
60+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
61+
params := make(map[string]interface{})
62+
if topicName, ok := d.GetOk("topic_name"); ok {
63+
params["topic_name"] = topicName
64+
}
65+
if partitionCount, ok := d.GetOk("partition_count"); ok {
66+
params["partition_count"] = partitionCount
67+
}
68+
clbService := ClbService{
69+
client: meta.(*TencentCloudClient).apiV3Conn,
70+
}
71+
err := clbService.CreateTopic(ctx, params)
72+
if err != nil {
73+
log.Printf("[CRITAL]%s create CLB topic failed, reason:%+v", logId, err)
74+
return err
75+
}
76+
return nil
77+
}

tencentcloud/service_tencentcloud_clb.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
1111
"github.com/pkg/errors"
1212
clb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb/v20180317"
13+
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
1314
sdkErrors "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
1415
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/connectivity"
1516
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
@@ -1058,6 +1059,31 @@ func (me *ClbService) CreateTargetGroup(ctx context.Context, targetGroupName str
10581059
return
10591060
}
10601061

1062+
func (me *ClbService) CreateTopic(ctx context.Context, params map[string]interface{}) error {
1063+
1064+
request := clb.NewCreateTopicRequest()
1065+
1066+
if topicName, ok := params["topic_name"]; ok {
1067+
request.TopicName = common.StringPtr(topicName.(string))
1068+
}
1069+
1070+
if partitionCount, ok := params["partition_count"]; ok {
1071+
request.PartitionCount = common.Uint64Ptr((uint64)(partitionCount.(int)))
1072+
}
1073+
1074+
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
1075+
_, err := me.client.UseClbClient().CreateTopic(request)
1076+
if err != nil {
1077+
return retryError(err)
1078+
}
1079+
return nil
1080+
})
1081+
if err != nil {
1082+
return err
1083+
}
1084+
return nil
1085+
}
1086+
10611087
func (me *ClbService) ModifyTargetGroup(ctx context.Context, targetGroupId, targetGroupName string, port uint64) (err error) {
10621088
request := clb.NewModifyTargetGroupAttributeRequest()
10631089
request.TargetGroupId = &targetGroupId
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
subcategory: "Cloud Load Balancer(CLB)"
3+
layout: "tencentcloud"
4+
page_title: "TencentCloud: tencentcloud_clb_instance_topic"
5+
sidebar_current: "docs-tencentcloud-resource-clb_instance_topic"
6+
description: |-
7+
Provides a resource to create a CLB instance topic.
8+
---
9+
10+
# tencentcloud_clb_instance_topic
11+
12+
Provides a resource to create a CLB instance topic.
13+
14+
## Example Usage
15+
16+
```hcl
17+
resource "tencentcloud_clb_instances_topic" "topic" {
18+
topic_name = "clb-topic"
19+
partition_count = 3
20+
}
21+
```
22+
23+
## Argument Reference
24+
25+
The following arguments are supported:
26+
27+
* `topic_name` - (Required) Log topic of CLB instance.
28+
* `partition_count` - (Optional) Topic partition count of CLB instance.(Default 1).
29+
30+
## Attributes Reference
31+
32+
In addition to all arguments above, the following attributes are exported:
33+
34+
* `id` - ID of the resource.
35+
36+
37+

website/tencentcloud.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,9 @@
488488
<li>
489489
<a href="/docs/providers/tencentcloud/r/clb_instance.html">tencentcloud_clb_instance</a>
490490
</li>
491+
<li>
492+
<a href="/docs/providers/tencentcloud/r/clb_instance_topic.html">tencentcloud_clb_instance_topic</a>
493+
</li>
491494
<li>
492495
<a href="/docs/providers/tencentcloud/r/clb_listener.html">tencentcloud_clb_listener</a>
493496
</li>

0 commit comments

Comments
 (0)