Skip to content

Commit 4694d94

Browse files
authored
fix(clb): [125668619] tencentcloud_clb_attachment optmize targets code logic (#3437)
* add * add
1 parent 9e6c7f7 commit 4694d94

File tree

5 files changed

+51
-25
lines changed

5 files changed

+51
-25
lines changed

.changelog/3437.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_attachment: optmize `targets` code logic
3+
```

tencentcloud/services/clb/extension_clb.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,16 @@ const (
134134
)
135135

136136
const (
137-
CLB_BACKEND_TYPE_CVM = "CVM"
138-
CLB_BACKEND_TYPE_ENI = "ENI"
139-
CLB_BACKEND_TYPE_NAT = "NAT"
140-
CLB_BACKEND_TYPE_CCN = "CCN"
141-
CLB_BACKEND_TYPE_SRV = "SRV"
137+
CLB_BACKEND_TYPE_CVM = "CVM"
138+
CLB_BACKEND_TYPE_ENI = "ENI"
139+
CLB_BACKEND_TYPE_NAT = "NAT"
140+
CLB_BACKEND_TYPE_CCN = "CCN"
141+
CLB_BACKEND_TYPE_SRV = "SRV"
142+
CLB_BACKEND_TYPE_MS = "MANAGED_SERVICE"
143+
CLB_BACKEND_TYPE_EVM = "EVM"
144+
CLB_BACKEND_TYPE_GR = "GLOBALROUTE"
145+
CLB_BACKEND_TYPE_IPDC = "IPDC"
146+
CLB_BACKEND_TYPE_PVGW = "PVGW"
142147
)
143148

144149
const (

tencentcloud/services/clb/resource_tc_clb_attachment.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ func resourceTencentCloudClbServerAttachmentCreate(d *schema.ResourceData, meta
199199
} else if domain != "" && url != "" {
200200
id = fmt.Sprintf("%s,%s#%v#%v", domain, url, d.Get("listener_id"), d.Get("clb_id"))
201201
} else {
202+
// only api support for now
202203
id = fmt.Sprintf("%s#%v#%v", "", d.Get("listener_id"), d.Get("clb_id"))
203204
}
204205

@@ -265,18 +266,22 @@ func resourceTencentCloudClbServerAttachmentRead(d *schema.ResourceData, meta in
265266
_ = d.Set("listener_id", listenerId)
266267
_ = d.Set("protocol_type", instance.Protocol)
267268

269+
if locationId != "" {
270+
_ = d.Set("rule_id", locationId)
271+
}
272+
268273
if domain != "" && url != "" {
269274
_ = d.Set("domain", domain)
270275
_ = d.Set("url", url)
271276
}
272277

273278
var onlineTargets []*clb.Backend
274279
if *instance.Protocol == CLB_LISTENER_PROTOCOL_HTTP || *instance.Protocol == CLB_LISTENER_PROTOCOL_HTTPS {
275-
_ = d.Set("rule_id", locationId)
276280
if len(instance.Rules) > 0 {
277281
for _, loc := range instance.Rules {
278-
if locationId == "" || locationId == *loc.LocationId {
282+
if (locationId == *loc.LocationId) || (domain == *loc.Domain && url == *loc.Url) {
279283
onlineTargets = loc.Targets
284+
break
280285
}
281286
}
282287
}
@@ -296,7 +301,10 @@ func resourceTencentCloudClbServerAttachmentRead(d *schema.ResourceData, meta in
296301

297302
targets = append(targets, target)
298303
} else if *onlineTarget.Type == CLB_BACKEND_TYPE_ENI || *onlineTarget.Type == CLB_BACKEND_TYPE_NAT ||
299-
*onlineTarget.Type == CLB_BACKEND_TYPE_CCN || *onlineTarget.Type == CLB_BACKEND_TYPE_SRV {
304+
*onlineTarget.Type == CLB_BACKEND_TYPE_CCN || *onlineTarget.Type == CLB_BACKEND_TYPE_SRV ||
305+
*onlineTarget.Type == CLB_BACKEND_TYPE_MS || *onlineTarget.Type == CLB_BACKEND_TYPE_EVM ||
306+
*onlineTarget.Type == CLB_BACKEND_TYPE_GR || *onlineTarget.Type == CLB_BACKEND_TYPE_IPDC ||
307+
*onlineTarget.Type == CLB_BACKEND_TYPE_PVGW {
300308
target := map[string]interface{}{
301309
"weight": int(*onlineTarget.Weight),
302310
"port": int(*onlineTarget.Port),

tencentcloud/services/clb/resource_tc_clb_attachment.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Provides a resource to create a CLB attachment.
44

55
Example Usage
66

7-
Bind a Cvm instance by using `rule_id`
7+
Bind a Cvm instance by using rule_id
88

99
```hcl
1010
resource "tencentcloud_clb_attachment" "example" {
@@ -20,7 +20,7 @@ resource "tencentcloud_clb_attachment" "example" {
2020
}
2121
```
2222

23-
Bind a Cvm instance by using `domian` and `url`
23+
Bind a Cvm instance by using domian and url
2424

2525
```hcl
2626
resource "tencentcloud_clb_attachment" "example" {
@@ -37,7 +37,7 @@ resource "tencentcloud_clb_attachment" "example" {
3737
}
3838
```
3939

40-
Bind multiple Cvm instances by using `rule_id`
40+
Bind multiple Cvm instances by using rule_id
4141

4242
```hcl
4343
resource "tencentcloud_clb_attachment" "example" {
@@ -59,7 +59,7 @@ resource "tencentcloud_clb_attachment" "example" {
5959
}
6060
```
6161

62-
Bind multiple Cvm instances by using `domian` and `url`
62+
Bind multiple Cvm instances by using domian and url
6363

6464
```hcl
6565
resource "tencentcloud_clb_attachment" "example" {
@@ -82,7 +82,7 @@ resource "tencentcloud_clb_attachment" "example" {
8282
}
8383
```
8484

85-
Bind backend target is ENI by using `rule_id`
85+
Bind backend target is ENI by using rule_id
8686

8787
```hcl
8888
resource "tencentcloud_clb_attachment" "example" {
@@ -98,14 +98,14 @@ resource "tencentcloud_clb_attachment" "example" {
9898
}
9999
```
100100

101-
Bind backend target is ENI by using `domian` and `url`
101+
Bind backend target is ENI by using domian and url
102102

103103
```hcl
104104
resource "tencentcloud_clb_attachment" "example" {
105105
clb_id = "lb-k2zjp9lv"
106106
listener_id = "lbl-hh141sn9"
107107
domain = "test.com"
108-
url = "/"
108+
url = "/path"
109109
110110
targets {
111111
eni_ip = "172.16.16.52"
@@ -119,10 +119,14 @@ Import
119119

120120
CLB attachment can be imported using the id, e.g.
121121

122+
If use rule_id
123+
122124
```
123125
$ terraform import tencentcloud_clb_attachment.example loc-4xxr2cy7#lbl-hh141sn9#lb-7a0t6zqb
126+
```
124127

125-
Or
128+
If use domain & url
126129

127-
$ terraform import tencentcloud_clb_attachment.example test.com,/#lbl-hh141sn9#lb-7a0t6zqb
130+
```
131+
$ terraform import tencentcloud_clb_attachment.example test.com,/path#lbl-hh141sn9#lb-7a0t6zqb
128132
```

website/docs/r/clb_attachment.html.markdown

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Provides a resource to create a CLB attachment.
1515

1616
## Example Usage
1717

18+
### Bind a Cvm instance by using rule_id
19+
1820
```hcl
1921
resource "tencentcloud_clb_attachment" "example" {
2022
clb_id = "lb-k2zjp9lv"
@@ -29,7 +31,7 @@ resource "tencentcloud_clb_attachment" "example" {
2931
}
3032
```
3133

32-
34+
### Bind a Cvm instance by using domian and url
3335

3436
```hcl
3537
resource "tencentcloud_clb_attachment" "example" {
@@ -46,7 +48,7 @@ resource "tencentcloud_clb_attachment" "example" {
4648
}
4749
```
4850

49-
51+
### Bind multiple Cvm instances by using rule_id
5052

5153
```hcl
5254
resource "tencentcloud_clb_attachment" "example" {
@@ -68,7 +70,7 @@ resource "tencentcloud_clb_attachment" "example" {
6870
}
6971
```
7072

71-
73+
### Bind multiple Cvm instances by using domian and url
7274

7375
```hcl
7476
resource "tencentcloud_clb_attachment" "example" {
@@ -91,7 +93,7 @@ resource "tencentcloud_clb_attachment" "example" {
9193
}
9294
```
9395

94-
96+
### Bind backend target is ENI by using rule_id
9597

9698
```hcl
9799
resource "tencentcloud_clb_attachment" "example" {
@@ -107,14 +109,14 @@ resource "tencentcloud_clb_attachment" "example" {
107109
}
108110
```
109111

110-
112+
### Bind backend target is ENI by using domian and url
111113

112114
```hcl
113115
resource "tencentcloud_clb_attachment" "example" {
114116
clb_id = "lb-k2zjp9lv"
115117
listener_id = "lbl-hh141sn9"
116118
domain = "test.com"
117-
url = "/"
119+
url = "/path"
118120
119121
targets {
120122
eni_ip = "172.16.16.52"
@@ -154,11 +156,15 @@ In addition to all arguments above, the following attributes are exported:
154156

155157
CLB attachment can be imported using the id, e.g.
156158

159+
If use rule_id
160+
157161
```
158162
$ terraform import tencentcloud_clb_attachment.example loc-4xxr2cy7#lbl-hh141sn9#lb-7a0t6zqb
163+
```
159164

160-
Or
165+
If use domain & url
161166

162-
$ terraform import tencentcloud_clb_attachment.example test.com,/#lbl-hh141sn9#lb-7a0t6zqb
167+
```
168+
$ terraform import tencentcloud_clb_attachment.example test.com,/path#lbl-hh141sn9#lb-7a0t6zqb
163169
```
164170

0 commit comments

Comments
 (0)