Skip to content

Commit aacbd13

Browse files
author
ivan
committed
# This is a combination of 2 commits.
# This is the 1st commit message: 修改拼写错误 favorate -> favorite, 解决 https://registry.terraform.io/providers/tencentcloudstack/tencentcloud/latest/docs/resources/instance 中的错误 添加支持 clb 创建目标工作组的逻辑,添加相应函数的参数 修复新添加的命令行参数错误,Elem字段使用 schema.Resource指针 添加安全组对内网clb的支持(注释掉对当前网络是否为内网的判断) 添加支持开启和关闭CLB安全组默认放通的配置 添加terraform支持external CLB创建AZ实例 添加clb创建目标工作组中,调用create后的update操作中的 port 字段 添加create中调用update操作时,设置load_balancer_pass_to_target 修改在 resourceTencentCloudClbInstanceUpdate 中对 LoadBalancerPassToTarget 取值的处理,修复 tf 文件该值有变化时,没有触发更改的问题 修改支持internal CLB的security group 中description注释部分 添加调用 CreateClusterInstances时,传入imageId参数来指定镜像,以及对镜像的验证,满足 img-xxx 的格式 # This is the commit message #2: 回退版本(添加镜像),该文件不再维护
1 parent bd00ea6 commit aacbd13

6 files changed

+142
-13
lines changed

tencentcloud/resource_tc_clb_instance.go

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func resourceTencentCloudClbInstance() *schema.Resource {
135135
Type: schema.TypeList,
136136
Optional: true,
137137
Elem: &schema.Schema{Type: schema.TypeString},
138-
Description: "Security groups of the CLB instance. Only supports `OPEN` CLBs.",
138+
Description: "Security groups of the CLB instance. Supports both `OPEN` and `INTERNAL` CLBs.",
139139
},
140140
"target_region_info_region": {
141141
Type: schema.TypeString,
@@ -159,6 +159,27 @@ func resourceTencentCloudClbInstance() *schema.Resource {
159159
Computed: true,
160160
Description: "Network operator, only applicable to open CLB. Valid values are `CMCC`(China Mobile), `CTCC`(Telecom), `CUCC`(China Unicom) and `BGP`. If this ISP is specified, network billing method can only use the bandwidth package billing (BANDWIDTH_PACKAGE).",
161161
},
162+
"load_balancer_pass_to_target": {
163+
Type: schema.TypeBool,
164+
Optional: true,
165+
Default: true,
166+
Description: "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.",
167+
},
168+
"master_zone_id": {
169+
Type: schema.TypeString,
170+
Optional: true,
171+
Description: "Setting master zone id of cross available zone disaster recovery, only applicable to open CLB.",
172+
},
173+
"zone_id": {
174+
Type: schema.TypeString,
175+
Optional: true,
176+
Description: "Available zone id, only applicable to open CLB.",
177+
},
178+
"slave_zone_id": {
179+
Type: schema.TypeString,
180+
Optional: true,
181+
Description: "Setting slave zone id of cross available zone disaster recovery, only applicable to open CLB. this zone will undertake traffic when the master is down",
182+
},
162183
},
163184
}
164185
}
@@ -197,11 +218,7 @@ func resourceTencentCloudClbInstanceCreate(d *schema.ResourceData, meta interfac
197218
if (targetRegionInfoRegion != "" && targetRegionInfoVpcId == "") || (targetRegionInfoRegion == "" && targetRegionInfoVpcId != "") {
198219
return fmt.Errorf("[CHECK][CLB instance][Create] check: region and vpc_id must be set at same time")
199220
}
200-
if _, ok := d.GetOk("security_groups"); ok {
201-
if networkType == CLB_NETWORK_TYPE_INTERNAL {
202-
return fmt.Errorf("[CHECK][CLB instance][Create] check: INTERNAL network_type do not support this operation with sercurity_groups")
203-
}
204-
}
221+
205222
request := clb.NewCreateLoadBalancerRequest()
206223
request.LoadBalancerType = helper.String(networkType)
207224
request.LoadBalancerName = helper.String(clbName)
@@ -252,6 +269,26 @@ func resourceTencentCloudClbInstanceCreate(d *schema.ResourceData, meta interfac
252269
}
253270
}
254271

272+
if v, ok := d.GetOk("master_zone_id"); ok {
273+
if networkType == CLB_NETWORK_TYPE_INTERNAL {
274+
return fmt.Errorf("[CHECK][CLB instance][Create] check: INTERNAL network_type do not support master zone id setting")
275+
}
276+
request.MasterZoneId = helper.String(v.(string))
277+
}
278+
279+
if v, ok := d.GetOk("zone_id"); ok {
280+
if networkType == CLB_NETWORK_TYPE_INTERNAL {
281+
return fmt.Errorf("[CHECK][CLB instance][Create] check: INTERNAL network_type do not support zone id setting")
282+
}
283+
request.ZoneId = helper.String(v.(string))
284+
}
285+
286+
if v, ok := d.GetOk("slave_zone_id"); ok {
287+
if networkType == CLB_NETWORK_TYPE_INTERNAL {
288+
return fmt.Errorf("[CHECK][CLB instance][Create] check: INTERNAL network_type do not support slave zone id setting")
289+
}
290+
request.SlaveZoneId = helper.String(v.(string))
291+
}
255292
clbId := ""
256293
var response *clb.CreateLoadBalancerResponse
257294
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
@@ -312,13 +349,15 @@ func resourceTencentCloudClbInstanceCreate(d *schema.ResourceData, meta interfac
312349
}
313350

314351
if targetRegionInfoRegion != "" {
352+
isLoadBalancePassToTgt := d.Get("load_balancer_pass_to_target").(bool)
315353
targetRegionInfo := clb.TargetRegionInfo{
316354
Region: &targetRegionInfoRegion,
317355
VpcId: &targetRegionInfoVpcId,
318356
}
319357
mRequest := clb.NewModifyLoadBalancerAttributesRequest()
320358
mRequest.LoadBalancerId = helper.String(clbId)
321359
mRequest.TargetRegionInfo = &targetRegionInfo
360+
mRequest.LoadBalancerPassToTarget = &isLoadBalancePassToTgt
322361
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
323362
mResponse, e := meta.(*TencentCloudClient).apiV3Conn.UseClbClient().ModifyLoadBalancerAttributes(mRequest)
324363
if e != nil {
@@ -402,6 +441,11 @@ func resourceTencentCloudClbInstanceRead(d *schema.ResourceData, meta interface{
402441
_ = d.Set("internet_charge_type", instance.NetworkAttributes.InternetChargeType)
403442
}
404443

444+
_ = d.Set("load_balancer_pass_to_target", instance.LoadBalancerPassToTarget)
445+
_ = d.Set("master_zone_id", instance.MasterZone)
446+
_ = d.Set("zone_id", instance.MasterZone)
447+
_ = d.Set("slave_zone_id", instance.MasterZone)
448+
405449
tcClient := meta.(*TencentCloudClient).apiV3Conn
406450
tagService := &TagService{client: tcClient}
407451
tags, err := tagService.DescribeResourceTags(ctx, "clb", "clb", tcClient.Region, d.Id())
@@ -428,6 +472,7 @@ func resourceTencentCloudClbInstanceUpdate(d *schema.ResourceData, meta interfac
428472
targetRegionInfo := clb.TargetRegionInfo{}
429473
internet := clb.InternetAccessible{}
430474
changed := false
475+
isLoadBalancerPassToTgt := false
431476

432477
if d.HasChange("clb_name") {
433478
changed = true
@@ -469,6 +514,11 @@ func resourceTencentCloudClbInstanceUpdate(d *schema.ResourceData, meta interfac
469514
}
470515
}
471516

517+
if d.HasChange("load_balancer_pass_to_target") {
518+
changed = true
519+
isLoadBalancerPassToTgt = d.Get("load_balancer_pass_to_target").(bool)
520+
}
521+
472522
if changed {
473523
request := clb.NewModifyLoadBalancerAttributesRequest()
474524
request.LoadBalancerId = helper.String(clbId)
@@ -481,6 +531,9 @@ func resourceTencentCloudClbInstanceUpdate(d *schema.ResourceData, meta interfac
481531
if d.HasChange("internet_charge_type") || d.HasChange("internet_bandwidth_max_out") {
482532
request.InternetChargeInfo = &internet
483533
}
534+
if d.HasChange("load_balancer_pass_to_target") {
535+
request.LoadBalancerPassToTarget = &isLoadBalancerPassToTgt
536+
}
484537
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
485538
response, e := meta.(*TencentCloudClient).apiV3Conn.UseClbClient().ModifyLoadBalancerAttributes(request)
486539
if e != nil {
@@ -515,9 +568,7 @@ func resourceTencentCloudClbInstanceUpdate(d *schema.ResourceData, meta interfac
515568
}
516569

517570
if d.HasChange("security_groups") {
518-
if d.Get("network_type") == CLB_NETWORK_TYPE_INTERNAL {
519-
return fmt.Errorf("[CHECK][CLB instance %s][Update] check: INTERNAL network_type do not support this operation with sercurity_groups", clbId)
520-
}
571+
521572
sgRequest := clb.NewSetLoadBalancerSecurityGroupsRequest()
522573
sgRequest.LoadBalancerId = helper.String(clbId)
523574
securityGroups := d.Get("security_groups").([]interface{})

tencentcloud/resource_tc_clb_target_group.go

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ package tencentcloud
2222

2323
import (
2424
"context"
25-
2625
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
2726
clb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb/v20180317"
2827
)
@@ -50,6 +49,44 @@ func resourceTencentCloudClbTargetGroup() *schema.Resource {
5049
ForceNew: true,
5150
Description: "VPC ID, default is based on the network.",
5251
},
52+
"port": {
53+
Type: schema.TypeInt,
54+
Optional: true,
55+
ValidateFunc: validatePort,
56+
Description: "The default port of target group, add server after can use it.",
57+
},
58+
"target_group_instances": {
59+
Type: schema.TypeList,
60+
Optional: true,
61+
Description: "The backend server of target group bind.",
62+
Elem: &schema.Resource{
63+
Schema: map[string]*schema.Schema{
64+
"bind_ip": {
65+
Type: schema.TypeString,
66+
Required: true,
67+
ValidateFunc: validateIp,
68+
Description: "The internal ip of target group instance.",
69+
},
70+
"port": {
71+
Type: schema.TypeInt,
72+
Required: true,
73+
ValidateFunc: validatePort,
74+
Description: "The port of target group instance.",
75+
},
76+
"weight": {
77+
Type: schema.TypeInt,
78+
Optional: true,
79+
Description: "The weight of target group instance.",
80+
},
81+
"new_port": {
82+
Type: schema.TypeInt,
83+
Optional: true,
84+
ValidateFunc: validatePort,
85+
Description: "The new port of target group instance.",
86+
},
87+
},
88+
},
89+
},
5390
},
5491
}
5592
}
@@ -63,12 +100,31 @@ func resourceTencentCloudClbTargetCreate(d *schema.ResourceData, meta interface{
63100
clbService = ClbService{client: meta.(*TencentCloudClient).apiV3Conn}
64101
vpcId = d.Get("vpc_id").(string)
65102
targetGroupName = d.Get("target_group_name").(string)
103+
port = uint64(d.Get("port").(int))
66104
insAttachments = make([]*clb.TargetGroupInstance, 0)
67105
targetGroupId string
68106
err error
69107
)
70108

71-
targetGroupId, err = clbService.CreateTargetGroup(ctx, targetGroupName, vpcId, insAttachments)
109+
if v, ok := d.GetOk("target_group_instance"); ok {
110+
targetGroupInstances := v.([]interface{})
111+
for _, v1 := range targetGroupInstances {
112+
value := v1.(map[string]interface{})
113+
bindIP := value["bind_ip"].(string)
114+
port := uint64(value["port"].(int))
115+
weight := uint64(value["weight"].(int))
116+
newPort := uint64(value["new_port"].(int))
117+
tgtGrp := &clb.TargetGroupInstance{
118+
BindIP: &bindIP,
119+
Port: &port,
120+
Weight: &weight,
121+
NewPort: &newPort,
122+
}
123+
insAttachments = append(insAttachments, tgtGrp)
124+
}
125+
}
126+
127+
targetGroupId, err = clbService.CreateTargetGroup(ctx, targetGroupName, vpcId, port, insAttachments)
72128
if err != nil {
73129
return err
74130
}
@@ -99,6 +155,7 @@ func resourceTencentCloudClbTargetRead(d *schema.ResourceData, meta interface{})
99155
}
100156
_ = d.Set("target_group_name", targetGroupInfos[0].TargetGroupName)
101157
_ = d.Set("vpc_id", targetGroupInfos[0].VpcId)
158+
_ = d.Set("port", targetGroupInfos[0].Port)
102159

103160
return nil
104161
}

tencentcloud/resource_tc_instance.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ resource "tencentcloud_subnet" "app" {
4242
// Create 2 CVM instances to host awesome_app
4343
resource "tencentcloud_instance" "my_awesome_app" {
4444
instance_name = "awesome_app"
45-
availability_zone = data.tencentcloud_availability_zones.my_favorate_zones.zones.0.name
45+
availability_zone = data.tencentcloud_availability_zones.my_favorite_zones.zones.0.name
4646
image_id = data.tencentcloud_images.my_favorite_image.images.0.image_id
4747
instance_type = data.tencentcloud_instance_types.my_favorite_instance_types.instance_types.0.instance_type
4848
system_disk_type = "CLOUD_PREMIUM"

tencentcloud/resource_tc_kubernetes_cluster.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ func TkeCvmCreateInfo() map[string]*schema.Schema {
549549
Elem: &schema.Schema{Type: schema.TypeString},
550550
Description: "Disaster recover groups to which a CVM instance belongs. Only support maximum 1.",
551551
},
552+
<<<<<<< HEAD
552553
// InstanceAdvancedSettingsOverrides
553554
"desired_pod_num": {
554555
Type: schema.TypeInt,
@@ -594,6 +595,13 @@ func TkeExistCvmCreateInfo() map[string]*schema.Schema {
594595
ForceNew: true,
595596
Elem: &schema.Schema{Type: schema.TypeInt},
596597
Description: "Custom mode cluster, you can specify the number of pods for each node. corresponding to the existed_instances_para.instance_ids parameter.",
598+
=======
599+
"os": {
600+
Type: schema.TypeString,
601+
Optional: true,
602+
ValidateFunc: validateImageID,
603+
Description: "The valid image id, format of img-xxx.",
604+
>>>>>>> 37314e6e... 添加调用 CreateClusterInstances时传入imageId参数来指定镜像以及对镜像的验证满足 img-xxx 的格式
597605
},
598606
}
599607
}
@@ -1337,6 +1345,10 @@ func tkeGetCvmRunInstancesPara(dMap map[string]interface{}, meta interface{},
13371345
}
13381346
}
13391347

1348+
if v, ok := dMap["os"]; ok {
1349+
request.ImageId = helper.String(v.(string))
1350+
}
1351+
13401352
cvmJson = request.ToJsonString()
13411353

13421354
cvmJson = strings.Replace(cvmJson, `"Password":"",`, "", -1)

tencentcloud/service_tencentcloud_clb.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1025,13 +1025,14 @@ func clbNewTarget(instanceId, port, weight interface{}) *clb.Target {
10251025
return &bk
10261026
}
10271027

1028-
func (me *ClbService) CreateTargetGroup(ctx context.Context, targetGroupName string, vpcId string,
1028+
func (me *ClbService) CreateTargetGroup(ctx context.Context, targetGroupName string, vpcId string, port uint64,
10291029
targetGroupInstances []*clb.TargetGroupInstance) (targetGroupId string, err error) {
10301030
var response *clb.CreateTargetGroupResponse
10311031

10321032
request := clb.NewCreateTargetGroupRequest()
10331033
request.TargetGroupName = &targetGroupName
10341034
request.TargetGroupInstances = targetGroupInstances
1035+
request.Port = &port
10351036
if vpcId != "" {
10361037
request.VpcId = &vpcId
10371038
}

tencentcloud/validators.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ func validateIp(v interface{}, k string) (ws []string, errors []error) {
6565
return
6666
}
6767

68+
func validateImageID(v interface{}, k string) (ws []string, errors []error) {
69+
value := v.(string)
70+
if !strings.HasPrefix(value, "img-") {
71+
errors = append(errors, fmt.Errorf("the format of %q is invalid: %s, it should begin with `img-`", k, value))
72+
}
73+
return
74+
}
75+
6876
// NOTE not exactly strict, but ok for now
6977
func validateIntegerInRange(min, max int64) schema.SchemaValidateFunc {
7078
return func(v interface{}, k string) (ws []string, errors []error) {

0 commit comments

Comments
 (0)