From 911c005c500b334d54aacc6fe26f225027ae9ed6 Mon Sep 17 00:00:00 2001 From: "guimin.hgm" Date: Tue, 3 Dec 2024 16:31:01 +0800 Subject: [PATCH] supports dingtalk message --- alicloud/alicloud_sweeper_test.go | 18 ++++- ...ud_cloud_firewall_instance_members_test.go | 1 + alicloud/provider_test.go | 71 +++++++++++++++++-- ...oud_cloud_firewall_instance_member_test.go | 3 +- ...e_alicloud_cloud_firewall_instance_test.go | 12 ++-- ...icloud_cloud_firewall_nat_firewall_test.go | 30 ++++---- ...cloud_firewall_vpc_cen_tr_firewall_test.go | 2 +- ...ud_cloud_firewall_vpc_firewall_cen_test.go | 2 +- ...rewall_vpc_firewall_control_policy_test.go | 4 +- ...icloud_cloud_firewall_vpc_firewall_test.go | 2 +- alicloud/service_alicloud_bss_open_api.go | 70 +++++++++++++++++- 11 files changed, 182 insertions(+), 33 deletions(-) diff --git a/alicloud/alicloud_sweeper_test.go b/alicloud/alicloud_sweeper_test.go index 4f461e237874..b3e7aec94bd4 100644 --- a/alicloud/alicloud_sweeper_test.go +++ b/alicloud/alicloud_sweeper_test.go @@ -2,8 +2,10 @@ package alicloud import ( "fmt" + "github.com/aliyun/credentials-go/credentials" "log" "os" + "strings" "sync" "testing" @@ -52,7 +54,7 @@ var endpoints sync.Map // sharedClientForRegion returns a common AlicloudClient setup needed for the sweeper // functions for a give n region func sharedClientForRegion(region string) (interface{}, error) { - var accessKey, secretKey string + var accessKey, secretKey, securityToken string if accessKey = os.Getenv("ALICLOUD_ACCESS_KEY"); accessKey == "" { return nil, fmt.Errorf("empty ALICLOUD_ACCESS_KEY") } @@ -61,6 +63,8 @@ func sharedClientForRegion(region string) (interface{}, error) { return nil, fmt.Errorf("empty ALICLOUD_SECRET_KEY") } + securityToken = os.Getenv("ALICLOUD_SECURITY_TOKEN") + conf := connectivity.Config{ Region: connectivity.Region(region), RegionId: region, @@ -69,9 +73,21 @@ func sharedClientForRegion(region string) (interface{}, error) { Protocol: "HTTPS", Endpoints: &endpoints, } + if securityToken != "" { + conf.SecurityToken = securityToken + } if accountId := os.Getenv("ALICLOUD_ACCOUNT_ID"); accountId != "" { conf.AccountId = accountId } + credentialConfig := new(credentials.Config).SetType("access_key").SetAccessKeyId(accessKey).SetAccessKeySecret(secretKey) + if v := strings.TrimSpace(securityToken); v != "" { + credentialConfig.SetType("sts").SetSecurityToken(v) + } + credential, err := credentials.NewCredential(credentialConfig) + if err != nil { + return nil, err + } + conf.Credential = credential // configures a default client for the region, using the above env vars client, err := conf.Client() diff --git a/alicloud/data_source_alicloud_cloud_firewall_instance_members_test.go b/alicloud/data_source_alicloud_cloud_firewall_instance_members_test.go index 15a78f6fef4c..d4375c2662d1 100644 --- a/alicloud/data_source_alicloud_cloud_firewall_instance_members_test.go +++ b/alicloud/data_source_alicloud_cloud_firewall_instance_members_test.go @@ -63,6 +63,7 @@ variable "name" { resource "alicloud_resource_manager_account" "default" { display_name = var.name + abandon_able_check_id = ["SP_fc_fc"] } resource "alicloud_cloud_firewall_instance_member" "default" { diff --git a/alicloud/provider_test.go b/alicloud/provider_test.go index b0685a7b3278..31d69e3e0423 100644 --- a/alicloud/provider_test.go +++ b/alicloud/provider_test.go @@ -1,10 +1,12 @@ package alicloud import ( + "bytes" "encoding/json" "fmt" "io/ioutil" "log" + "net/http" "os" "testing" "time" @@ -65,10 +67,34 @@ func testAccPreCheck(t *testing.T) { } } -func testAccPreCheckForIntl(t *testing.T) { - if strings.TrimSpace(os.Getenv("ALIBABA_CLOUD_ACCOUNT_TYPE")) != "International" { - t.Skipf("Skipping %s Site.", "International") - t.Skipped() +func testAccPreCheckForCleanUpInstances(t *testing.T, instanceRegion, productCode, productType, productCodeIntl, productTypeIntl string) { + rawClient, err := sharedClientForRegion(defaultRegionToTest) + if err != nil { + t.Errorf("error getting AliCloud client: %s", err) + } + client := rawClient.(*connectivity.AliyunClient) + bssOpenApiService := BssOpenApiService{client} + accountId, err := client.AccountId() + if err != nil { + t.Errorf("error getting AliCloud client: %s", err) + } + instances, err := bssOpenApiService.QueryAvailableInstanceList(instanceRegion, productCode, productType, productCodeIntl, productTypeIntl) + if err != nil { + t.Errorf("error querying available instances: %s", err) + } + for _, instance := range instances { + v := instance.(map[string]interface{}) + if v["Status"].(string) != "Normal" { + continue + } + sendMessage(fmt.Sprintf(` +[Critical] Please cleaning up instance before running integration test. + +AccountId: %s +ProductCode: %s +InstanceId: %s +`, accountId, productCode, v["InstanceID"])) + time.Sleep(3 * time.Minute) } } @@ -423,6 +449,43 @@ func testAccPreCheckWithResourceManagerHandshakesSetting(t *testing.T) { } } +type DingTalkMessage struct { + MsgType string `json:"msgtype"` + Text struct { + Content string `json:"content"` + } `json:"text"` +} + +func sendMessage(msg string) { + // 钉钉机器人的 Webhook 地址 + webhookURL := "https://oapi.dingtalk.com/robot/send?access_token=" + os.Getenv("DINGTALK_WEBHOOK_ACCESS_TOKEN") + + // 构建消息内容 + message := DingTalkMessage{ + MsgType: "text", + Text: struct { + Content string `json:"content"` + }{ + Content: msg, + }, + } + + // 将消息内容转换为 JSON 格式 + jsonData, err := json.Marshal(message) + if err != nil { + fmt.Println("[ERROR] send dingTalk message failed. Error:", err) + return + } + + // 发送 POST 请求 + resp, err := http.Post(webhookURL, "application/json", bytes.NewBuffer(jsonData)) + if err != nil { + fmt.Println("[ERROR] send dingTalk message failed. Error:", err) + return + } + defer resp.Body.Close() +} + func setStsCredential() { // 创建OSSClient实例。 client, err := oss.New("https://oss-cn-zhangjiakou.aliyuncs.com", os.Getenv("ALICLOUD_ACCESS_KEY"), os.Getenv("ALICLOUD_SECRET_KEY")) diff --git a/alicloud/resource_alicloud_cloud_firewall_instance_member_test.go b/alicloud/resource_alicloud_cloud_firewall_instance_member_test.go index d2eaaed5234b..0fd5b67fcb48 100644 --- a/alicloud/resource_alicloud_cloud_firewall_instance_member_test.go +++ b/alicloud/resource_alicloud_cloud_firewall_instance_member_test.go @@ -32,7 +32,7 @@ func TestAccAlicloudCloudFirewallInstanceMember_basic(t *testing.T) { { Config: testAccConfig(map[string]interface{}{ "member_desc": "${var.name}", - "member_uid": "${alicloud_resource_manager_account.default.id}", + "member_uid": "${data.alicloud_resource_manager_accounts.default.ids.0}", }), Check: resource.ComposeTestCheckFunc( testAccCheck(map[string]string{ @@ -69,6 +69,7 @@ variable "name" { resource "alicloud_resource_manager_account" "default" { display_name = var.name + abandon_able_check_id = ["SP_fc_fc"] } `, name) } diff --git a/alicloud/resource_alicloud_cloud_firewall_instance_test.go b/alicloud/resource_alicloud_cloud_firewall_instance_test.go index cab746544d78..e941c1da219d 100644 --- a/alicloud/resource_alicloud_cloud_firewall_instance_test.go +++ b/alicloud/resource_alicloud_cloud_firewall_instance_test.go @@ -19,7 +19,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccAliCloudCloudFirewallAaInstance_basic0(t *testing.T) { +func TestAccAliCloudCloudFirewallInstance_basic0(t *testing.T) { var v map[string]interface{} resourceId := "alicloud_cloud_firewall_instance.default" ra := resourceAttrInit(resourceId, AliCloudCloudFirewallInstanceMap0) @@ -34,7 +34,7 @@ func TestAccAliCloudCloudFirewallAaInstance_basic0(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) - testAccPreCheckForIntl(t) + testAccPreCheckForCleanUpInstances(t, "", "vipcloudfw", "vipcloudfw", "cfw", "cfw_pre_intl") }, IDRefreshName: resourceId, Providers: testAccProviders, @@ -69,7 +69,7 @@ func TestAccAliCloudCloudFirewallAaInstance_basic0(t *testing.T) { }) } -func TestAccAliCloudCloudFirewallAaInstance_basic0_twin(t *testing.T) { +func TestAccAliCloudCloudFirewallInstance_basic0_twin(t *testing.T) { var v map[string]interface{} resourceId := "alicloud_cloud_firewall_instance.default" ra := resourceAttrInit(resourceId, AliCloudCloudFirewallInstanceMap0) @@ -84,7 +84,7 @@ func TestAccAliCloudCloudFirewallAaInstance_basic0_twin(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) - testAccPreCheckForIntl(t) + testAccPreCheckForCleanUpInstances(t, "", "vipcloudfw", "vipcloudfw", "cfw", "cfw_pre_intl") }, IDRefreshName: resourceId, Providers: testAccProviders, @@ -113,7 +113,7 @@ func TestAccAliCloudCloudFirewallAaInstance_basic0_twin(t *testing.T) { }) } -func TestAccAliCloudCloudFirewallA0Instance_basic1(t *testing.T) { +func TestAccAliCloudCloudFirewallInstance_basic1(t *testing.T) { var v map[string]interface{} resourceId := "alicloud_cloud_firewall_instance.default" ra := resourceAttrInit(resourceId, AliCloudCloudFirewallInstanceMap0) @@ -128,7 +128,7 @@ func TestAccAliCloudCloudFirewallA0Instance_basic1(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) - testAccPreCheckForIntl(t) + testAccPreCheckForCleanUpInstances(t, "", "vipcloudfw", "vipcloudfw", "cfw", "cfw_pre_intl") }, IDRefreshName: resourceId, Providers: testAccProviders, diff --git a/alicloud/resource_alicloud_cloud_firewall_nat_firewall_test.go b/alicloud/resource_alicloud_cloud_firewall_nat_firewall_test.go index 3c69d97b956b..37405bccf518 100644 --- a/alicloud/resource_alicloud_cloud_firewall_nat_firewall_test.go +++ b/alicloud/resource_alicloud_cloud_firewall_nat_firewall_test.go @@ -11,9 +11,9 @@ import ( // Test CloudFirewall NatFirewall. >>> Resource test cases, automatically generated. // Case 云防火墙资源测试-v1 6822 -func TestAccAliCloudCloudFirewallA0NatFirewall_basic6822(t *testing.T) { +func TestAccAliCloudCloudFirewallNatFirewall_basic6822(t *testing.T) { var v map[string]interface{} - checkoutSupportedRegions(t, true, []connectivity.Region{"cn-shenzhen"}) + checkoutSupportedRegions(t, true, []connectivity.Region{"cn-hangzhou"}) resourceId := "alicloud_cloud_firewall_nat_firewall.default" ra := resourceAttrInit(resourceId, AlicloudCloudFirewallNatFirewallMap6822) rc := resourceCheckInitWithDescribeMethod(resourceId, &v, func() interface{} { @@ -27,7 +27,6 @@ func TestAccAliCloudCloudFirewallA0NatFirewall_basic6822(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) - //testAccPreCheckWithRegions(t, true, []connectivity.Region{"cn-shenzhen"}) }, IDRefreshName: resourceId, Providers: testAccProviders, @@ -36,7 +35,7 @@ func TestAccAliCloudCloudFirewallA0NatFirewall_basic6822(t *testing.T) { { Config: testAccConfig(map[string]interface{}{ "status": "normal", - "region_no": "cn-shenzhen", + "region_no": "${data.alicloud_regions.current.ids.0}", "vswitch_auto": "true", "strict_mode": "0", "vpc_id": "${alicloud_vpc.defaultikZ0gD.id}", @@ -57,7 +56,7 @@ func TestAccAliCloudCloudFirewallA0NatFirewall_basic6822(t *testing.T) { }), Check: resource.ComposeTestCheckFunc( testAccCheck(map[string]string{ - "region_no": "cn-shenzhen", + "region_no": defaultRegionToTest, "vpc_id": CHECKSET, "proxy_name": "YQC-防火墙测试", "nat_gateway_id": CHECKSET, @@ -87,7 +86,7 @@ func TestAccAliCloudCloudFirewallA0NatFirewall_basic6822(t *testing.T) { }, { Config: testAccConfig(map[string]interface{}{ - "region_no": "cn-shenzhen", + "region_no": "${data.alicloud_regions.current.ids.0}", "vswitch_auto": "true", "strict_mode": "0", "vpc_id": "${alicloud_vpc.defaultikZ0gD.id}", @@ -109,7 +108,7 @@ func TestAccAliCloudCloudFirewallA0NatFirewall_basic6822(t *testing.T) { }), Check: resource.ComposeTestCheckFunc( testAccCheck(map[string]string{ - "region_no": "cn-shenzhen", + "region_no": defaultRegionToTest, "vswitch_auto": "true", "strict_mode": "0", "vpc_id": CHECKSET, @@ -144,6 +143,9 @@ variable "name" { default = "%s" } +data "alicloud_regions" "current" { + current = true +} data "alicloud_zones" "default" { available_resource_creation = "VSwitch" } @@ -192,9 +194,9 @@ resource "alicloud_snat_entry" "defaultAKE43g" { } // Case 云防火墙资源测试-v1 6822 twin -func TestAccAliCloudCloudFirewallA0NatFirewall_basic6822_twin(t *testing.T) { +func TestAccAliCloudCloudFirewallNatFirewall_basic6822_twin(t *testing.T) { var v map[string]interface{} - checkoutSupportedRegions(t, true, []connectivity.Region{"cn-shenzhen"}) + checkoutSupportedRegions(t, true, []connectivity.Region{"cn-hangzhou"}) resourceId := "alicloud_cloud_firewall_nat_firewall.default" ra := resourceAttrInit(resourceId, AlicloudCloudFirewallNatFirewallMap6822) rc := resourceCheckInitWithDescribeMethod(resourceId, &v, func() interface{} { @@ -216,7 +218,7 @@ func TestAccAliCloudCloudFirewallA0NatFirewall_basic6822_twin(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccConfig(map[string]interface{}{ - "region_no": "cn-shenzhen", + "region_no": "${data.alicloud_regions.current.ids.0}", "vswitch_auto": "true", "strict_mode": "0", "vpc_id": "${alicloud_vpc.defaultikZ0gD.id}", @@ -238,7 +240,7 @@ func TestAccAliCloudCloudFirewallA0NatFirewall_basic6822_twin(t *testing.T) { }), Check: resource.ComposeTestCheckFunc( testAccCheck(map[string]string{ - "region_no": "cn-shenzhen", + "region_no": defaultRegionToTest, "vswitch_auto": "true", "strict_mode": "0", "vpc_id": CHECKSET, @@ -264,9 +266,9 @@ func TestAccAliCloudCloudFirewallA0NatFirewall_basic6822_twin(t *testing.T) { } // Case 云防火墙资源测试-v1 6822 raw -func TestAccAliCloudCloudFirewallA0NatFirewall_basic6822_raw(t *testing.T) { +func TestAccAliCloudCloudFirewallNatFirewall_basic6822_raw(t *testing.T) { var v map[string]interface{} - checkoutSupportedRegions(t, true, []connectivity.Region{"cn-shenzhen"}) + checkoutSupportedRegions(t, true, []connectivity.Region{"cn-hangzhou"}) resourceId := "alicloud_cloud_firewall_nat_firewall.default" ra := resourceAttrInit(resourceId, AlicloudCloudFirewallNatFirewallMap6822) rc := resourceCheckInitWithDescribeMethod(resourceId, &v, func() interface{} { @@ -288,7 +290,7 @@ func TestAccAliCloudCloudFirewallA0NatFirewall_basic6822_raw(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccConfig(map[string]interface{}{ - "region_no": defaultRegionToTest, + "region_no": "${data.alicloud_regions.current.ids.0}", "vswitch_auto": "true", "strict_mode": "0", "vpc_id": "${alicloud_vpc.defaultikZ0gD.id}", diff --git a/alicloud/resource_alicloud_cloud_firewall_vpc_cen_tr_firewall_test.go b/alicloud/resource_alicloud_cloud_firewall_vpc_cen_tr_firewall_test.go index 5d5218b56b63..5c800173680d 100644 --- a/alicloud/resource_alicloud_cloud_firewall_vpc_cen_tr_firewall_test.go +++ b/alicloud/resource_alicloud_cloud_firewall_vpc_cen_tr_firewall_test.go @@ -125,7 +125,7 @@ resource "alicloud_cen_transit_router_vpc_attachment" "tr-vpc1" { } // Case VpcCenTrFirewall全生命周期测试_副本1689148389922 3609 raw -func TestAccAliCloudCloudFirewallA0VpcCenTrFirewall_basic3609_raw(t *testing.T) { +func TestAccAliCloudCloudFirewallVpcCenTrFirewall_basic3609_raw(t *testing.T) { var v map[string]interface{} checkoutSupportedRegions(t, true, []connectivity.Region{"cn-shanghai"}) resourceId := "alicloud_cloud_firewall_vpc_cen_tr_firewall.default" diff --git a/alicloud/resource_alicloud_cloud_firewall_vpc_firewall_cen_test.go b/alicloud/resource_alicloud_cloud_firewall_vpc_firewall_cen_test.go index c2f0e95827a6..c31068d36eb4 100644 --- a/alicloud/resource_alicloud_cloud_firewall_vpc_firewall_cen_test.go +++ b/alicloud/resource_alicloud_cloud_firewall_vpc_firewall_cen_test.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccAliCloudCloudFirewallA0VpcFirewallCen_basic(t *testing.T) { +func TestAccAliCloudCloudFirewallVpcFirewallCen_basic(t *testing.T) { var v map[string]interface{} //checkoutSupportedRegions(t, true, connectivity.CloudFirewallVpcFirewallCenSupportRegions) resourceId := "alicloud_cloud_firewall_vpc_firewall_cen.default" diff --git a/alicloud/resource_alicloud_cloud_firewall_vpc_firewall_control_policy_test.go b/alicloud/resource_alicloud_cloud_firewall_vpc_firewall_control_policy_test.go index ac8ea79a7744..96b41b05f83f 100644 --- a/alicloud/resource_alicloud_cloud_firewall_vpc_firewall_control_policy_test.go +++ b/alicloud/resource_alicloud_cloud_firewall_vpc_firewall_control_policy_test.go @@ -19,7 +19,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccAliCloudCloudFirewallA0VpcFirewallControlPolicy_basic0(t *testing.T) { +func TestAccAliCloudCloudFirewallVpcFirewallControlPolicy_basic0(t *testing.T) { var v map[string]interface{} resourceId := "alicloud_cloud_firewall_vpc_firewall_control_policy.default" ra := resourceAttrInit(resourceId, AliCloudCloudFirewallVpcFirewallControlPolicyMap0) @@ -203,7 +203,7 @@ func TestAccAliCloudCloudFirewallA0VpcFirewallControlPolicy_basic0(t *testing.T) }) } -func TestAccAliCloudCloudFirewallA0VpcFirewallControlPolicy_basic1(t *testing.T) { +func TestAccAliCloudCloudFirewallVpcFirewallControlPolicy_basic1(t *testing.T) { var v map[string]interface{} resourceId := "alicloud_cloud_firewall_vpc_firewall_control_policy.default" ra := resourceAttrInit(resourceId, AliCloudCloudFirewallVpcFirewallControlPolicyMap0) diff --git a/alicloud/resource_alicloud_cloud_firewall_vpc_firewall_test.go b/alicloud/resource_alicloud_cloud_firewall_vpc_firewall_test.go index f4da35f7dfa5..99b3d9d4a481 100644 --- a/alicloud/resource_alicloud_cloud_firewall_vpc_firewall_test.go +++ b/alicloud/resource_alicloud_cloud_firewall_vpc_firewall_test.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccAliCloudCloudfirewallA0VpcFirewall_basic(t *testing.T) { +func TestAccAliCloudCloudfirewallVpcFirewall_basic(t *testing.T) { var v map[string]interface{} checkoutSupportedRegions(t, true, connectivity.CloudFirewallVpcFirewallSupportRegions) resourceId := "alicloud_cloud_firewall_vpc_firewall.default" diff --git a/alicloud/service_alicloud_bss_open_api.go b/alicloud/service_alicloud_bss_open_api.go index b03765c97073..12ea82a0269b 100644 --- a/alicloud/service_alicloud_bss_open_api.go +++ b/alicloud/service_alicloud_bss_open_api.go @@ -22,10 +22,12 @@ func (s *BssOpenApiService) QueryAvailableInstances(id, instanceRegion, productC } action := "QueryAvailableInstances" request := map[string]interface{}{ - "InstanceIDs": id, "ProductCode": productCode, "ProductType": productType, } + if id != "" { + request["InstanceIDs"] = id + } if instanceRegion != "" { request["Region"] = instanceRegion } @@ -78,7 +80,7 @@ func (s *BssOpenApiService) QueryAvailableInstances(id, instanceRegion, productC } if len(v.([]interface{})) < 1 { return object, WrapErrorf(Error(GetNotFoundMessage(productCode+"Instance", id)), NotFoundWithResponse, response) - } else { + } else if id != "" { if fmt.Sprint(v.([]interface{})[0].(map[string]interface{})["InstanceID"]) != id { return object, WrapErrorf(Error(GetNotFoundMessage(productCode+"Instance", id)), NotFoundWithResponse, response) } @@ -320,3 +322,67 @@ func (s *BssOpenApiService) CloudFirewallInstanceOrderDetailStateRefreshFunc(ord return object, object["PaymentStatus"].(string), nil } } + +func (s *BssOpenApiService) QueryAvailableInstanceList(instanceRegion, productCode, productType, productCodeIntl, productTypeIntl string) (object []interface{}, err error) { + var response map[string]interface{} + conn, err := s.client.NewBssopenapiClient() + if err != nil { + return nil, WrapError(err) + } + action := "QueryAvailableInstances" + request := map[string]interface{}{ + "ProductCode": productCode, + "ProductType": productType, + } + if instanceRegion != "" { + request["Region"] = instanceRegion + } + 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("2017-12-14"), StringPointer("AK"), nil, request, &runtime) + if err != nil { + if NeedRetry(err) { + wait() + return resource.RetryableError(err) + } + if IsExpectedErrors(err, []string{"NotApplicable", "SignatureDoesNotMatch"}) { + conn.Endpoint = String(connectivity.BssOpenAPIEndpointInternational) + request["ProductCode"] = productCodeIntl + request["ProductType"] = productTypeIntl + return resource.RetryableError(err) + } + return resource.NonRetryableError(err) + } + resp, _ := jsonpath.Get("$.Data.InstanceList", response) + if len(resp.([]interface{})) < 1 { + request["ProductCode"] = productCodeIntl + if productTypeIntl != "" { + request["ProductType"] = productTypeIntl + } + conn.Endpoint = String(connectivity.BssOpenAPIEndpointInternational) + response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2017-12-14"), 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 { + return object, WrapError(err) + } + if fmt.Sprint(response["Code"]) != "Success" { + return object, WrapError(fmt.Errorf("%s failed, response: %v", action, response)) + } + v, err := jsonpath.Get("$.Data.InstanceList", response) + if err != nil { + return object, WrapError(err) + } + return v.([]interface{}), nil +}