fix vpc and vswitch bug while creating vpc and vswitch (#15082)

This commit is contained in:
He Guimin 2017-06-06 01:24:25 +08:00 committed by Paul Stack
parent eed23bd803
commit 0b63007142
3 changed files with 32 additions and 6 deletions

View File

@ -36,6 +36,9 @@ const (
// ess
InvalidScalingGroupIdNotFound = "InvalidScalingGroupId.NotFound"
IncorrectScalingConfigurationLifecycleState = "IncorrectScalingConfigurationLifecycleState"
//unknown Error
UnknownError = "UnknownError"
)
func GetNotFoundErrorFromString(str string) error {

View File

@ -2,11 +2,11 @@ package alicloud
import (
"fmt"
"strings"
"github.com/denverdino/aliyungo/common"
"github.com/denverdino/aliyungo/ecs"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
"strings"
"time"
)
@ -73,9 +73,20 @@ func resourceAliyunVpcCreate(d *schema.ResourceData, meta interface{}) error {
ecsconn := meta.(*AliyunClient).ecsconn
vpc, err := ecsconn.CreateVpc(args)
var vpc *ecs.CreateVpcResponse
err = resource.Retry(3*time.Minute, func() *resource.RetryError {
resp, err := ecsconn.CreateVpc(args)
if err != nil {
return err
if e, ok := err.(*common.Error); ok && (e.StatusCode == 400 || e.Code == UnknownError) {
return resource.RetryableError(fmt.Errorf("Vpc is still creating result from some unknown error -- try again"))
}
return resource.NonRetryableError(err)
}
vpc = resp
return nil
})
if err != nil {
return fmt.Errorf("Create vpc got an error :%#v", err)
}
d.SetId(vpc.VpcId)

View File

@ -56,9 +56,21 @@ func resourceAliyunSwitchCreate(d *schema.ResourceData, meta interface{}) error
return err
}
vswitchID, err := conn.CreateVSwitch(args)
var vswitchID string
err = resource.Retry(3*time.Minute, func() *resource.RetryError {
vswId, err := conn.CreateVSwitch(args)
if err != nil {
return fmt.Errorf("Create subnet got a error :%s", err)
if e, ok := err.(*common.Error); ok && (e.StatusCode == 400 || e.Code == UnknownError) {
return resource.RetryableError(fmt.Errorf("Vswitch is still creating result from some unknown error -- try again"))
}
return resource.NonRetryableError(err)
}
vswitchID = vswId
return nil
})
if err != nil {
return fmt.Errorf("Create subnet got an error :%s", err)
}
d.SetId(vswitchID)