Skip to content

Commit

Permalink
fix vpc and vswitch bug while creating vpc and vswitch (#15082)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaozhu36 authored and stack72 committed Jun 5, 2017
1 parent eed23bd commit 0b63007
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
3 changes: 3 additions & 0 deletions builtin/providers/alicloud/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ const (
// ess
InvalidScalingGroupIdNotFound = "InvalidScalingGroupId.NotFound"
IncorrectScalingConfigurationLifecycleState = "IncorrectScalingConfigurationLifecycleState"

//unknown Error
UnknownError = "UnknownError"
)

func GetNotFoundErrorFromString(str string) error {
Expand Down
19 changes: 15 additions & 4 deletions builtin/providers/alicloud/resource_alicloud_vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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 {
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 err
return fmt.Errorf("Create vpc got an error :%#v", err)
}

d.SetId(vpc.VpcId)
Expand Down
16 changes: 14 additions & 2 deletions builtin/providers/alicloud/resource_alicloud_vswitch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
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 a error :%s", err)
return fmt.Errorf("Create subnet got an error :%s", err)
}

d.SetId(vswitchID)
Expand Down

0 comments on commit 0b63007

Please sign in to comment.