Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provider/alicloud: Fix vpc and vswitch bugs while creating vpc and vswitch #15082

Merged
merged 1 commit into from
Jun 5, 2017
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
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