Skip to content

Commit

Permalink
testcase: Adds a new test case for resource alicloud_cen_bandwidth_pa…
Browse files Browse the repository at this point in the history
…ckage
  • Loading branch information
thisnihonglei authored and xiaozhu36 committed Jan 25, 2022
1 parent a9cde15 commit 1ce7211
Show file tree
Hide file tree
Showing 3 changed files with 205 additions and 0 deletions.
4 changes: 4 additions & 0 deletions alicloud/resource_alicloud_cen_bandwidth_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ func resourceAlicloudCenBandwidthPackageUpdate(d *schema.ResourceData, meta inte
return resourceAlicloudCenBandwidthPackageRead(d, meta)
}
func resourceAlicloudCenBandwidthPackageDelete(d *schema.ResourceData, meta interface{}) error {
if d.Get("payment_type").(string) == "PrePaid" {
log.Printf("[WARN] Cannot destroy resource Alicloud Resource Cen BandwidthPackage. Terraform will remove this resource from the state file, however resources may remain.")
return nil
}
client := meta.(*connectivity.AliyunClient)
request := cbn.CreateDeleteCenBandwidthPackageRequest()
request.CenBandwidthPackageId = d.Id()
Expand Down
194 changes: 194 additions & 0 deletions alicloud/resource_alicloud_cen_bandwidth_package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,200 @@ func TestAccAlicloudCenBandwidthPackage_upgrade(t *testing.T) {
})
}

func TestAccAlicloudCenBandwidthPackage_basic1(t *testing.T) {
var v cbn.CenBandwidthPackage
resourceId := "alicloud_cen_bandwidth_package.default"
ra := resourceAttrInit(resourceId, nil)
rc := resourceCheckInitWithDescribeMethod(resourceId, &v, func() interface{} {
return &CbnService{testAccProvider.Meta().(*connectivity.AliyunClient)}
}, "DescribeCenBandwidthPackage")
rac := resourceAttrCheckInit(rc, ra)
testAccCheck := rac.resourceAttrMapUpdateSet()
rand := acctest.RandIntRange(1000000, 9999999)
name := fmt.Sprintf("tf-testAccCen%sBandwidthPackage-%d", defaultRegionToTest, rand)
testAccConfig := resourceTestAccConfigFunc(resourceId, name, resourceCenBandwidthPackageConfigDependence_upgrade)
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccPreCheckWithTime(t, []int{1})
},

IDRefreshName: resourceId,
Providers: testAccProviders,
CheckDestroy: nil,
Steps: []resource.TestStep{
{
Config: testAccConfig(map[string]interface{}{
"bandwidth": "5",
"geographic_region_ids": []string{"China", "China"},
"cen_bandwidth_package_name": "${var.name}",
"payment_type": "PrePaid",
"period": "1",
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"bandwidth": "5",
"geographic_region_ids.#": "1",
"cen_bandwidth_package_name": name,
"payment_type": "PrePaid",
"period": "1",
}),
),
},
{
ResourceName: resourceId,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"period"},
},
},
})
}

func TestAccAlicloudCenBandwidthPackage_basic2(t *testing.T) {
var v cbn.CenBandwidthPackage
resourceId := "alicloud_cen_bandwidth_package.default"
ra := resourceAttrInit(resourceId, nil)
rc := resourceCheckInitWithDescribeMethod(resourceId, &v, func() interface{} {
return &CbnService{testAccProvider.Meta().(*connectivity.AliyunClient)}
}, "DescribeCenBandwidthPackage")
rac := resourceAttrCheckInit(rc, ra)
testAccCheck := rac.resourceAttrMapUpdateSet()
rand := acctest.RandIntRange(1000000, 9999999)
name := fmt.Sprintf("tf-testAccCen%sBandwidthPackage-%d", defaultRegionToTest, rand)
testAccConfig := resourceTestAccConfigFunc(resourceId, name, resourceCenBandwidthPackageConfigDependence_upgrade)
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccPreCheckWithTime(t, []int{1})
},

IDRefreshName: resourceId,
Providers: testAccProviders,
CheckDestroy: nil,
Steps: []resource.TestStep{
{
Config: testAccConfig(map[string]interface{}{
"bandwidth": "5",
"geographic_region_ids": []string{"China", "China"},
"name": "${var.name}",
"charge_type": "PrePaid",
"period": "1",
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"bandwidth": "5",
"geographic_region_ids.#": "1",
"name": name,
"charge_type": "PrePaid",
"period": "1",
}),
),
},
{
ResourceName: resourceId,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"period"},
},
},
})
}

func TestAccAlicloudCenBandwidthPackage_basic3(t *testing.T) {
var v cbn.CenBandwidthPackage
resourceId := "alicloud_cen_bandwidth_package.default"
ra := resourceAttrInit(resourceId, nil)
rc := resourceCheckInitWithDescribeMethod(resourceId, &v, func() interface{} {
return &CbnService{testAccProvider.Meta().(*connectivity.AliyunClient)}
}, "DescribeCenBandwidthPackage")
rac := resourceAttrCheckInit(rc, ra)
testAccCheck := rac.resourceAttrMapUpdateSet()
rand := acctest.RandIntRange(1000000, 9999999)
name := fmt.Sprintf("tf-testAccCen%sBandwidthPackage-%d", defaultRegionToTest, rand)
testAccConfig := resourceTestAccConfigFunc(resourceId, name, resourceCenBandwidthPackageConfigDependence_upgrade)
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},

IDRefreshName: resourceId,
Providers: testAccProviders,
CheckDestroy: nil,
Steps: []resource.TestStep{
{
Config: testAccConfig(map[string]interface{}{
"bandwidth": "5",
"geographic_region_ids": []string{"China", "China"},
"cen_bandwidth_package_name": "${var.name}",
"payment_type": "PostPaid",
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"bandwidth": "5",
"geographic_region_ids.#": "1",
"cen_bandwidth_package_name": name,
"payment_type": "PostPaid",
}),
),
},
{
ResourceName: resourceId,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"period"},
},
},
})
}

func TestAccAlicloudCenBandwidthPackage_basic4(t *testing.T) {
var v cbn.CenBandwidthPackage
resourceId := "alicloud_cen_bandwidth_package.default"
ra := resourceAttrInit(resourceId, nil)
rc := resourceCheckInitWithDescribeMethod(resourceId, &v, func() interface{} {
return &CbnService{testAccProvider.Meta().(*connectivity.AliyunClient)}
}, "DescribeCenBandwidthPackage")
rac := resourceAttrCheckInit(rc, ra)
testAccCheck := rac.resourceAttrMapUpdateSet()
rand := acctest.RandIntRange(1000000, 9999999)
name := fmt.Sprintf("tf-testAccCen%sBandwidthPackage-%d", defaultRegionToTest, rand)
testAccConfig := resourceTestAccConfigFunc(resourceId, name, resourceCenBandwidthPackageConfigDependence_upgrade)
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},

IDRefreshName: resourceId,
Providers: testAccProviders,
CheckDestroy: nil,
Steps: []resource.TestStep{
{
Config: testAccConfig(map[string]interface{}{
"bandwidth": "5",
"geographic_region_ids": []string{"China", "China"},
"name": "${var.name}",
"charge_type": "PostPaid",
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"bandwidth": "5",
"geographic_region_ids.#": "1",
"name": name,
"charge_type": "PostPaid",
}),
),
},
{
ResourceName: resourceId,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"period"},
},
},
})
}

var cenBandwidthPackageBasicMap = map[string]string{
"bandwidth": "5",
}
Expand Down
7 changes: 7 additions & 0 deletions website/docs/r/cen_bandwidth_package.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ resource "alicloud_cen_bandwidth_package" "example" {
geographic_region_b_id = "China"
}
```

### Deleting `alicloud_cen_bandwidth_package` or removing it from your configuration

The `alicloud_cen_bandwidth_package` resource allows you to manage `payment_type = "PrePaid"` bandwidth package, but Terraform cannot destroy it.
Deleting the subscription resource or removing it from your configuration will remove it from your statefile and management, but will not destroy the Bandwidth Package.
You can resume managing the subscription bandwidth package via the AlibabaCloud Console.

## Argument Reference

The following arguments are supported:
Expand Down

0 comments on commit 1ce7211

Please sign in to comment.