Skip to content

Commit

Permalink
Merge pull request #72 from xiaozhu36/token
Browse files Browse the repository at this point in the history
fix creating rds Prepaid instance failed error
  • Loading branch information
zhuzhih2017 authored Jan 8, 2018
2 parents 594c966 + 7acbbac commit b7b830b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## 1.6.0 (Unreleased)

## 1.5.2 (January 8, 2018)

BUG FIXES:
* fix creating rds 'Prepaid' instance failed error ([#70](https://github.com/alibaba/terraform-provider/pull/70))

## 1.5.1 (January 5, 2018)

BUG FIXES:
Expand Down
20 changes: 17 additions & 3 deletions alicloud/resource_alicloud_db_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,16 @@ func resourceAlicloudDBInstanceRead(d *schema.ResourceData, meta interface{}) er
func resourceAlicloudDBInstanceDelete(d *schema.ResourceData, meta interface{}) error {
client := meta.(*AliyunClient)

instance, err := client.DescribeDBInstanceById(d.Id())
if err != nil {
if NotFoundError(err) || IsExceptedError(err, InvalidDBInstanceNameNotFound) {
return nil
}
return fmt.Errorf("Error Describe DB InstanceAttribute: %#v", err)
}
if instance.PayType == rds.Prepaid {
return fmt.Errorf("At present, 'Prepaid' instance cannot be deleted and must wait it to be expired and release it automatically.")
}
return resource.Retry(5*time.Minute, func() *resource.RetryError {
err := client.rdsconn.DeleteInstance(d.Id())

Expand Down Expand Up @@ -428,14 +438,18 @@ func buildDBCreateOrderArgs(d *schema.ResourceData, meta interface{}) (*rds.Crea
args.PayType = rds.DBPayType(d.Get("instance_charge_type").(string))

// if charge type is postpaid, the commodity code must set to bards
args.CommodityCode = rds.Rds
if args.PayType == rds.Postpaid {
args.CommodityCode = rds.Bards
args.CommodityCode = rds.Bards
// At present, API supports two charge options about 'Prepaid'.
// 'Month': valid period ranges [1-9]; 'Year': valid period range [1-3]
// This resource only supports to input Month period [1-9, 12, 24, 36] and the values need to be converted before using them.
if args.PayType == rds.Prepaid {
args.CommodityCode = rds.Rds

period := d.Get("period").(int)
args.UsedTime = period
args.TimeType = common.Month
if period > 9 {
args.UsedTime = period / 12
args.TimeType = common.Year
}
}
Expand Down
2 changes: 1 addition & 1 deletion alicloud/resource_alicloud_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ func resourceAliyunInstanceDelete(d *schema.ResourceData, meta interface{}) erro
client := meta.(*AliyunClient)
conn := client.ecsconn
if common.InstanceChargeType(d.Get("instance_charge_type").(string)) == common.PrePaid {
return fmt.Errorf("At present, 'PrePaid' instance cannot be deleted and must wait it to be outdated and release it automatically.")
return fmt.Errorf("At present, 'PrePaid' instance cannot be deleted and must wait it to be expired and release it automatically.")
}
return resource.Retry(5*time.Minute, func() *resource.RetryError {
instance, err := client.QueryInstancesById(d.Id())
Expand Down

0 comments on commit b7b830b

Please sign in to comment.