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

resource/alicloud_kvstore_instance: fix bug for creating status polling. #7318

Merged
merged 1 commit into from
Jun 4, 2024
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
2 changes: 1 addition & 1 deletion alicloud/resource_alicloud_kvstore_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ func resourceAliCloudKvstoreInstanceCreate(d *schema.ResourceData, meta interfac

d.SetId(fmt.Sprintf("%v", response.InstanceId))

stateConf := BuildStateConf([]string{}, []string{"Normal"}, d.Timeout(schema.TimeoutCreate), 180*time.Second, r_kvstoreService.KvstoreInstanceStateRefreshFunc(d.Id(), []string{}))
stateConf := BuildStateConf([]string{}, []string{"Normal"}, d.Timeout(schema.TimeoutCreate), 180*time.Second, r_kvstoreService.KvstoreInstancesStateRefreshFunc(d.Id(), []string{}))
if _, err := stateConf.WaitForState(); err != nil {
return WrapErrorf(err, IdMsg, d.Id())
}
Expand Down
18 changes: 11 additions & 7 deletions alicloud/resource_alicloud_kvstore_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ func TestAccAliCloudKVStoreRedisInstance_vpctest(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccPreCheckWithRegions(t, true, []connectivity.Region{"cn-hangzhou"})
},
IDRefreshName: resourceId,
Providers: testAccProviders,
Expand Down Expand Up @@ -211,15 +212,15 @@ func TestAccAliCloudKVStoreRedisInstance_vpctest(t *testing.T) {
"config": map[string]string{
"appendonly": "no",
"lazyfree-lazy-eviction": "no",
"EvictionPolicy": "volatile-lru",
"maxmemory-policy": "volatile-lru",
},
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"config.%": "3",
"config.appendonly": "no",
"config.lazyfree-lazy-eviction": "no",
"config.EvictionPolicy": "volatile-lru",
"config.maxmemory-policy": "volatile-lru",
}),
),
},
Expand Down Expand Up @@ -381,7 +382,7 @@ func TestAccAliCloudKVStoreRedisInstance_vpctest(t *testing.T) {
"config": map[string]string{
"appendonly": "yes",
"lazyfree-lazy-eviction": "yes",
"EvictionPolicy": "volatile-lru",
"maxmemory-policy": "volatile-lru",
},
"tags": map[string]string{
"Created": "TF",
Expand Down Expand Up @@ -414,7 +415,7 @@ func TestAccAliCloudKVStoreRedisInstance_vpctest(t *testing.T) {
"config.%": "3",
"config.appendonly": "yes",
"config.lazyfree-lazy-eviction": "yes",
"config.EvictionPolicy": "volatile-lru",
"config.maxmemory-policy": "volatile-lru",
"tags.%": "2",
"tags.Created": "TF",
"tags.For": "acceptance test",
Expand Down Expand Up @@ -449,6 +450,7 @@ func TestAccAliCloudKVStoreRedisInstance_6_0(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccPreCheckWithRegions(t, true, []connectivity.Region{"cn-hangzhou"})
},
IDRefreshName: resourceId,
Providers: testAccProviders,
Expand Down Expand Up @@ -757,6 +759,7 @@ func TestAccAliCloudKVStoreRedisInstance_7_0(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccPreCheckWithRegions(t, true, []connectivity.Region{"cn-hangzhou"})
},
IDRefreshName: resourceId,
Providers: testAccProviders,
Expand Down Expand Up @@ -1022,6 +1025,7 @@ func TestAccAliCloudKVStoreRedisInstance_7_0_with_proxy_class(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccPreCheckWithRegions(t, true, []connectivity.Region{"cn-hangzhou"})
},
IDRefreshName: resourceId,
Providers: testAccProviders,
Expand Down Expand Up @@ -1829,7 +1833,7 @@ func TestAccAliCloudKVStoreRedisInstance_prepaid(t *testing.T) {
func TestAccAliCloudKVStoreRedisInstance_5_0_memory_classic_standard(t *testing.T) {
var v r_kvstore.DBInstanceAttribute
// en-central-1 has no enough quota for this class
checkoutSupportedRegions(t, true, []connectivity.Region{connectivity.APSouthEast1, connectivity.Hangzhou})
checkoutSupportedRegions(t, true, []connectivity.Region{connectivity.Hangzhou})
resourceId := "alicloud_kvstore_instance.default"
ra := resourceAttrInit(resourceId, RedisDbInstanceMap)
rc := resourceCheckInitWithDescribeMethod(resourceId, &v, func() interface{} {
Expand Down Expand Up @@ -2112,7 +2116,7 @@ func TestAccAliCloudKVStoreRedisInstance_5_0_memory_classic_standard(t *testing.
func TestAccAliCloudKVStoreRedisInstance_5_0_memory_classic_cluster(t *testing.T) {
var v r_kvstore.DBInstanceAttribute
// en-central-1 has no enough quota for this class
checkoutSupportedRegions(t, true, []connectivity.Region{connectivity.APSouthEast1, connectivity.Hangzhou})
checkoutSupportedRegions(t, true, []connectivity.Region{connectivity.Hangzhou})
resourceId := "alicloud_kvstore_instance.default"
ra := resourceAttrInit(resourceId, RedisDbInstanceMap)
rc := resourceCheckInitWithDescribeMethod(resourceId, &v, func() interface{} {
Expand Down Expand Up @@ -2402,7 +2406,7 @@ func KvstoreInstanceVpcTestdependence(name string) string {
instance_charge_type = "PostPaid"
}
data "alicloud_vpcs" "default" {
name_regex = "^default-NODELETING$"
name_regex = "^default-NODELETING-Redis$"
cidr_block = "192.168.0.0/16"
}
data "alicloud_vswitches" "default" {
Expand Down
64 changes: 64 additions & 0 deletions alicloud/service_alicloud_r_kvstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,70 @@ func (s *R_kvstoreService) KvstoreInstanceAttributeRefreshFunc(id, attribute str
}
}

func (s *R_kvstoreService) DescribeKvstoreInstances(id string) (object map[string]interface{}, err error) {
var response map[string]interface{}
conn, err := s.client.NewRedisaClient()
if err != nil {
return nil, WrapError(err)
}
action := "DescribeInstances"
request := map[string]interface{}{
"RegionId": s.client.RegionId,
"InstanceIds": id,
}
runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
wait := incrementalWait(3*time.Second, 3*time.Second)
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), nil, request, &runtime)
if err != nil {
if NeedRetry(err) {
wait()
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
return nil
})
addDebug(action, response, request)
if err != nil {
if IsExpectedErrors(err, []string{"InvalidInstanceId.NotFound"}) {
err = WrapErrorf(Error(GetNotFoundMessage("KvstoreInstance", id)), NotFoundMsg, ProviderERROR)
return object, err
}
err = WrapErrorf(err, DefaultErrorMsg, id, action, AlibabaCloudSdkGoERROR)
return object, err
}
v, err := jsonpath.Get("$.Instances.KVStoreInstance", response)
if err != nil {
return object, WrapErrorf(err, FailedGetAttributeMsg, id, "$.Instances", response)
}
if v == nil || len(v.([]interface{})) < 1 || fmt.Sprint(v.([]interface{})[0].(map[string]interface{})["InstanceId"]) != id {
return object, WrapErrorf(Error(GetNotFoundMessage("Redis", id)), NotFoundWithResponse, response)
}
return v.([]interface{})[0].(map[string]interface{}), nil
}

func (s *R_kvstoreService) KvstoreInstancesStateRefreshFunc(id string, failStates []string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
object, err := s.DescribeKvstoreInstances(id)
if err != nil {
if NotFoundError(err) {
// Set this to nil as if we didn't find anything.
return nil, "", nil
}
return nil, "", WrapError(err)
}

for _, failState := range failStates {
if object["InstanceStatus"] == failState {
return object, fmt.Sprint(object["InstanceStatus"]), WrapError(Error(FailedToReachTargetStatus, fmt.Sprint(object["InstanceStatus"])))
}
}
return object, fmt.Sprint(object["InstanceStatus"]), nil
}
}

func (s *R_kvstoreService) DescribeKvstoreInstanceDeleted(id string) (object map[string]interface{}, err error) {
var response map[string]interface{}
conn, err := s.client.NewRedisaClient()
Expand Down
Loading