Skip to content

Commit 75e16f7

Browse files
committed
add
1 parent 76fad48 commit 75e16f7

File tree

3 files changed

+215
-0
lines changed

3 files changed

+215
-0
lines changed

tencentcloud/services/clb/resource_tc_clb_instance.go

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1515
"github.com/pkg/errors"
1616
clb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb/v20180317"
17+
vpc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc/v20170312"
1718

1819
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
1920
)
@@ -218,6 +219,11 @@ func ResourceTencentCloudClbInstance() *schema.Resource {
218219
Optional: true,
219220
Description: "If create dynamic vip CLB instance, `true` or `false`.",
220221
},
222+
"eip_address_id": {
223+
Type: schema.TypeString,
224+
Optional: true,
225+
Description: "The unique ID of the EIP, such as eip-1v2rmbwk, is only applicable to the intranet load balancing binding EIP.",
226+
},
221227
"domain": {
222228
Type: schema.TypeString,
223229
Computed: true,
@@ -406,6 +412,10 @@ func resourceTencentCloudClbInstanceCreate(d *schema.ResourceData, meta interfac
406412
request.DynamicVip = helper.Bool(v.(bool))
407413
}
408414

415+
if v, ok := d.GetOk("eip_address_id"); ok {
416+
request.EipAddressId = helper.String(v.(string))
417+
}
418+
409419
if tags := helper.GetTags(d, "tags"); len(tags) > 0 {
410420
for k, v := range tags {
411421
tmpKey := k
@@ -675,6 +685,40 @@ func resourceTencentCloudClbInstanceRead(d *schema.ResourceData, meta interface{
675685
_ = d.Set("snat_pro", instance.SnatPro)
676686
}
677687

688+
if *instance.LoadBalancerType == "INTERNAL" {
689+
request := vpc.NewDescribeAddressesRequest()
690+
request.Filters = []*vpc.Filter{
691+
{
692+
Name: helper.String("instance-id"),
693+
Values: helper.Strings([]string{clbId}),
694+
},
695+
}
696+
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
697+
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseVpcClient().DescribeAddresses(request)
698+
if e != nil {
699+
return tccommon.RetryError(e)
700+
}
701+
702+
if result == nil || result.Response == nil || result.Response.AddressSet == nil {
703+
e = fmt.Errorf("Describe CLB instance EIP failed")
704+
return resource.NonRetryableError(e)
705+
}
706+
707+
if len(result.Response.AddressSet) == 1 {
708+
if result.Response.AddressSet[0].AddressId != nil {
709+
_ = d.Set("eip_address_id", result.Response.AddressSet[0].AddressId)
710+
}
711+
}
712+
713+
return nil
714+
})
715+
716+
if err != nil {
717+
log.Printf("[CRITAL]%s Describe CLB instance EIP failed, reason:%+v", logId, err)
718+
return err
719+
}
720+
}
721+
678722
tcClient := meta.(tccommon.ProviderMeta).GetAPIV3Conn()
679723
tagService := svctag.NewTagService(tcClient)
680724
tags, err := tagService.DescribeResourceTags(ctx, "clb", "clb", tcClient.Region, d.Id())
@@ -932,6 +976,102 @@ func resourceTencentCloudClbInstanceUpdate(d *schema.ResourceData, meta interfac
932976
}
933977
}
934978

979+
if d.HasChange("eip_address_id") {
980+
oldEip, newEip := d.GetChange("eip_address_id")
981+
oldEipStr := oldEip.(string)
982+
newEipStr := newEip.(string)
983+
// delete old first
984+
if oldEipStr != "" {
985+
request := vpc.NewDisassociateAddressRequest()
986+
request.AddressId = helper.String(oldEipStr)
987+
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
988+
_, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseVpcClient().DisassociateAddress(request)
989+
if e != nil {
990+
return tccommon.RetryError(e)
991+
}
992+
993+
return nil
994+
})
995+
996+
if err != nil {
997+
log.Printf("[CRITAL]%s Disassociate EIP failed, reason:%+v", logId, err)
998+
return err
999+
}
1000+
1001+
// wait
1002+
eipRequest := vpc.NewDescribeAddressesRequest()
1003+
eipRequest.AddressIds = helper.Strings([]string{oldEipStr})
1004+
err = resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
1005+
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseVpcClient().DescribeAddresses(eipRequest)
1006+
if e != nil {
1007+
return tccommon.RetryError(e)
1008+
}
1009+
1010+
if result == nil || result.Response == nil || result.Response.AddressSet == nil || len(result.Response.AddressSet) != 1 {
1011+
e = fmt.Errorf("Describe CLB instance EIP failed")
1012+
return resource.NonRetryableError(e)
1013+
}
1014+
1015+
if *result.Response.AddressSet[0].AddressStatus != "UNBIND" {
1016+
return resource.RetryableError(fmt.Errorf("EIP status is still %s", *result.Response.AddressSet[0].AddressStatus))
1017+
}
1018+
1019+
return nil
1020+
})
1021+
1022+
if err != nil {
1023+
log.Printf("[CRITAL]%s Describe CLB instance EIP failed, reason:%+v", logId, err)
1024+
return err
1025+
}
1026+
}
1027+
1028+
// attach new
1029+
if newEipStr != "" {
1030+
request := vpc.NewAssociateAddressRequest()
1031+
request.AddressId = helper.String(newEipStr)
1032+
request.InstanceId = helper.String(clbId)
1033+
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
1034+
_, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseVpcClient().AssociateAddress(request)
1035+
if e != nil {
1036+
return tccommon.RetryError(e)
1037+
}
1038+
1039+
return nil
1040+
})
1041+
1042+
if err != nil {
1043+
log.Printf("[CRITAL]%s Associate EIP failed, reason:%+v", logId, err)
1044+
return err
1045+
}
1046+
1047+
// wait
1048+
eipRequest := vpc.NewDescribeAddressesRequest()
1049+
eipRequest.AddressIds = helper.Strings([]string{newEipStr})
1050+
err = resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
1051+
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseVpcClient().DescribeAddresses(eipRequest)
1052+
if e != nil {
1053+
return tccommon.RetryError(e)
1054+
}
1055+
1056+
if result == nil || result.Response == nil || result.Response.AddressSet == nil || len(result.Response.AddressSet) != 1 {
1057+
e = fmt.Errorf("Describe CLB instance EIP failed")
1058+
return resource.NonRetryableError(e)
1059+
}
1060+
1061+
if *result.Response.AddressSet[0].AddressStatus != "BIND" {
1062+
return resource.RetryableError(fmt.Errorf("EIP status is still %s", *result.Response.AddressSet[0].AddressStatus))
1063+
}
1064+
1065+
return nil
1066+
})
1067+
1068+
if err != nil {
1069+
log.Printf("[CRITAL]%s Describe CLB instance EIP failed, reason:%+v", logId, err)
1070+
return err
1071+
}
1072+
}
1073+
}
1074+
9351075
if d.HasChange("tags") {
9361076
oldValue, newValue := d.GetChange("tags")
9371077
replaceTags, deleteTags := svctag.DiffTags(oldValue.(map[string]interface{}), newValue.(map[string]interface{}))

tencentcloud/services/clb/resource_tc_clb_instance.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,43 @@ resource "tencentcloud_clb_instance" "example" {
3838
}
3939
```
4040

41+
Create CLB with eip_address_id, Only support INTERNAL CLB
42+
43+
```hcl
44+
variable "availability_zone" {
45+
default = "ap-guangzhou-4"
46+
}
47+
48+
// create vpc
49+
resource "tencentcloud_vpc" "vpc" {
50+
cidr_block = "10.0.0.0/16"
51+
name = "vpc"
52+
}
53+
54+
// create subnet
55+
resource "tencentcloud_subnet" "subnet" {
56+
vpc_id = tencentcloud_vpc.vpc.id
57+
availability_zone = var.availability_zone
58+
name = "subnet"
59+
cidr_block = "10.0.1.0/24"
60+
is_multicast = false
61+
}
62+
63+
// create clb
64+
resource "tencentcloud_clb_instance" "example" {
65+
network_type = "INTERNAL"
66+
clb_name = "tf-example"
67+
project_id = 0
68+
vpc_id = tencentcloud_vpc.vpc.id
69+
subnet_id = tencentcloud_subnet.subnet.id
70+
eip_address_id = "eip-lt0w6jhq"
71+
72+
tags = {
73+
tagKey = "tagValue"
74+
}
75+
}
76+
```
77+
4178
Create dedicated cluster clb
4279

4380
```hcl

website/docs/r/clb_instance.html.markdown

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,43 @@ resource "tencentcloud_clb_instance" "example" {
4949
}
5050
```
5151

52+
### Create CLB with eip_address_id, Only support INTERNAL CLB
53+
54+
```hcl
55+
variable "availability_zone" {
56+
default = "ap-guangzhou-4"
57+
}
58+
59+
// create vpc
60+
resource "tencentcloud_vpc" "vpc" {
61+
cidr_block = "10.0.0.0/16"
62+
name = "vpc"
63+
}
64+
65+
// create subnet
66+
resource "tencentcloud_subnet" "subnet" {
67+
vpc_id = tencentcloud_vpc.vpc.id
68+
availability_zone = var.availability_zone
69+
name = "subnet"
70+
cidr_block = "10.0.1.0/24"
71+
is_multicast = false
72+
}
73+
74+
// create clb
75+
resource "tencentcloud_clb_instance" "example" {
76+
network_type = "INTERNAL"
77+
clb_name = "tf-example"
78+
project_id = 0
79+
vpc_id = tencentcloud_vpc.vpc.id
80+
subnet_id = tencentcloud_subnet.subnet.id
81+
eip_address_id = "eip-lt0w6jhq"
82+
83+
tags = {
84+
tagKey = "tagValue"
85+
}
86+
}
87+
```
88+
5289
### Create dedicated cluster clb
5390

5491
```hcl
@@ -486,6 +523,7 @@ The following arguments are supported:
486523
* `cluster_id` - (Optional, String, ForceNew) Cluster ID.
487524
* `delete_protect` - (Optional, Bool) Whether to enable delete protection.
488525
* `dynamic_vip` - (Optional, Bool) If create dynamic vip CLB instance, `true` or `false`.
526+
* `eip_address_id` - (Optional, String) The unique ID of the EIP, such as eip-1v2rmbwk, is only applicable to the intranet load balancing binding EIP.
489527
* `internet_bandwidth_max_out` - (Optional, Int) Max bandwidth out, only applicable to open CLB. Valid value ranges is [1, 2048]. Unit is MB.
490528
* `internet_charge_type` - (Optional, String) Internet charge type, only applicable to open CLB. Valid values are `TRAFFIC_POSTPAID_BY_HOUR`, `BANDWIDTH_POSTPAID_BY_HOUR` and `BANDWIDTH_PACKAGE`.
491529
* `load_balancer_pass_to_target` - (Optional, Bool) Whether the target allow flow come from clb. If value is true, only check security group of clb, or check both clb and backend instance security group.

0 commit comments

Comments
 (0)