Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@ DEPRECATED:

ENHANCEMENTS:

* Resource `tencentcloud_ccn` add `charge_type` to support billing mode setting.
* Resource `tencentcloud_ccn` add `bandwidth_limit_type` to support the speed limit type setting.
* Resource `tencentcloud_ccn_bandwidth_limit` add `dst_region` to support destination area restriction setting.
* Resource `tencentcloud_cdn_domain` add `range_origin_switch` to support range back to source configuration.
* Resource `tencentcloud_cdn_domain` add `rule_cache` to support advanced path cache configuration.
* Resource `tencentcloud_cdn_domain` add `request_header` to support request header configuration.
* Data Source `tencentcloud_ccn_instances` add `charge_type` to support billing mode.
* Data Source `tencentcloud_ccn_instances` add `bandwidth_limit_type` to support the speed limit type.
* Data Source `tencentcloud_ccn_bandwidth_limit` add `dst_region` to support destination area restriction.
* Data Source `tencentcloud_cdn_domains` add `range_origin_switch` to support range back to source configuration.
* Data Source `tencentcloud_cdn_domains` add `rule_cache` to support advanced path cache configuration.
* Data Source `tencentcloud_cdn_domains` add `request_header` to support request header configuration.
Expand Down
12 changes: 9 additions & 3 deletions tencentcloud/data_source_tc_ccn_bandwidth_limits.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ func dataSourceTencentCloudCcnBandwidthLimits() *schema.Resource {
Computed: true,
Description: "Limitation of bandwidth.",
},
"dst_region": {
Type: schema.TypeString,
Computed: true,
Description: "Destination area restriction.",
},
},
},
},
Expand All @@ -85,7 +90,7 @@ func dataSourceTencentCloudCcnBandwidthLimitsRead(d *schema.ResourceData, meta i
ccnId = d.Get("ccn_id").(string)
)

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

for _, item := range infos {
var infoMap = make(map[string]interface{})
infoMap["region"] = item.region
infoMap["bandwidth_limit"] = item.limit
infoMap["region"] = item.Region
infoMap["bandwidth_limit"] = item.BandwidthLimit
infoMap["dst_region"] = item.DstRegion
infoList = append(infoList, infoMap)
}
if err := d.Set("limits", infoList); err != nil {
Expand Down
61 changes: 56 additions & 5 deletions tencentcloud/data_source_tc_ccn_bandwidth_limits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,50 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

func TestAccDataSourceTencentCloudCcnV3BandwidthLimitsBasic(t *testing.T) {
func TestAccDataSourceTencentCloudCcnV3BandwidthLimitsOuter(t *testing.T) {
keyName := "data.tencentcloud_ccn_bandwidth_limits.limit"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: TestAccDataSourceTencentCloudCcnBandwidthLimits,
Config: TestAccDataSourceTencentCloudCcnOuterBandwidthLimits,

Check: resource.ComposeTestCheckFunc(
testAccCheckTencentCloudDataSourceID(keyName),
resource.TestCheckResourceAttrSet(keyName, "ccn_id"),
resource.TestCheckResourceAttrSet(keyName, "limits.#"),
resource.TestCheckResourceAttr(keyName, "limits.#", "1"),
resource.TestCheckResourceAttr(keyName, "limits.0.region", "ap-shanghai"),
resource.TestCheckResourceAttr(keyName, "limits.0.bandwidth_limit", "500"),
),
},
},
})
}

const TestAccDataSourceTencentCloudCcnBandwidthLimits = `
func TestAccDataSourceTencentCloudCcnV3BandwidthLimitsInter(t *testing.T) {
keyName := "data.tencentcloud_ccn_bandwidth_limits.limit"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: TestAccDataSourceTencentCloudCcnInterBandwidthLimits,

Check: resource.ComposeTestCheckFunc(
testAccCheckTencentCloudDataSourceID(keyName),
resource.TestCheckResourceAttrSet(keyName, "ccn_id"),
resource.TestCheckResourceAttr(keyName, "limits.#", "1"),
resource.TestCheckResourceAttr(keyName, "limits.0.region", "ap-shanghai"),
resource.TestCheckResourceAttr(keyName, "limits.0.dst_region", "ap-beijing"),
resource.TestCheckResourceAttr(keyName, "limits.0.bandwidth_limit", "500"),
),
},
},
})
}

const TestAccDataSourceTencentCloudCcnOuterBandwidthLimits = `
variable "other_region1" {
default = "ap-shanghai"
}
Expand All @@ -37,13 +60,41 @@ resource tencentcloud_ccn main {
qos = "AG"
}

resource tencentcloud_ccn_bandwidth_limit limit1 {
ccn_id = tencentcloud_ccn.main.id
region = var.other_region1
bandwidth_limit = 500
}

data tencentcloud_ccn_bandwidth_limits limit {
ccn_id = tencentcloud_ccn.main.id
ccn_id = tencentcloud_ccn_bandwidth_limit.limit1.ccn_id
}
`

const TestAccDataSourceTencentCloudCcnInterBandwidthLimits = `
variable "other_region1" {
default = "ap-shanghai"
}

variable "other_region2" {
default = "ap-beijing"
}

resource tencentcloud_ccn main {
name = "ci-temp-test-ccn"
description = "ci-temp-test-ccn-des"
qos = "AG"
bandwidth_limit_type = "INTER_REGION_LIMIT"
}

resource tencentcloud_ccn_bandwidth_limit limit1 {
ccn_id = tencentcloud_ccn.main.id
region = var.other_region1
dst_region = var.other_region2
bandwidth_limit = 500
}

data tencentcloud_ccn_bandwidth_limits limit {
ccn_id = tencentcloud_ccn_bandwidth_limit.limit1.ccn_id
}
`
12 changes: 12 additions & 0 deletions tencentcloud/data_source_tc_ccn_instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ func dataSourceTencentCloudCcnInstances() *schema.Resource {
Computed: true,
Description: "States of instance. The available value include 'ISOLATED'(arrears) and 'AVAILABLE'.",
},
"charge_type": {
Type: schema.TypeString,
Computed: true,
Description: "Billing mode.",
},
"bandwidth_limit_type": {
Type: schema.TypeString,
Computed: true,
Description: "The speed limit type.",
},
"attachment_list": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -178,6 +188,8 @@ func dataSourceTencentCloudCcnInstancesRead(d *schema.ResourceData, meta interfa
infoMap["qos"] = item.qos
infoMap["state"] = strings.ToUpper(item.state)
infoMap["create_time"] = item.createTime
infoMap["charge_type"] = item.chargeType
infoMap["bandwidth_limit_type"] = item.bandWithLimitType
infoList = append(infoList, infoMap)

instances, err := service.DescribeCcnAttachedInstances(ctx, item.ccnId)
Expand Down
4 changes: 4 additions & 0 deletions tencentcloud/data_source_tc_ccn_instances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ func TestAccDataSourceTencentCloudCcnV3InstancesBasic(t *testing.T) {
resource.TestCheckResourceAttrSet(keyId, "instance_list.0.ccn_id"),
resource.TestCheckResourceAttrSet(keyId, "instance_list.0.qos"),
resource.TestCheckResourceAttrSet(keyId, "instance_list.0.state"),
resource.TestCheckResourceAttrSet(keyId, "instance_list.0.charge_type"),
resource.TestCheckResourceAttrSet(keyId, "instance_list.0.bandwidth_limit_type"),
resource.TestCheckResourceAttrSet(keyId, "instance_list.0.attachment_list.#"),
resource.TestCheckResourceAttrSet(keyId, "instance_list.0.create_time"),

Expand All @@ -36,6 +38,8 @@ func TestAccDataSourceTencentCloudCcnV3InstancesBasic(t *testing.T) {
resource.TestCheckResourceAttrSet(keyName, "instance_list.0.ccn_id"),
resource.TestCheckResourceAttrSet(keyName, "instance_list.0.qos"),
resource.TestCheckResourceAttrSet(keyName, "instance_list.0.state"),
resource.TestCheckResourceAttrSet(keyId, "instance_list.0.charge_type"),
resource.TestCheckResourceAttrSet(keyId, "instance_list.0.bandwidth_limit_type"),
resource.TestCheckResourceAttrSet(keyName, "instance_list.0.attachment_list.#"),
resource.TestCheckResourceAttrSet(keyName, "instance_list.0.create_time"),
),
Expand Down
6 changes: 6 additions & 0 deletions tencentcloud/extension_cnn.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ const CNN_INSTANCE_TYPE_VPC = "VPC"
const CNN_INSTANCE_TYPE_DIRECTCONNECT = "DIRECTCONNECT"
const CNN_INSTANCE_TYPE_BMVPC = "BMVPC"
const CNN_INSTANCE_TYPE_VPNGW = "VPNGW"

const PREPAID = "PREPAID"
const POSTPAID = "POSTPAID"

const OuterRegionLimit = "OUTER_REGION_LIMIT"
const InterRegionLimit = "INTER_REGION_LIMIT"
81 changes: 74 additions & 7 deletions tencentcloud/resource_tc_ccn.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,39 @@ Provides a resource to create a CCN instance.

Example Usage

Create a prepaid CCN

```hcl
resource "tencentcloud_ccn" "main" {
name = "ci-temp-test-ccn"
description = "ci-temp-test-ccn-des"
qos = "AG"
charge_type = "PREPAID"
bandwidth_limit_type = "INTER_REGION_LIMIT"
}
```

Create a post-paid regional export speed limit type CCN

```hcl
resource "tencentcloud_ccn" "main" {
name = "ci-temp-test-ccn"
description = "ci-temp-test-ccn-des"
qos = "AG"
charge_type = "POSTPAID"
bandwidth_limit_type = "OUTER_REGION_LIMIT"
}
```

Create a post-paid inter-regional rate limit type CNN

```hcl
resource "tencentcloud_ccn" "main" {
name = "ci-temp-test-ccn"
description = "ci-temp-test-ccn-des"
qos = "AG"
name = "ci-temp-test-ccn"
description = "ci-temp-test-ccn-des"
qos = "AG"
charge_type = "POSTPAID"
bandwidth_limit_type = "INTER_REGION_LIMIT"
}
```

Expand Down Expand Up @@ -62,6 +90,28 @@ func resourceTencentCloudCcn() *schema.Resource {
ValidateFunc: validateAllowedStringValue([]string{CNN_QOS_PT, CNN_QOS_AU, CNN_QOS_AG}),
Description: "Service quality of CCN. Valid values: `PT`, `AU`, `AG`. The default is `AU`.",
},
"charge_type": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: POSTPAID,
ValidateFunc: validateAllowedStringValue([]string{POSTPAID, PREPAID}),
Description: "Billing mode. Valid values: `PREPAID`, `POSTPAID`. " +
"`PREPAID` means prepaid, which means annual and monthly subscription, " +
"`POSTPAID` means post-payment, which means billing by volume. " +
"The default is `POSTPAID`. The prepaid model only supports inter-regional speed limit, " +
"and the post-paid model supports inter-regional speed limit and regional export speed limit.",
},
"bandwidth_limit_type": {
Type: schema.TypeString,
Optional: true,
Default: OuterRegionLimit,
ValidateFunc: validateAllowedStringValue([]string{OuterRegionLimit, InterRegionLimit}),
Description: "The speed limit type. Valid values: `INTER_REGION_LIMIT`, `OUTER_REGION_LIMIT`. " +
"`OUTER_REGION_LIMIT` represents the regional export speed limit, " +
"`INTER_REGION_LIMIT` is the inter-regional speed limit. " +
"The default is `OUTER_REGION_LIMIT`.",
},
// Computed values
"state": {
Type: schema.TypeString,
Expand Down Expand Up @@ -96,14 +146,16 @@ func resourceTencentCloudCcnCreate(d *schema.ResourceData, meta interface{}) err
service := VpcService{client: meta.(*TencentCloudClient).apiV3Conn}

var (
name = d.Get("name").(string)
description = ""
qos = d.Get("qos").(string)
name = d.Get("name").(string)
description = ""
qos = d.Get("qos").(string)
chargeType = d.Get("charge_type").(string)
bandwidthLimitType = d.Get("bandwidth_limit_type").(string)
)
if temp, ok := d.GetOk("description"); ok {
description = temp.(string)
}
info, err := service.CreateCcn(ctx, name, description, qos)
info, err := service.CreateCcn(ctx, name, description, qos, chargeType, bandwidthLimitType)
if err != nil {
return err
}
Expand Down Expand Up @@ -146,6 +198,8 @@ func resourceTencentCloudCcnRead(d *schema.ResourceData, meta interface{}) error
_ = d.Set("state", strings.ToUpper(info.state))
_ = d.Set("instance_count", info.instanceCount)
_ = d.Set("create_time", info.createTime)
_ = d.Set("charge_type", info.chargeType)
_ = d.Set("bandwidth_limit_type", info.bandWithLimitType)

return nil
})
Expand Down Expand Up @@ -203,6 +257,19 @@ func resourceTencentCloudCcnUpdate(d *schema.ResourceData, meta interface{}) err
d.SetPartial(val)
}
}
// modify band width limit type
if d.HasChange("bandwidth_limit_type") {
_, news := d.GetChange("bandwidth_limit_type")
if err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
if err := service.ModifyCcnRegionBandwidthLimitsType(ctx, d.Id(), news.(string)); err != nil {
return retryError(err)
}
return nil
}); err != nil {
return err
}
d.SetPartial("bandwidth_limit_type")
}

if d.HasChange("tags") {

Expand Down
Loading