Skip to content

Commit 99aae10

Browse files
authored
Merge pull request #575 from ttomzhou/cnn
fix ccn instance and ccn bandwidth limit
2 parents 2ff1bd3 + ece7990 commit 99aae10

15 files changed

+511
-79
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,15 @@ DEPRECATED:
1010

1111
ENHANCEMENTS:
1212

13+
* Resource `tencentcloud_ccn` add `charge_type` to support billing mode setting.
14+
* Resource `tencentcloud_ccn` add `bandwidth_limit_type` to support the speed limit type setting.
15+
* Resource `tencentcloud_ccn_bandwidth_limit` add `dst_region` to support destination area restriction setting.
1316
* Resource `tencentcloud_cdn_domain` add `range_origin_switch` to support range back to source configuration.
1417
* Resource `tencentcloud_cdn_domain` add `rule_cache` to support advanced path cache configuration.
1518
* Resource `tencentcloud_cdn_domain` add `request_header` to support request header configuration.
19+
* Data Source `tencentcloud_ccn_instances` add `charge_type` to support billing mode.
20+
* Data Source `tencentcloud_ccn_instances` add `bandwidth_limit_type` to support the speed limit type.
21+
* Data Source `tencentcloud_ccn_bandwidth_limit` add `dst_region` to support destination area restriction.
1622
* Data Source `tencentcloud_cdn_domains` add `range_origin_switch` to support range back to source configuration.
1723
* Data Source `tencentcloud_cdn_domains` add `rule_cache` to support advanced path cache configuration.
1824
* Data Source `tencentcloud_cdn_domains` add `request_header` to support request header configuration.

tencentcloud/data_source_tc_ccn_bandwidth_limits.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ func dataSourceTencentCloudCcnBandwidthLimits() *schema.Resource {
6666
Computed: true,
6767
Description: "Limitation of bandwidth.",
6868
},
69+
"dst_region": {
70+
Type: schema.TypeString,
71+
Computed: true,
72+
Description: "Destination area restriction.",
73+
},
6974
},
7075
},
7176
},
@@ -85,7 +90,7 @@ func dataSourceTencentCloudCcnBandwidthLimitsRead(d *schema.ResourceData, meta i
8590
ccnId = d.Get("ccn_id").(string)
8691
)
8792

88-
var infos, err = service.DescribeCcnRegionBandwidthLimits(ctx, ccnId)
93+
var infos, err = service.GetCcnRegionBandwidthLimits(ctx, ccnId)
8994
if err != nil {
9095
return err
9196
}
@@ -94,8 +99,9 @@ func dataSourceTencentCloudCcnBandwidthLimitsRead(d *schema.ResourceData, meta i
9499

95100
for _, item := range infos {
96101
var infoMap = make(map[string]interface{})
97-
infoMap["region"] = item.region
98-
infoMap["bandwidth_limit"] = item.limit
102+
infoMap["region"] = item.Region
103+
infoMap["bandwidth_limit"] = item.BandwidthLimit
104+
infoMap["dst_region"] = item.DstRegion
99105
infoList = append(infoList, infoMap)
100106
}
101107
if err := d.Set("limits", infoList); err != nil {

tencentcloud/data_source_tc_ccn_bandwidth_limits_test.go

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,50 @@ import (
66
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
77
)
88

9-
func TestAccDataSourceTencentCloudCcnV3BandwidthLimitsBasic(t *testing.T) {
9+
func TestAccDataSourceTencentCloudCcnV3BandwidthLimitsOuter(t *testing.T) {
1010
keyName := "data.tencentcloud_ccn_bandwidth_limits.limit"
1111
resource.Test(t, resource.TestCase{
1212
PreCheck: func() { testAccPreCheck(t) },
1313
Providers: testAccProviders,
1414
Steps: []resource.TestStep{
1515
{
16-
Config: TestAccDataSourceTencentCloudCcnBandwidthLimits,
16+
Config: TestAccDataSourceTencentCloudCcnOuterBandwidthLimits,
1717

1818
Check: resource.ComposeTestCheckFunc(
1919
testAccCheckTencentCloudDataSourceID(keyName),
2020
resource.TestCheckResourceAttrSet(keyName, "ccn_id"),
21-
resource.TestCheckResourceAttrSet(keyName, "limits.#"),
21+
resource.TestCheckResourceAttr(keyName, "limits.#", "1"),
22+
resource.TestCheckResourceAttr(keyName, "limits.0.region", "ap-shanghai"),
23+
resource.TestCheckResourceAttr(keyName, "limits.0.bandwidth_limit", "500"),
2224
),
2325
},
2426
},
2527
})
2628
}
2729

28-
const TestAccDataSourceTencentCloudCcnBandwidthLimits = `
30+
func TestAccDataSourceTencentCloudCcnV3BandwidthLimitsInter(t *testing.T) {
31+
keyName := "data.tencentcloud_ccn_bandwidth_limits.limit"
32+
resource.Test(t, resource.TestCase{
33+
PreCheck: func() { testAccPreCheck(t) },
34+
Providers: testAccProviders,
35+
Steps: []resource.TestStep{
36+
{
37+
Config: TestAccDataSourceTencentCloudCcnInterBandwidthLimits,
2938

39+
Check: resource.ComposeTestCheckFunc(
40+
testAccCheckTencentCloudDataSourceID(keyName),
41+
resource.TestCheckResourceAttrSet(keyName, "ccn_id"),
42+
resource.TestCheckResourceAttr(keyName, "limits.#", "1"),
43+
resource.TestCheckResourceAttr(keyName, "limits.0.region", "ap-shanghai"),
44+
resource.TestCheckResourceAttr(keyName, "limits.0.dst_region", "ap-beijing"),
45+
resource.TestCheckResourceAttr(keyName, "limits.0.bandwidth_limit", "500"),
46+
),
47+
},
48+
},
49+
})
50+
}
51+
52+
const TestAccDataSourceTencentCloudCcnOuterBandwidthLimits = `
3053
variable "other_region1" {
3154
default = "ap-shanghai"
3255
}
@@ -37,13 +60,41 @@ resource tencentcloud_ccn main {
3760
qos = "AG"
3861
}
3962
63+
resource tencentcloud_ccn_bandwidth_limit limit1 {
64+
ccn_id = tencentcloud_ccn.main.id
65+
region = var.other_region1
66+
bandwidth_limit = 500
67+
}
68+
4069
data tencentcloud_ccn_bandwidth_limits limit {
41-
ccn_id = tencentcloud_ccn.main.id
70+
ccn_id = tencentcloud_ccn_bandwidth_limit.limit1.ccn_id
71+
}
72+
`
73+
74+
const TestAccDataSourceTencentCloudCcnInterBandwidthLimits = `
75+
variable "other_region1" {
76+
default = "ap-shanghai"
77+
}
78+
79+
variable "other_region2" {
80+
default = "ap-beijing"
81+
}
82+
83+
resource tencentcloud_ccn main {
84+
name = "ci-temp-test-ccn"
85+
description = "ci-temp-test-ccn-des"
86+
qos = "AG"
87+
bandwidth_limit_type = "INTER_REGION_LIMIT"
4288
}
4389
4490
resource tencentcloud_ccn_bandwidth_limit limit1 {
4591
ccn_id = tencentcloud_ccn.main.id
4692
region = var.other_region1
93+
dst_region = var.other_region2
4794
bandwidth_limit = 500
4895
}
96+
97+
data tencentcloud_ccn_bandwidth_limits limit {
98+
ccn_id = tencentcloud_ccn_bandwidth_limit.limit1.ccn_id
99+
}
49100
`

tencentcloud/data_source_tc_ccn_instances.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@ func dataSourceTencentCloudCcnInstances() *schema.Resource {
8484
Computed: true,
8585
Description: "States of instance. The available value include 'ISOLATED'(arrears) and 'AVAILABLE'.",
8686
},
87+
"charge_type": {
88+
Type: schema.TypeString,
89+
Computed: true,
90+
Description: "Billing mode.",
91+
},
92+
"bandwidth_limit_type": {
93+
Type: schema.TypeString,
94+
Computed: true,
95+
Description: "The speed limit type.",
96+
},
8797
"attachment_list": {
8898
Type: schema.TypeList,
8999
Computed: true,
@@ -178,6 +188,8 @@ func dataSourceTencentCloudCcnInstancesRead(d *schema.ResourceData, meta interfa
178188
infoMap["qos"] = item.qos
179189
infoMap["state"] = strings.ToUpper(item.state)
180190
infoMap["create_time"] = item.createTime
191+
infoMap["charge_type"] = item.chargeType
192+
infoMap["bandwidth_limit_type"] = item.bandWithLimitType
181193
infoList = append(infoList, infoMap)
182194

183195
instances, err := service.DescribeCcnAttachedInstances(ctx, item.ccnId)

tencentcloud/data_source_tc_ccn_instances_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ func TestAccDataSourceTencentCloudCcnV3InstancesBasic(t *testing.T) {
2525
resource.TestCheckResourceAttrSet(keyId, "instance_list.0.ccn_id"),
2626
resource.TestCheckResourceAttrSet(keyId, "instance_list.0.qos"),
2727
resource.TestCheckResourceAttrSet(keyId, "instance_list.0.state"),
28+
resource.TestCheckResourceAttrSet(keyId, "instance_list.0.charge_type"),
29+
resource.TestCheckResourceAttrSet(keyId, "instance_list.0.bandwidth_limit_type"),
2830
resource.TestCheckResourceAttrSet(keyId, "instance_list.0.attachment_list.#"),
2931
resource.TestCheckResourceAttrSet(keyId, "instance_list.0.create_time"),
3032

@@ -36,6 +38,8 @@ func TestAccDataSourceTencentCloudCcnV3InstancesBasic(t *testing.T) {
3638
resource.TestCheckResourceAttrSet(keyName, "instance_list.0.ccn_id"),
3739
resource.TestCheckResourceAttrSet(keyName, "instance_list.0.qos"),
3840
resource.TestCheckResourceAttrSet(keyName, "instance_list.0.state"),
41+
resource.TestCheckResourceAttrSet(keyId, "instance_list.0.charge_type"),
42+
resource.TestCheckResourceAttrSet(keyId, "instance_list.0.bandwidth_limit_type"),
3943
resource.TestCheckResourceAttrSet(keyName, "instance_list.0.attachment_list.#"),
4044
resource.TestCheckResourceAttrSet(keyName, "instance_list.0.create_time"),
4145
),

tencentcloud/extension_cnn.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,9 @@ const CNN_INSTANCE_TYPE_VPC = "VPC"
88
const CNN_INSTANCE_TYPE_DIRECTCONNECT = "DIRECTCONNECT"
99
const CNN_INSTANCE_TYPE_BMVPC = "BMVPC"
1010
const CNN_INSTANCE_TYPE_VPNGW = "VPNGW"
11+
12+
const PREPAID = "PREPAID"
13+
const POSTPAID = "POSTPAID"
14+
15+
const OuterRegionLimit = "OUTER_REGION_LIMIT"
16+
const InterRegionLimit = "INTER_REGION_LIMIT"

tencentcloud/resource_tc_ccn.go

Lines changed: 74 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,39 @@ Provides a resource to create a CCN instance.
33
44
Example Usage
55
6+
Create a prepaid CCN
7+
8+
```hcl
9+
resource "tencentcloud_ccn" "main" {
10+
name = "ci-temp-test-ccn"
11+
description = "ci-temp-test-ccn-des"
12+
qos = "AG"
13+
charge_type = "PREPAID"
14+
bandwidth_limit_type = "INTER_REGION_LIMIT"
15+
}
16+
```
17+
18+
Create a post-paid regional export speed limit type CCN
19+
20+
```hcl
21+
resource "tencentcloud_ccn" "main" {
22+
name = "ci-temp-test-ccn"
23+
description = "ci-temp-test-ccn-des"
24+
qos = "AG"
25+
charge_type = "POSTPAID"
26+
bandwidth_limit_type = "OUTER_REGION_LIMIT"
27+
}
28+
```
29+
30+
Create a post-paid inter-regional rate limit type CNN
31+
632
```hcl
733
resource "tencentcloud_ccn" "main" {
8-
name = "ci-temp-test-ccn"
9-
description = "ci-temp-test-ccn-des"
10-
qos = "AG"
34+
name = "ci-temp-test-ccn"
35+
description = "ci-temp-test-ccn-des"
36+
qos = "AG"
37+
charge_type = "POSTPAID"
38+
bandwidth_limit_type = "INTER_REGION_LIMIT"
1139
}
1240
```
1341
@@ -62,6 +90,28 @@ func resourceTencentCloudCcn() *schema.Resource {
6290
ValidateFunc: validateAllowedStringValue([]string{CNN_QOS_PT, CNN_QOS_AU, CNN_QOS_AG}),
6391
Description: "Service quality of CCN. Valid values: `PT`, `AU`, `AG`. The default is `AU`.",
6492
},
93+
"charge_type": {
94+
Type: schema.TypeString,
95+
Optional: true,
96+
ForceNew: true,
97+
Default: POSTPAID,
98+
ValidateFunc: validateAllowedStringValue([]string{POSTPAID, PREPAID}),
99+
Description: "Billing mode. Valid values: `PREPAID`, `POSTPAID`. " +
100+
"`PREPAID` means prepaid, which means annual and monthly subscription, " +
101+
"`POSTPAID` means post-payment, which means billing by volume. " +
102+
"The default is `POSTPAID`. The prepaid model only supports inter-regional speed limit, " +
103+
"and the post-paid model supports inter-regional speed limit and regional export speed limit.",
104+
},
105+
"bandwidth_limit_type": {
106+
Type: schema.TypeString,
107+
Optional: true,
108+
Default: OuterRegionLimit,
109+
ValidateFunc: validateAllowedStringValue([]string{OuterRegionLimit, InterRegionLimit}),
110+
Description: "The speed limit type. Valid values: `INTER_REGION_LIMIT`, `OUTER_REGION_LIMIT`. " +
111+
"`OUTER_REGION_LIMIT` represents the regional export speed limit, " +
112+
"`INTER_REGION_LIMIT` is the inter-regional speed limit. " +
113+
"The default is `OUTER_REGION_LIMIT`.",
114+
},
65115
// Computed values
66116
"state": {
67117
Type: schema.TypeString,
@@ -96,14 +146,16 @@ func resourceTencentCloudCcnCreate(d *schema.ResourceData, meta interface{}) err
96146
service := VpcService{client: meta.(*TencentCloudClient).apiV3Conn}
97147

98148
var (
99-
name = d.Get("name").(string)
100-
description = ""
101-
qos = d.Get("qos").(string)
149+
name = d.Get("name").(string)
150+
description = ""
151+
qos = d.Get("qos").(string)
152+
chargeType = d.Get("charge_type").(string)
153+
bandwidthLimitType = d.Get("bandwidth_limit_type").(string)
102154
)
103155
if temp, ok := d.GetOk("description"); ok {
104156
description = temp.(string)
105157
}
106-
info, err := service.CreateCcn(ctx, name, description, qos)
158+
info, err := service.CreateCcn(ctx, name, description, qos, chargeType, bandwidthLimitType)
107159
if err != nil {
108160
return err
109161
}
@@ -146,6 +198,8 @@ func resourceTencentCloudCcnRead(d *schema.ResourceData, meta interface{}) error
146198
_ = d.Set("state", strings.ToUpper(info.state))
147199
_ = d.Set("instance_count", info.instanceCount)
148200
_ = d.Set("create_time", info.createTime)
201+
_ = d.Set("charge_type", info.chargeType)
202+
_ = d.Set("bandwidth_limit_type", info.bandWithLimitType)
149203

150204
return nil
151205
})
@@ -203,6 +257,19 @@ func resourceTencentCloudCcnUpdate(d *schema.ResourceData, meta interface{}) err
203257
d.SetPartial(val)
204258
}
205259
}
260+
// modify band width limit type
261+
if d.HasChange("bandwidth_limit_type") {
262+
_, news := d.GetChange("bandwidth_limit_type")
263+
if err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
264+
if err := service.ModifyCcnRegionBandwidthLimitsType(ctx, d.Id(), news.(string)); err != nil {
265+
return retryError(err)
266+
}
267+
return nil
268+
}); err != nil {
269+
return err
270+
}
271+
d.SetPartial("bandwidth_limit_type")
272+
}
206273

207274
if d.HasChange("tags") {
208275

0 commit comments

Comments
 (0)