mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
fix vpc and vswitch bug while creating vpc and vswitch (#15082)
This commit is contained in:
parent
eed23bd803
commit
0b63007142
@ -36,6 +36,9 @@ const (
|
|||||||
// ess
|
// ess
|
||||||
InvalidScalingGroupIdNotFound = "InvalidScalingGroupId.NotFound"
|
InvalidScalingGroupIdNotFound = "InvalidScalingGroupId.NotFound"
|
||||||
IncorrectScalingConfigurationLifecycleState = "IncorrectScalingConfigurationLifecycleState"
|
IncorrectScalingConfigurationLifecycleState = "IncorrectScalingConfigurationLifecycleState"
|
||||||
|
|
||||||
|
//unknown Error
|
||||||
|
UnknownError = "UnknownError"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetNotFoundErrorFromString(str string) error {
|
func GetNotFoundErrorFromString(str string) error {
|
||||||
|
@ -2,11 +2,11 @@ package alicloud
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"github.com/denverdino/aliyungo/common"
|
||||||
|
|
||||||
"github.com/denverdino/aliyungo/ecs"
|
"github.com/denverdino/aliyungo/ecs"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -73,9 +73,20 @@ func resourceAliyunVpcCreate(d *schema.ResourceData, meta interface{}) error {
|
|||||||
|
|
||||||
ecsconn := meta.(*AliyunClient).ecsconn
|
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 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)
|
d.SetId(vpc.VpcId)
|
||||||
|
@ -56,9 +56,21 @@ func resourceAliyunSwitchCreate(d *schema.ResourceData, meta interface{}) error
|
|||||||
return err
|
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 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)
|
d.SetId(vswitchID)
|
||||||
|
Loading…
Reference in New Issue
Block a user