|
| 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 | +} |
0 commit comments