From 8b131da8644f8cd132d073898566d79fee86733b Mon Sep 17 00:00:00 2001 From: "guimin.hgm" Date: Fri, 18 Oct 2024 10:23:49 +0800 Subject: [PATCH] DCDN: Improves the invoking dcdn api method and supports refreshing credential automatically --- alicloud/data_source_alicloud_dcdn_domains.go | 10 +- .../data_source_alicloud_dcdn_domains_test.go | 1 + .../data_source_alicloud_dcdn_ipa_domains.go | 10 +- ...a_source_alicloud_dcdn_ipa_domains_test.go | 4 +- .../data_source_alicloud_dcdn_waf_domains.go | 10 +- .../data_source_alicloud_dcdn_waf_policies.go | 10 +- .../data_source_alicloud_dcdn_waf_rules.go | 11 +- alicloud/resource_alicloud_dcdn_domain.go | 60 ++----- .../resource_alicloud_dcdn_domain_config.go | 28 +--- .../resource_alicloud_dcdn_domain_test.go | 75 +++++---- alicloud/resource_alicloud_dcdn_er.go | 29 +--- alicloud/resource_alicloud_dcdn_ipa_domain.go | 26 +-- .../resource_alicloud_dcdn_ipa_domain_test.go | 13 +- alicloud/resource_alicloud_dcdn_kv.go | 27 +-- .../resource_alicloud_dcdn_kv_namespace.go | 18 +- alicloud/resource_alicloud_dcdn_waf_domain.go | 22 +-- alicloud/resource_alicloud_dcdn_waf_policy.go | 22 +-- ...cloud_dcdn_waf_policy_domain_attachment.go | 14 +- .../resource_alicloud_dcdn_waf_policy_test.go | 13 +- alicloud/resource_alicloud_dcdn_waf_rule.go | 27 +-- alicloud/service_alicloud_dcdn.go | 155 ++++-------------- alicloud/service_alicloud_dcdn_v2.go | 25 +-- website/docs/d/dcdn_domains.html.markdown | 46 +++--- website/docs/d/dcdn_ipa_domains.html.markdown | 40 ++--- website/docs/d/dcdn_kv_account.html.markdown | 2 +- website/docs/d/dcdn_waf_domains.html.markdown | 6 +- .../docs/d/dcdn_waf_policies.html.markdown | 6 +- 27 files changed, 215 insertions(+), 495 deletions(-) diff --git a/alicloud/data_source_alicloud_dcdn_domains.go b/alicloud/data_source_alicloud_dcdn_domains.go index 0dcc9753455b..9a17f7c5a2ef 100644 --- a/alicloud/data_source_alicloud_dcdn_domains.go +++ b/alicloud/data_source_alicloud_dcdn_domains.go @@ -5,7 +5,6 @@ import ( "regexp" "github.com/PaesslerAG/jsonpath" - util "github.com/alibabacloud-go/tea-utils/service" "github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/helper/validation" @@ -214,14 +213,9 @@ func dataSourceAlicloudDcdnDomainsRead(d *schema.ResourceData, meta interface{}) } } var response map[string]interface{} - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error for { - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, true) if err != nil { return WrapErrorf(err, DataDefaultErrorMsg, "alicloud_dcdn_domains", action, AlibabaCloudSdkGoERROR) } diff --git a/alicloud/data_source_alicloud_dcdn_domains_test.go b/alicloud/data_source_alicloud_dcdn_domains_test.go index be66a81f5c76..0746c721cfe0 100644 --- a/alicloud/data_source_alicloud_dcdn_domains_test.go +++ b/alicloud/data_source_alicloud_dcdn_domains_test.go @@ -110,6 +110,7 @@ resource "alicloud_dcdn_domain" "default" { port = "80" priority = "20" type = "ipaddr" + weight = 10 } resource_group_id = data.alicloud_resource_manager_resource_groups.default.ids.0 scope = "overseas" diff --git a/alicloud/data_source_alicloud_dcdn_ipa_domains.go b/alicloud/data_source_alicloud_dcdn_ipa_domains.go index 6e7af1e62e24..6a6fa7a7b87c 100644 --- a/alicloud/data_source_alicloud_dcdn_ipa_domains.go +++ b/alicloud/data_source_alicloud_dcdn_ipa_domains.go @@ -5,7 +5,6 @@ import ( "time" "github.com/PaesslerAG/jsonpath" - util "github.com/alibabacloud-go/tea-utils/service" "github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" @@ -157,16 +156,11 @@ func dataSourceAlicloudDcdnIpaDomainsRead(d *schema.ResourceData, meta interface } } var response map[string]interface{} - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error for { - 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("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() diff --git a/alicloud/data_source_alicloud_dcdn_ipa_domains_test.go b/alicloud/data_source_alicloud_dcdn_ipa_domains_test.go index a48edea3accf..f3876d0713ba 100644 --- a/alicloud/data_source_alicloud_dcdn_ipa_domains_test.go +++ b/alicloud/data_source_alicloud_dcdn_ipa_domains_test.go @@ -64,7 +64,7 @@ func TestAccAlicloudDCDNIpaDomainsDataSource(t *testing.T) { "domains.0.description": "", "domains.0.id": CHECKSET, "domains.0.resource_group_id": CHECKSET, - "domains.0.scope": "domestic", + "domains.0.scope": "overseas", "domains.0.sources.#": "1", "domains.0.sources.0.content": "www.alicloud-provider.cn", "domains.0.sources.0.port": "8898", @@ -108,7 +108,7 @@ variable "domain_name" { resource "alicloud_dcdn_ipa_domain" "default" { domain_name = "${var.domain_name}" - scope = "domestic" + scope = "overseas" sources { content = "www.alicloud-provider.cn" port = 8898 diff --git a/alicloud/data_source_alicloud_dcdn_waf_domains.go b/alicloud/data_source_alicloud_dcdn_waf_domains.go index b4fcd2c251a7..c44450d7f98e 100644 --- a/alicloud/data_source_alicloud_dcdn_waf_domains.go +++ b/alicloud/data_source_alicloud_dcdn_waf_domains.go @@ -5,7 +5,6 @@ import ( "time" "github.com/PaesslerAG/jsonpath" - util "github.com/alibabacloud-go/tea-utils/service" "github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" @@ -97,16 +96,11 @@ func dataSourceAlicloudDcdnWafDomainsRead(d *schema.ResourceData, meta interface } } var response map[string]interface{} - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error for { - 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("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() diff --git a/alicloud/data_source_alicloud_dcdn_waf_policies.go b/alicloud/data_source_alicloud_dcdn_waf_policies.go index 98cbd0e7bac2..574deb1970af 100644 --- a/alicloud/data_source_alicloud_dcdn_waf_policies.go +++ b/alicloud/data_source_alicloud_dcdn_waf_policies.go @@ -6,7 +6,6 @@ import ( "time" "github.com/PaesslerAG/jsonpath" - util "github.com/alibabacloud-go/tea-utils/service" "github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" @@ -125,16 +124,11 @@ func dataSourceAlicloudDcdnWafPoliciesRead(d *schema.ResourceData, meta interfac } status, statusOk := d.GetOk("status") var response map[string]interface{} - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error for { - 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("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() diff --git a/alicloud/data_source_alicloud_dcdn_waf_rules.go b/alicloud/data_source_alicloud_dcdn_waf_rules.go index 56eb3798c289..c3ecde89ad1c 100644 --- a/alicloud/data_source_alicloud_dcdn_waf_rules.go +++ b/alicloud/data_source_alicloud_dcdn_waf_rules.go @@ -5,7 +5,6 @@ import ( "time" "github.com/PaesslerAG/jsonpath" - util "github.com/alibabacloud-go/tea-utils/service" "github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" @@ -225,20 +224,15 @@ func dataSourceAlicloudDcdnWafRulesRead(d *schema.ResourceData, meta interface{} } } - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error var objects []interface{} var response map[string]interface{} for { action := "DescribeDcdnWafRules" - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(5*time.Minute, func() *resource.RetryError { - resp, err := conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -246,7 +240,6 @@ func dataSourceAlicloudDcdnWafRulesRead(d *schema.ResourceData, meta interface{} } return resource.NonRetryableError(err) } - response = resp addDebug(action, response, request) return nil }) diff --git a/alicloud/resource_alicloud_dcdn_domain.go b/alicloud/resource_alicloud_dcdn_domain.go index 4cfee2956f1a..f8c04d1e507f 100644 --- a/alicloud/resource_alicloud_dcdn_domain.go +++ b/alicloud/resource_alicloud_dcdn_domain.go @@ -9,7 +9,6 @@ import ( "time" "github.com/PaesslerAG/jsonpath" - util "github.com/alibabacloud-go/tea-utils/service" "github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" @@ -168,10 +167,7 @@ func resourceAliCloudDcdnDomainCreate(d *schema.ResourceData, meta interface{}) var request map[string]interface{} var response map[string]interface{} query := make(map[string]interface{}) - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error request = make(map[string]interface{}) query["DomainName"] = d.Get("domain_name") @@ -219,11 +215,9 @@ func resourceAliCloudDcdnDomainCreate(d *schema.ResourceData, meta interface{}) request["Sources"] = string(sourcesMapsJson) } - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, query, request, false) if err != nil { if IsExpectedErrors(err, []string{"ServiceBusy"}) || NeedRetry(err) { wait() @@ -360,10 +354,7 @@ func resourceAliCloudDcdnDomainUpdate(d *schema.ResourceData, meta interface{}) update := false d.Partial(true) action := "ModifyDCdnDomainSchdmByProperty" - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error request = make(map[string]interface{}) query = make(map[string]interface{}) query["DomainName"] = d.Id() @@ -374,11 +365,9 @@ func resourceAliCloudDcdnDomainUpdate(d *schema.ResourceData, meta interface{}) } if update { - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, query, request, false) if err != nil { if NeedRetry(err) { wait() @@ -400,10 +389,6 @@ func resourceAliCloudDcdnDomainUpdate(d *schema.ResourceData, meta interface{}) } update = false action = "UpdateDcdnDomain" - conn, err = client.NewDcdnClient() - if err != nil { - return WrapError(err) - } request = make(map[string]interface{}) query = make(map[string]interface{}) query["DomainName"] = d.Id() @@ -441,11 +426,9 @@ func resourceAliCloudDcdnDomainUpdate(d *schema.ResourceData, meta interface{}) request["TopLevelDomain"] = v } if update { - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, query, request, false) if err != nil { if NeedRetry(err) { wait() @@ -475,10 +458,6 @@ func resourceAliCloudDcdnDomainUpdate(d *schema.ResourceData, meta interface{}) update = false action = "SetDcdnDomainSSLCertificate" - conn, err = client.NewDcdnClient() - if err != nil { - return WrapError(err) - } request = make(map[string]interface{}) query = make(map[string]interface{}) query["DomainName"] = d.Id() @@ -522,11 +501,9 @@ func resourceAliCloudDcdnDomainUpdate(d *schema.ResourceData, meta interface{}) request["Env"] = v } if update { - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, query, request, false) if err != nil { if NeedRetry(err) { wait() @@ -559,19 +536,13 @@ func resourceAliCloudDcdnDomainUpdate(d *schema.ResourceData, meta interface{}) if object["DomainStatus"].(string) != target { if target == "online" { action = "StartDcdnDomain" - conn, err = client.NewDcdnClient() - if err != nil { - return WrapError(err) - } request = make(map[string]interface{}) query = make(map[string]interface{}) query["DomainName"] = d.Id() - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, query, request, false) if err != nil { if NeedRetry(err) { wait() @@ -594,19 +565,13 @@ func resourceAliCloudDcdnDomainUpdate(d *schema.ResourceData, meta interface{}) } if target == "offline" { action = "StopDcdnDomain" - conn, err = client.NewDcdnClient() - if err != nil { - return WrapError(err) - } request = make(map[string]interface{}) query = make(map[string]interface{}) query["DomainName"] = d.Id() - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, query, request, false) if err != nil { if NeedRetry(err) { wait() @@ -641,18 +606,13 @@ func resourceAliCloudDcdnDomainDelete(d *schema.ResourceData, meta interface{}) var request map[string]interface{} var response map[string]interface{} query := make(map[string]interface{}) - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error request = make(map[string]interface{}) query["DomainName"] = d.Id() - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutDelete), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, query, request, false) if err != nil { if NeedRetry(err) { diff --git a/alicloud/resource_alicloud_dcdn_domain_config.go b/alicloud/resource_alicloud_dcdn_domain_config.go index 4bab62d6eb86..44923d45f1d0 100644 --- a/alicloud/resource_alicloud_dcdn_domain_config.go +++ b/alicloud/resource_alicloud_dcdn_domain_config.go @@ -7,7 +7,6 @@ import ( "github.com/PaesslerAG/jsonpath" - util "github.com/alibabacloud-go/tea-utils/service" "github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" @@ -73,10 +72,7 @@ func resourceAliCloudDcdnDomainConfigCreate(d *schema.ResourceData, meta interfa var response map[string]interface{} action := "BatchSetDcdnDomainConfigs" request := make(map[string]interface{}) - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error request["DomainNames"] = d.Get("domain_name").(string) @@ -107,11 +103,9 @@ func resourceAliCloudDcdnDomainConfigCreate(d *schema.ResourceData, meta interfa request["Functions"] = string(bytConfig) - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if IsExpectedErrors(err, []string{"FlowControlError"}) || NeedRetry(err) { wait() @@ -215,10 +209,6 @@ func resourceAliCloudDcdnDomainConfigUpdate(d *schema.ResourceData, meta interfa if d.HasChange("function_args") || d.HasChange("parent_id") { action := "BatchSetDcdnDomainConfigs" request := make(map[string]interface{}) - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } parts, err := ParseResourceId(d.Id(), 3) if err != nil { @@ -252,12 +242,9 @@ func resourceAliCloudDcdnDomainConfigUpdate(d *schema.ResourceData, meta interfa bytconfig, _ := json.Marshal(config) request["Functions"] = string(bytconfig) - - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if IsExpectedErrors(err, []string{"FlowControlError"}) || NeedRetry(err) { wait() @@ -288,10 +275,7 @@ func resourceAliCloudDcdnDomainConfigDelete(d *schema.ResourceData, meta interfa action := "DeleteDcdnSpecificConfig" var response map[string]interface{} - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error parts, err := ParseResourceId(d.Id(), 3) if err != nil { @@ -303,11 +287,9 @@ func resourceAliCloudDcdnDomainConfigDelete(d *schema.ResourceData, meta interfa "ConfigId": parts[2], } - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutDelete), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() diff --git a/alicloud/resource_alicloud_dcdn_domain_test.go b/alicloud/resource_alicloud_dcdn_domain_test.go index e7601fb78666..3ade1637ad6e 100644 --- a/alicloud/resource_alicloud_dcdn_domain_test.go +++ b/alicloud/resource_alicloud_dcdn_domain_test.go @@ -2,11 +2,11 @@ package alicloud import ( "fmt" + "github.com/PaesslerAG/jsonpath" "log" "strings" "testing" - - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" + "time" "github.com/aliyun/alibaba-cloud-sdk-go/services/dcdn" "github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity" @@ -29,50 +29,63 @@ func testSweepDcdnDomain(region string) error { return WrapError(err) } client := rawClient.(*connectivity.AliyunClient) - queryRequest := dcdn.CreateDescribeDcdnUserDomainsRequest() - var allDomains []dcdn.PageData - queryRequest.PageSize = requests.NewInteger(PageSizeLarge) - queryRequest.PageNumber = requests.NewInteger(1) + + action := "DescribeDcdnUserDomains" + request := make(map[string]interface{}) + request["PageSize"] = PageSizeLarge + request["PageNumber"] = 1 + + var allDomains []string + var response map[string]interface{} for { - raw, err := client.WithDcdnClient(func(dcdnClient *dcdn.Client) (interface{}, error) { - return dcdnClient.DescribeDcdnUserDomains(queryRequest) - }) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, true) if err != nil { - log.Printf("[ERROR] %s get an error %#v", queryRequest.GetActionName(), err) + return WrapErrorf(err, DataDefaultErrorMsg, "alicloud_dcdn_domains", action, AlibabaCloudSdkGoERROR) } - addDebug(queryRequest.GetActionName(), raw) - response, _ := raw.(*dcdn.DescribeDcdnUserDomainsResponse) - domains := response.Domains.PageData + addDebug(action, response, request) - for _, domain := range domains { - if strings.HasPrefix(domain.DomainName, "tf-testacc") { - allDomains = append(allDomains, domain) + resp, err := jsonpath.Get("$.Domains.PageData", response) + if err != nil { + return WrapErrorf(err, FailedGetAttributeMsg, action, "$.Domains.PageData", response) + } + result, _ := resp.([]interface{}) + for _, v := range result { + item := v.(map[string]interface{}) + if strings.HasPrefix(item["DomainName"].(string), "tf-testacc") { + allDomains = append(allDomains, item["DomainName"].(string)) } else { - log.Printf("Skip %#v", domain) + log.Printf("Skip %#v", item["DomainName"].(string)) } } - - if len(domains) < PageSizeLarge { + if len(result) < PageSizeLarge { break } - if page, err := getNextpageNumber(queryRequest.PageNumber); err != nil { - return WrapError(err) - } else { - queryRequest.PageNumber = page - } + request["PageNumber"] = request["PageNumber"].(int) + 1 } - removeRequest := dcdn.CreateDeleteDcdnDomainRequest() - removeRequest.DomainName = "" + + action = "DeleteDcdnDomain" for _, domain := range allDomains { - removeRequest.DomainName = domain.DomainName - raw, err := client.WithDcdnClient(func(dcdnClient *dcdn.Client) (interface{}, error) { - return dcdnClient.DeleteDcdnDomain(removeRequest) + query := make(map[string]interface{}) + request = make(map[string]interface{}) + query["DomainName"] = domain + + wait := incrementalWait(3*time.Second, 5*time.Second) + err = resource.Retry(1*time.Minute, func() *resource.RetryError { + response, err = client.RpcPost("dcdn", "2018-01-15", action, query, request, false) + if err != nil { + if NeedRetry(err) { + wait() + return resource.RetryableError(err) + } + return resource.NonRetryableError(err) + } + addDebug(action, response, request) + return nil }) if err != nil { - log.Printf("[ERROR] %s get an error %s", removeRequest.GetActionName(), err) + return WrapErrorf(err, DefaultErrorMsg, domain, action, AlibabaCloudSdkGoERROR) } - addDebug(removeRequest.GetActionName(), raw) } return nil diff --git a/alicloud/resource_alicloud_dcdn_er.go b/alicloud/resource_alicloud_dcdn_er.go index 9f6b56ff034c..e88139fe365a 100644 --- a/alicloud/resource_alicloud_dcdn_er.go +++ b/alicloud/resource_alicloud_dcdn_er.go @@ -5,7 +5,6 @@ import ( "fmt" "time" - util "github.com/alibabacloud-go/tea-utils/service" "github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" @@ -1017,10 +1016,7 @@ func resourceAliCloudDcdnErCreate(d *schema.ResourceData, meta interface{}) erro var response map[string]interface{} action := "CreateRoutine" request := make(map[string]interface{}) - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error request["Name"] = d.Get("er_name") @@ -1893,11 +1889,9 @@ func resourceAliCloudDcdnErCreate(d *schema.ResourceData, meta interface{}) erro request["EnvConf"] = envConfJson } - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutCreate)), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() @@ -2844,6 +2838,7 @@ func resourceAliCloudDcdnErRead(d *schema.ResourceData, meta interface{}) error func resourceAliCloudDcdnErUpdate(d *schema.ResourceData, meta interface{}) error { client := meta.(*connectivity.AliyunClient) var response map[string]interface{} + var err error update := false request := map[string]interface{}{ @@ -3727,16 +3722,9 @@ func resourceAliCloudDcdnErUpdate(d *schema.ResourceData, meta interface{}) erro if update { action := "EditRoutineConf" - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } - - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutUpdate)), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() @@ -3761,20 +3749,15 @@ func resourceAliCloudDcdnErDelete(d *schema.ResourceData, meta interface{}) erro action := "DeleteRoutine" var response map[string]interface{} - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error request := map[string]interface{}{ "Name": d.Id(), } - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutDelete)), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() diff --git a/alicloud/resource_alicloud_dcdn_ipa_domain.go b/alicloud/resource_alicloud_dcdn_ipa_domain.go index 03b6a432d6d8..b81505be0b10 100644 --- a/alicloud/resource_alicloud_dcdn_ipa_domain.go +++ b/alicloud/resource_alicloud_dcdn_ipa_domain.go @@ -5,7 +5,6 @@ import ( "log" "time" - util "github.com/alibabacloud-go/tea-utils/service" "github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" @@ -92,10 +91,7 @@ func resourceAlicloudDcdnIpaDomainCreate(d *schema.ResourceData, meta interface{ var response map[string]interface{} action := "AddDcdnIpaDomain" request := make(map[string]interface{}) - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error request["DomainName"] = d.Get("domain_name") if v, ok := d.GetOk("resource_group_id"); ok { request["ResourceGroupId"] = v @@ -110,7 +106,7 @@ func resourceAlicloudDcdnIpaDomainCreate(d *schema.ResourceData, meta interface{ request["Sources"] = sources wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() @@ -174,10 +170,7 @@ func resourceAlicloudDcdnIpaDomainRead(d *schema.ResourceData, meta interface{}) func resourceAlicloudDcdnIpaDomainUpdate(d *schema.ResourceData, meta interface{}) error { client := meta.(*connectivity.AliyunClient) dcdnService := DcdnService{client} - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error var response map[string]interface{} update := false request := map[string]interface{}{ @@ -202,7 +195,7 @@ func resourceAlicloudDcdnIpaDomainUpdate(d *schema.ResourceData, meta interface{ action := "UpdateDcdnIpaDomain" wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() @@ -238,7 +231,7 @@ func resourceAlicloudDcdnIpaDomainUpdate(d *schema.ResourceData, meta interface{ action := "StopDcdnIpaDomain" wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() @@ -264,7 +257,7 @@ func resourceAlicloudDcdnIpaDomainUpdate(d *schema.ResourceData, meta interface{ action := "StartDcdnIpaDomain" wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() @@ -294,17 +287,14 @@ func resourceAlicloudDcdnIpaDomainDelete(d *schema.ResourceData, meta interface{ dcdnService := DcdnService{client} action := "DeleteDcdnIpaDomain" var response map[string]interface{} - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error request := map[string]interface{}{ "DomainName": d.Id(), } wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutDelete), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) || IsExpectedErrors(err, []string{"ServiceBusy"}) { wait() diff --git a/alicloud/resource_alicloud_dcdn_ipa_domain_test.go b/alicloud/resource_alicloud_dcdn_ipa_domain_test.go index 2374b5d32cff..119bc9c98efa 100644 --- a/alicloud/resource_alicloud_dcdn_ipa_domain_test.go +++ b/alicloud/resource_alicloud_dcdn_ipa_domain_test.go @@ -42,7 +42,7 @@ func testSweepDcdnIpaDomain(region string) error { if err != nil { return fmt.Errorf("error getting Alicloud client: %s", err) } - aliyunClient := rawClient.(*connectivity.AliyunClient) + client := rawClient.(*connectivity.AliyunClient) prefixes := []string{ "tf-testAcc", "tf_testAcc", @@ -54,17 +54,10 @@ func testSweepDcdnIpaDomain(region string) error { request["PageNumber"] = 1 var response map[string]interface{} - conn, err := aliyunClient.NewDcdnClient() - if err != nil { - log.Printf("[ERROR] %s get an error: %#v", action, err) - return nil - } for { - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(1*time.Minute, func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -103,7 +96,7 @@ func testSweepDcdnIpaDomain(region string) error { request := map[string]interface{}{ "DomainName": item["DomainName"], } - _, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + _, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, true) if err != nil { log.Printf("[ERROR] Failed to delete Dcdn Ipa Domain (%s): %s", item["DomainName"].(string), err) } diff --git a/alicloud/resource_alicloud_dcdn_kv.go b/alicloud/resource_alicloud_dcdn_kv.go index b941cbd56824..efb8168869ef 100644 --- a/alicloud/resource_alicloud_dcdn_kv.go +++ b/alicloud/resource_alicloud_dcdn_kv.go @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/validation" - util "github.com/alibabacloud-go/tea-utils/service" "github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" @@ -50,10 +49,7 @@ func resourceAlicloudDcdnKv() *schema.Resource { func resourceAlicloudDcdnKvCreate(d *schema.ResourceData, meta interface{}) error { client := meta.(*connectivity.AliyunClient) request := make(map[string]interface{}) - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error if v, ok := d.GetOk("key"); ok { request["Key"] = v @@ -69,7 +65,7 @@ func resourceAlicloudDcdnKvCreate(d *schema.ResourceData, meta interface{}) erro action := "PutDcdnKv" wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutCreate)), func() *resource.RetryError { - resp, err := conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() @@ -77,7 +73,6 @@ func resourceAlicloudDcdnKvCreate(d *schema.ResourceData, meta interface{}) erro } return resource.NonRetryableError(err) } - response = resp addDebug(action, response, request) return nil }) @@ -118,10 +113,7 @@ func resourceAlicloudDcdnKvRead(d *schema.ResourceData, meta interface{}) error func resourceAlicloudDcdnKvUpdate(d *schema.ResourceData, meta interface{}) error { client := meta.(*connectivity.AliyunClient) - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error parts, err := ParseResourceId(d.Id(), 2) if err != nil { return WrapError(err) @@ -141,7 +133,7 @@ func resourceAlicloudDcdnKvUpdate(d *schema.ResourceData, meta interface{}) erro action := "PutDcdnKv" wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutUpdate)), func() *resource.RetryError { - resp, err := conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err := client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() @@ -149,7 +141,7 @@ func resourceAlicloudDcdnKvUpdate(d *schema.ResourceData, meta interface{}) erro } return resource.NonRetryableError(err) } - addDebug(action, resp, request) + addDebug(action, response, request) return nil }) if err != nil { @@ -162,10 +154,7 @@ func resourceAlicloudDcdnKvUpdate(d *schema.ResourceData, meta interface{}) erro func resourceAlicloudDcdnKvDelete(d *schema.ResourceData, meta interface{}) error { client := meta.(*connectivity.AliyunClient) - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error parts, err := ParseResourceId(d.Id(), 2) if err != nil { return WrapError(err) @@ -179,7 +168,7 @@ func resourceAlicloudDcdnKvDelete(d *schema.ResourceData, meta interface{}) erro action := "DeleteDcdnKv" wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutDelete)), func() *resource.RetryError { - resp, err := conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err := client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() @@ -187,7 +176,7 @@ func resourceAlicloudDcdnKvDelete(d *schema.ResourceData, meta interface{}) erro } return resource.NonRetryableError(err) } - addDebug(action, resp, request) + addDebug(action, response, request) return nil }) if err != nil { diff --git a/alicloud/resource_alicloud_dcdn_kv_namespace.go b/alicloud/resource_alicloud_dcdn_kv_namespace.go index 755268c5d3d3..3389681538a9 100644 --- a/alicloud/resource_alicloud_dcdn_kv_namespace.go +++ b/alicloud/resource_alicloud_dcdn_kv_namespace.go @@ -9,7 +9,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/PaesslerAG/jsonpath" - util "github.com/alibabacloud-go/tea-utils/service" "github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" @@ -50,10 +49,7 @@ func resourceAlicloudDcdnKvNamespace() *schema.Resource { func resourceAlicloudDcdnKvNamespaceCreate(d *schema.ResourceData, meta interface{}) error { client := meta.(*connectivity.AliyunClient) request := make(map[string]interface{}) - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error if v, ok := d.GetOk("description"); ok { request["Description"] = v @@ -66,7 +62,7 @@ func resourceAlicloudDcdnKvNamespaceCreate(d *schema.ResourceData, meta interfac action := "PutDcdnKvNamespace" wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutCreate)), func() *resource.RetryError { - resp, err := conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() @@ -74,7 +70,6 @@ func resourceAlicloudDcdnKvNamespaceCreate(d *schema.ResourceData, meta interfac } return resource.NonRetryableError(err) } - response = resp addDebug(action, response, request) return nil }) @@ -113,10 +108,7 @@ func resourceAlicloudDcdnKvNamespaceRead(d *schema.ResourceData, meta interface{ func resourceAlicloudDcdnKvNamespaceDelete(d *schema.ResourceData, meta interface{}) error { client := meta.(*connectivity.AliyunClient) - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error dcdnService := DcdnService{client} request := map[string]interface{}{ @@ -126,7 +118,7 @@ func resourceAlicloudDcdnKvNamespaceDelete(d *schema.ResourceData, meta interfac action := "DeleteDcdnKvNamespace" wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutDelete)), func() *resource.RetryError { - resp, err := conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err := client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() @@ -134,7 +126,7 @@ func resourceAlicloudDcdnKvNamespaceDelete(d *schema.ResourceData, meta interfac } return resource.NonRetryableError(err) } - addDebug(action, resp, request) + addDebug(action, response, request) return nil }) if err != nil { diff --git a/alicloud/resource_alicloud_dcdn_waf_domain.go b/alicloud/resource_alicloud_dcdn_waf_domain.go index 1441021178e3..c012e28ceec5 100644 --- a/alicloud/resource_alicloud_dcdn_waf_domain.go +++ b/alicloud/resource_alicloud_dcdn_waf_domain.go @@ -5,7 +5,6 @@ import ( "log" "time" - util "github.com/alibabacloud-go/tea-utils/service" "github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" @@ -44,10 +43,7 @@ func resourceAlicloudDcdnWafDomainCreate(d *schema.ResourceData, meta interface{ var response map[string]interface{} action := "BatchSetDcdnWafDomainConfigs" request := make(map[string]interface{}) - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error if v, ok := d.GetOk("client_ip_tag"); ok { request["ClientIpTag"] = v } @@ -55,7 +51,7 @@ func resourceAlicloudDcdnWafDomainCreate(d *schema.ResourceData, meta interface{ request["DomainNames"] = d.Get("domain_name") wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutCreate)), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() @@ -94,10 +90,7 @@ func resourceAlicloudDcdnWafDomainRead(d *schema.ResourceData, meta interface{}) func resourceAlicloudDcdnWafDomainUpdate(d *schema.ResourceData, meta interface{}) error { client := meta.(*connectivity.AliyunClient) var response map[string]interface{} - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error if d.HasChange("client_ip_tag") { action := "BatchSetDcdnWafDomainConfigs" @@ -110,7 +103,7 @@ func resourceAlicloudDcdnWafDomainUpdate(d *schema.ResourceData, meta interface{ } wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutUpdate)), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() @@ -132,17 +125,14 @@ func resourceAlicloudDcdnWafDomainDelete(d *schema.ResourceData, meta interface{ client := meta.(*connectivity.AliyunClient) action := "BatchSetDcdnWafDomainConfigs" var response map[string]interface{} - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error request := map[string]interface{}{ "DomainNames": d.Id(), } request["DefenseStatus"] = "off" wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutDelete)), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() diff --git a/alicloud/resource_alicloud_dcdn_waf_policy.go b/alicloud/resource_alicloud_dcdn_waf_policy.go index 867bd348819f..a8bba2a3aa08 100644 --- a/alicloud/resource_alicloud_dcdn_waf_policy.go +++ b/alicloud/resource_alicloud_dcdn_waf_policy.go @@ -8,7 +8,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/validation" - util "github.com/alibabacloud-go/tea-utils/service" "github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" @@ -60,17 +59,14 @@ func resourceAlicloudDcdnWafPolicyCreate(d *schema.ResourceData, meta interface{ var response map[string]interface{} action := "CreateDcdnWafPolicy" request := make(map[string]interface{}) - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error request["DefenseScene"] = d.Get("defense_scene") request["PolicyName"] = d.Get("policy_name") request["PolicyType"] = d.Get("policy_type") request["PolicyStatus"] = d.Get("status") wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutCreate)), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() @@ -109,10 +105,7 @@ func resourceAlicloudDcdnWafPolicyRead(d *schema.ResourceData, meta interface{}) } func resourceAlicloudDcdnWafPolicyUpdate(d *schema.ResourceData, meta interface{}) error { client := meta.(*connectivity.AliyunClient) - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error var response map[string]interface{} update := false request := map[string]interface{}{ @@ -130,7 +123,7 @@ func resourceAlicloudDcdnWafPolicyUpdate(d *schema.ResourceData, meta interface{ action := "ModifyDcdnWafPolicy" wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutUpdate)), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() @@ -151,17 +144,14 @@ func resourceAlicloudDcdnWafPolicyDelete(d *schema.ResourceData, meta interface{ client := meta.(*connectivity.AliyunClient) action := "DeleteDcdnWafPolicy" var response map[string]interface{} - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error request := map[string]interface{}{ "PolicyId": d.Id(), } wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutDelete)), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() diff --git a/alicloud/resource_alicloud_dcdn_waf_policy_domain_attachment.go b/alicloud/resource_alicloud_dcdn_waf_policy_domain_attachment.go index e7479d234900..744811afd5a9 100644 --- a/alicloud/resource_alicloud_dcdn_waf_policy_domain_attachment.go +++ b/alicloud/resource_alicloud_dcdn_waf_policy_domain_attachment.go @@ -5,7 +5,6 @@ import ( "log" "time" - util "github.com/alibabacloud-go/tea-utils/service" "github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" @@ -43,15 +42,12 @@ func resourceAlicloudDcdnWafPolicyDomainAttachmentCreate(d *schema.ResourceData, var response map[string]interface{} action := "ModifyDcdnWafPolicyDomains" request := make(map[string]interface{}) - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error request["BindDomains"] = d.Get("domain_name") request["PolicyId"] = d.Get("policy_id") wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() @@ -99,17 +95,13 @@ func resourceAlicloudDcdnWafPolicyDomainAttachmentDelete(d *schema.ResourceData, return WrapError(err) } var response map[string]interface{} - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } request := map[string]interface{}{ "PolicyId": parts[0], "UnbindDomains": parts[1], } wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutDelete), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() diff --git a/alicloud/resource_alicloud_dcdn_waf_policy_test.go b/alicloud/resource_alicloud_dcdn_waf_policy_test.go index 9bc85ffe939e..99601df5845b 100644 --- a/alicloud/resource_alicloud_dcdn_waf_policy_test.go +++ b/alicloud/resource_alicloud_dcdn_waf_policy_test.go @@ -41,30 +41,25 @@ func testSweepDcdnWafPolicy(region string) error { if err != nil { return fmt.Errorf("error getting Alicloud client: %s", err) } - aliyunClient := rawClient.(*connectivity.AliyunClient) + client := rawClient.(*connectivity.AliyunClient) prefixes := []string{ "tf-testAcc", "tf_testAcc", } action := "DescribeDcdnWafPolicies" request := map[string]interface{}{} - request["RegionId"] = aliyunClient.RegionId + request["RegionId"] = client.RegionId request["PageSize"] = PageSizeLarge request["PageNumber"] = 1 var response map[string]interface{} - conn, err := aliyunClient.NewDcdnClient() - if err != nil { - log.Printf("[ERROR] %s get an error: %#v", action, err) - return nil - } for { runtime := util.RuntimeOptions{} runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(1*time.Minute, func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() @@ -103,7 +98,7 @@ func testSweepDcdnWafPolicy(region string) error { request := map[string]interface{}{ "PolicyId": item["PolicyId"], } - _, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + _, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, true) if err != nil { log.Printf("[ERROR] Failed to delete Dcdn Waf Policy (%s): %s", item["PolicyName"].(string), err) } diff --git a/alicloud/resource_alicloud_dcdn_waf_rule.go b/alicloud/resource_alicloud_dcdn_waf_rule.go index 5bb274aa311d..e0aa5861db8e 100644 --- a/alicloud/resource_alicloud_dcdn_waf_rule.go +++ b/alicloud/resource_alicloud_dcdn_waf_rule.go @@ -8,7 +8,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/PaesslerAG/jsonpath" - util "github.com/alibabacloud-go/tea-utils/service" "github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" @@ -195,10 +194,7 @@ func resourceAlicloudDcdnWafRule() *schema.Resource { func resourceAlicloudDcdnWafRuleCreate(d *schema.ResourceData, meta interface{}) error { client := meta.(*connectivity.AliyunClient) request := make(map[string]interface{}) - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error ruleConfigMap := make(map[string]interface{}, 0) if v, ok := d.GetOk("cc_status"); ok { ruleConfigMap["ccStatus"] = v @@ -285,7 +281,7 @@ func resourceAlicloudDcdnWafRuleCreate(d *schema.ResourceData, meta interface{}) action := "BatchCreateDcdnWafRules" wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutCreate)), func() *resource.RetryError { - resp, err := conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err = client.RpcPost("dcdn", "2018-01-15", action, request, nil, false) if err != nil { if NeedRetry(err) || IsExpectedErrors(err, []string{"InternalError"}) { wait() @@ -293,7 +289,6 @@ func resourceAlicloudDcdnWafRuleCreate(d *schema.ResourceData, meta interface{}) } return resource.NonRetryableError(err) } - response = resp addDebug(action, response, request) return nil }) @@ -389,10 +384,7 @@ func resourceAlicloudDcdnWafRuleRead(d *schema.ResourceData, meta interface{}) e func resourceAlicloudDcdnWafRuleUpdate(d *schema.ResourceData, meta interface{}) error { client := meta.(*connectivity.AliyunClient) - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error update := false request := map[string]interface{}{ "RuleId": d.Id(), @@ -524,7 +516,7 @@ func resourceAlicloudDcdnWafRuleUpdate(d *schema.ResourceData, meta interface{}) action := "ModifyDcdnWafRule" wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutUpdate)), func() *resource.RetryError { - resp, err := conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err := client.RpcPost("dcdn", "2018-01-15", action, request, nil, false) if err != nil { if NeedRetry(err) || IsExpectedErrors(err, []string{"InternalError"}) { wait() @@ -532,7 +524,7 @@ func resourceAlicloudDcdnWafRuleUpdate(d *schema.ResourceData, meta interface{}) } return resource.NonRetryableError(err) } - addDebug(action, resp, request) + addDebug(action, response, request) return nil }) if err != nil { @@ -545,10 +537,7 @@ func resourceAlicloudDcdnWafRuleUpdate(d *schema.ResourceData, meta interface{}) func resourceAlicloudDcdnWafRuleDelete(d *schema.ResourceData, meta interface{}) error { client := meta.(*connectivity.AliyunClient) - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error request := map[string]interface{}{ "RuleIds": d.Id(), @@ -557,7 +546,7 @@ func resourceAlicloudDcdnWafRuleDelete(d *schema.ResourceData, meta interface{}) action := "BatchDeleteDcdnWafRules" wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutDelete)), func() *resource.RetryError { - resp, err := conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err := client.RpcPost("dcdn", "2018-01-15", action, request, nil, false) if err != nil { if NeedRetry(err) { wait() @@ -565,7 +554,7 @@ func resourceAlicloudDcdnWafRuleDelete(d *schema.ResourceData, meta interface{}) } return resource.NonRetryableError(err) } - addDebug(action, resp, request) + addDebug(action, response, request) return nil }) if err != nil { diff --git a/alicloud/service_alicloud_dcdn.go b/alicloud/service_alicloud_dcdn.go index 5facd84b5546..6d55217f1c02 100644 --- a/alicloud/service_alicloud_dcdn.go +++ b/alicloud/service_alicloud_dcdn.go @@ -9,7 +9,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/PaesslerAG/jsonpath" - util "github.com/alibabacloud-go/tea-utils/service" "github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) @@ -39,18 +38,13 @@ func (s *DcdnService) convertSourcesToString(v []interface{}) (string, error) { func (s *DcdnService) DescribeDcdnDomainCertificateInfo(id string) (object map[string]interface{}, err error) { var response map[string]interface{} - conn, err := s.client.NewDcdnClient() - if err != nil { - return nil, WrapError(err) - } + client := s.client action := "DescribeDcdnDomainCertificateInfo" request := map[string]interface{}{ "RegionId": s.client.RegionId, "DomainName": id, } - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, true) if err != nil { err = WrapErrorf(err, DefaultErrorMsg, id, action, AlibabaCloudSdkGoERROR) return @@ -73,18 +67,13 @@ func (s *DcdnService) DescribeDcdnDomainCertificateInfo(id string) (object map[s func (s *DcdnService) DescribeDcdnDomain(id string) (object map[string]interface{}, err error) { var response map[string]interface{} - conn, err := s.client.NewDcdnClient() - if err != nil { - return nil, WrapError(err) - } + client := s.client action := "DescribeDcdnDomainDetail" request := map[string]interface{}{ "RegionId": s.client.RegionId, "DomainName": id, } - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, true) if err != nil { if IsExpectedErrors(err, []string{"InvalidDomain.NotFound"}) { err = WrapErrorf(Error(GetNotFoundMessage("DcdnDomain", id)), NotFoundMsg, ProviderERROR) @@ -125,12 +114,7 @@ func (s *DcdnService) DcdnDomainStateRefreshFunc(id string, failStates []string) func (s *DcdnService) DescribeDcdnDomainConfig(id string) (object map[string]interface{}, err error) { var response map[string]interface{} action := "DescribeDcdnDomainConfigs" - - conn, err := s.client.NewDcdnClient() - if err != nil { - return nil, WrapError(err) - } - + client := s.client parts, err := ParseResourceId(id, 3) if err != nil { return nil, WrapError(err) @@ -143,11 +127,9 @@ func (s *DcdnService) DescribeDcdnDomainConfig(id string) (object map[string]int } idExist := false - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(5*time.Minute, func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -158,7 +140,6 @@ func (s *DcdnService) DescribeDcdnDomainConfig(id string) (object map[string]int return nil }) addDebug(action, response, request) - if err != nil { if IsExpectedErrors(err, []string{"InvalidDomain.NotFound"}) { return object, WrapErrorf(Error(GetNotFoundMessage("Dcdn:DomainConfig", id)), NotFoundMsg, ProviderERROR, fmt.Sprint(response["RequestId"])) @@ -211,19 +192,14 @@ func (s *DcdnService) DcdnDomainConfigStateRefreshFunc(id string, failStates []s func (s *DcdnService) DescribeDcdnIpaDomain(id string) (object map[string]interface{}, err error) { var response map[string]interface{} - conn, err := s.client.NewDcdnClient() - if err != nil { - return nil, WrapError(err) - } + client := s.client action := "DescribeDcdnIpaDomainDetail" request := map[string]interface{}{ "DomainName": 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("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -271,21 +247,16 @@ func (s *DcdnService) DcdnIpaDomainStateRefreshFunc(id string, failStates []stri func (s *DcdnService) DescribeDcdnWafPolicy(id string) (object map[string]interface{}, err error) { var response map[string]interface{} - conn, err := s.client.NewDcdnClient() - if err != nil { - return nil, WrapError(err) - } + client := s.client action := "DescribeDcdnWafPolicies" request := map[string]interface{}{ "QueryArgs": fmt.Sprintf("{\"PolicyIds\":\"%s\"}", id), "PageNumber": 1, "PageSize": PageSizeLarge, } - 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("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -313,10 +284,7 @@ func (s *DcdnService) DescribeDcdnWafPolicy(id string) (object map[string]interf func (s *DcdnService) DescribeDcdnWafDomain(id string) (object map[string]interface{}, err error) { var response map[string]interface{} - conn, err := s.client.NewDcdnClient() - if err != nil { - return nil, WrapError(err) - } + client := s.client action := "DescribeDcdnWafDomains" request := map[string]interface{}{ "PageNumber": 1, @@ -324,11 +292,9 @@ func (s *DcdnService) DescribeDcdnWafDomain(id string) (object map[string]interf } for { - 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("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -364,19 +330,14 @@ func (s *DcdnService) DescribeDcdnWafDomain(id string) (object map[string]interf func (s *DcdnService) DescribeDcdnWafDomainDefenseScenes(id string) (object map[string]interface{}, err error) { var response map[string]interface{} - conn, err := s.client.NewDcdnClient() - if err != nil { - return nil, WrapError(err) - } + client := s.client action := "DescribeDcdnWafDomainDetail" request := map[string]interface{}{ "DomainName": 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("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -400,10 +361,7 @@ func (s *DcdnService) DescribeDcdnWafDomainDefenseScenes(id string) (object map[ func (s *DcdnService) DescribeDcdnWafPolicyDomainAttachment(id string) (object map[string]interface{}, err error) { var response map[string]interface{} - conn, err := s.client.NewDcdnClient() - if err != nil { - return nil, WrapError(err) - } + client := s.client parts, err := ParseResourceId(id, 2) if err != nil { return object, WrapError(err) @@ -413,11 +371,9 @@ func (s *DcdnService) DescribeDcdnWafPolicyDomainAttachment(id string) (object m "PolicyId": parts[0], } for { - 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("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -452,10 +408,7 @@ func (s *DcdnService) DescribeDcdnWafPolicyDomainAttachment(id string) (object m } func (s *DcdnService) DescribeDcdnKv(id string) (object map[string]interface{}, err error) { - conn, err := s.client.NewDcdnClient() - if err != nil { - return object, WrapError(err) - } + client := s.client parts, err := ParseResourceId(id, 2) if err != nil { return object, WrapError(err) @@ -468,11 +421,9 @@ func (s *DcdnService) DescribeDcdnKv(id string) (object map[string]interface{}, var response map[string]interface{} action := "GetDcdnKv" - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(5*time.Minute, func() *resource.RetryError { - resp, err := conn.DoRequest(StringPointer(action), nil, StringPointer("GET"), StringPointer("2018-01-15"), StringPointer("AK"), request, nil, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, request, nil, true) if err != nil { if NeedRetry(err) { wait() @@ -480,7 +431,6 @@ func (s *DcdnService) DescribeDcdnKv(id string) (object map[string]interface{}, } return resource.NonRetryableError(err) } - response = resp addDebug(action, response, request) return nil }) @@ -498,10 +448,7 @@ func (s *DcdnService) DescribeDcdnKv(id string) (object map[string]interface{}, } func (s *DcdnService) DescribeDcdnKvNamespace(id string) (object map[string]interface{}, err error) { - conn, err := s.client.NewDcdnClient() - if err != nil { - return object, WrapError(err) - } + client := s.client request := map[string]interface{}{ "Namespace": id, @@ -509,11 +456,9 @@ func (s *DcdnService) DescribeDcdnKvNamespace(id string) (object map[string]inte var response map[string]interface{} action := "DescribeDcdnKvNamespace" - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(5*time.Minute, func() *resource.RetryError { - resp, err := conn.DoRequest(StringPointer(action), nil, StringPointer("GET"), StringPointer("2018-01-15"), StringPointer("AK"), request, nil, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, request, nil, true) if err != nil { if NeedRetry(err) { wait() @@ -521,7 +466,6 @@ func (s *DcdnService) DescribeDcdnKvNamespace(id string) (object map[string]inte } return resource.NonRetryableError(err) } - response = resp addDebug(action, response, request) return nil }) @@ -558,18 +502,13 @@ func (s *DcdnService) DcdnKvNamespaceStateRefreshFunc(id string, failStates []st func (s *DcdnService) DescribeDcdnKvAccountStatus() (object map[string]interface{}, err error) { var response map[string]interface{} - conn, err := s.client.NewDcdnClient() - if err != nil { - return nil, WrapError(err) - } + client := s.client action := "DescribeDcdnKvAccountStatus" request := map[string]interface{}{} - 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("GET"), StringPointer("2018-01-15"), StringPointer("AK"), request, nil, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, request, nil, true) if err != nil { if NeedRetry(err) { wait() @@ -593,22 +532,16 @@ func (s *DcdnService) DescribeDcdnKvAccountStatus() (object map[string]interface } func (s *DcdnService) DescribeDcdnWafRule(id string) (object map[string]interface{}, err error) { - conn, err := s.client.NewDcdnClient() - if err != nil { - return object, WrapError(err) - } - + client := s.client request := map[string]interface{}{ "RuleId": id, } var response map[string]interface{} action := "DescribeDcdnWafRule" - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(5*time.Minute, func() *resource.RetryError { - resp, err := conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, true) if err != nil { if NeedRetry(err) || IsExpectedErrors(err, []string{"InternalError"}) { wait() @@ -616,7 +549,6 @@ func (s *DcdnService) DescribeDcdnWafRule(id string) (object map[string]interfac } return resource.NonRetryableError(err) } - response = resp addDebug(action, response, request) return nil }) @@ -639,20 +571,15 @@ func (s *DcdnService) DescribeDcdnEr(id string) (object map[string]interface{}, var response map[string]interface{} action := "DescribeRoutine" - conn, err := s.client.NewDcdnClient() - if err != nil { - return object, WrapError(err) - } + client := s.client request := map[string]interface{}{ "Name": 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("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -682,12 +609,8 @@ func (s *DcdnService) DescribeDcdnEr(id string) (object map[string]interface{}, } func (s *DcdnService) ListTagResources(id string, resourceType string) (object interface{}, err error) { - conn, err := s.client.NewDcdnClient() - if err != nil { - return nil, WrapError(err) - } + client := s.client action := "DescribeDcdnTagResources" - request := map[string]interface{}{ "ResourceType": resourceType, } @@ -707,12 +630,9 @@ func (s *DcdnService) ListTagResources(id string, resourceType string) (object i tags := make([]interface{}, 0) var response map[string]interface{} - - 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("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -721,7 +641,6 @@ func (s *DcdnService) ListTagResources(id string, resourceType string) (object i return resource.NonRetryableError(err) } addDebug(action, response, request) - resp, err := jsonpath.Get("$.TagResources", response) if err != nil { return resource.NonRetryableError(WrapErrorf(err, FailedGetAttributeMsg, id, "$.TagResources", response)) @@ -743,16 +662,12 @@ func (s *DcdnService) ListTagResources(id string, resourceType string) (object i } func (s *DcdnService) SetResourceTags(d *schema.ResourceData, resourceType string) error { - + client := s.client resourceIdNum := strings.Count(d.Id(), ":") - + var response map[string]interface{} + var err error if d.HasChange("tags") { added, removed := parsingTags(d) - conn, err := s.client.NewDcdnClient() - if err != nil { - return WrapError(err) - } - removedTagKeys := make([]string, 0) for _, v := range removed { if !ignoredTags(v, "") { @@ -781,11 +696,9 @@ func (s *DcdnService) SetResourceTags(d *schema.ResourceData, resourceType strin request[fmt.Sprintf("TagKey.%d", i+1)] = key } - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(2*time.Second, 1*time.Second) err := resource.Retry(10*time.Minute, func() *resource.RetryError { - response, err := conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() @@ -825,11 +738,9 @@ func (s *DcdnService) SetResourceTags(d *schema.ResourceData, resourceType strin count++ } - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(2*time.Second, 1*time.Second) err := resource.Retry(10*time.Minute, func() *resource.RetryError { - response, err := conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() diff --git a/alicloud/service_alicloud_dcdn_v2.go b/alicloud/service_alicloud_dcdn_v2.go index 9abeb6c01ead..526795032568 100644 --- a/alicloud/service_alicloud_dcdn_v2.go +++ b/alicloud/service_alicloud_dcdn_v2.go @@ -5,7 +5,6 @@ import ( "time" "github.com/PaesslerAG/jsonpath" - util "github.com/alibabacloud-go/tea-utils/service" "github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) @@ -22,19 +21,13 @@ func (s *DcdnServiceV2) DescribeDcdnDomain(id string) (object map[string]interfa var response map[string]interface{} var query map[string]interface{} action := "DescribeDcdnDomainDetail" - conn, err := client.NewDcdnClient() - if err != nil { - return object, WrapError(err) - } request = make(map[string]interface{}) query = make(map[string]interface{}) query["DomainName"] = id - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(1*time.Minute, func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, query, request, true) if err != nil { if NeedRetry(err) { @@ -67,19 +60,13 @@ func (s *DcdnServiceV2) DescribeDescribeDcdnDomainCertificateInfo(id string) (ob var response map[string]interface{} var query map[string]interface{} action := "DescribeDcdnDomainCertificateInfo" - conn, err := client.NewDcdnClient() - if err != nil { - return object, WrapError(err) - } request = make(map[string]interface{}) query = make(map[string]interface{}) query["DomainName"] = id - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(1*time.Minute, func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, query, request, true) if err != nil { if NeedRetry(err) { @@ -116,20 +103,14 @@ func (s *DcdnServiceV2) DescribeDescribeDcdnTagResources(id string) (object map[ var response map[string]interface{} var query map[string]interface{} action := "DescribeDcdnTagResources" - conn, err := client.NewDcdnClient() - if err != nil { - return object, WrapError(err) - } request = make(map[string]interface{}) query = make(map[string]interface{}) request["ResourceId.1"] = id request["ResourceType"] = "DOMAIN" - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(1*time.Minute, func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, query, request, true) if err != nil { if NeedRetry(err) { diff --git a/website/docs/d/dcdn_domains.html.markdown b/website/docs/d/dcdn_domains.html.markdown index 4559f591b527..a55bd4f46d31 100644 --- a/website/docs/d/dcdn_domains.html.markdown +++ b/website/docs/d/dcdn_domains.html.markdown @@ -11,11 +11,11 @@ description: |- Provides a collection of DCDN Domains to the specified filters. -~> **NOTE:** Available in 1.94.0+. +-> **NOTE:** Available since 1.94.0. ## Example Usage - ``` +```terraform data "alicloud_dcdn_domains" "example" { ids = ["example.com"] } @@ -44,24 +44,24 @@ The following arguments are supported: The following attributes are exported in addition to the arguments listed above: - * `ids` - A list ids of DCDN Domain. - * `names` - A list of DCDN Domain names. - * `domains` - A list of domains. Each element contains the following attributes: - * `id` - The ID of the DCDN Domain. - * `cert_name` - Indicates the name of the certificate. - * `resource_group_id` - The ID of the resource group. - * `domain_name` - The name of the DCDN Domain. - * `ssl_protocol` - Indicates whether the SSL certificate is enabled. - * `ssl_pub` - Indicates the public key of the certificate. - * `scope` - The acceleration region. - * `status` - The status of DCDN Domain. Valid values: `online`, `offline`, `check_failed`, `checking`, `configure_failed`, `configuring`. - * `cname` - The canonical name (CNAME) of the accelerated domain. - * `description` - The reason that causes the review failure. - * `gmt_modified` - The time when the accelerated domain was last modified. - * `sources` - The origin information. - * `content` - The origin address. - * `type` - The type of the origin. Valid values: - * `port` - The port number. - * `priority` - The priority of the origin if multiple origins are specified. - * `weight` - The weight of the origin if multiple origins are specified. - * `enabled` - The status of the origin. +* `ids` - A list ids of DCDN Domain. +* `names` - A list of DCDN Domain names. +* `domains` - A list of domains. Each element contains the following attributes: + * `id` - The ID of the DCDN Domain. + * `cert_name` - Indicates the name of the certificate. + * `resource_group_id` - The ID of the resource group. + * `domain_name` - The name of the DCDN Domain. + * `ssl_protocol` - Indicates whether the SSL certificate is enabled. + * `ssl_pub` - Indicates the public key of the certificate. + * `scope` - The acceleration region. + * `status` - The status of DCDN Domain. Valid values: `online`, `offline`, `check_failed`, `checking`, `configure_failed`, `configuring`. + * `cname` - The canonical name (CNAME) of the accelerated domain. + * `description` - The reason that causes the review failure. + * `gmt_modified` - The time when the accelerated domain was last modified. + * `sources` - The origin information. + * `content` - The origin address. + * `type` - The type of the origin. Valid values: + * `port` - The port number. + * `priority` - The priority of the origin if multiple origins are specified. + * `weight` - The weight of the origin if multiple origins are specified. + * `enabled` - The status of the origin. diff --git a/website/docs/d/dcdn_ipa_domains.html.markdown b/website/docs/d/dcdn_ipa_domains.html.markdown index 02d54fa89598..6c3a9a31667e 100644 --- a/website/docs/d/dcdn_ipa_domains.html.markdown +++ b/website/docs/d/dcdn_ipa_domains.html.markdown @@ -7,11 +7,11 @@ description: |- Provides a list of Dcdn Ipa Domains to the user. --- -# alicloud\_dcdn\_ipa\_domains +# alicloud_dcdn_ipa_domains This data source provides the Dcdn Ipa Domains of the current Alibaba Cloud user. --> **NOTE:** Available in v1.158.0+. +-> **NOTE:** Available since v1.158.0. ## Example Usage @@ -44,26 +44,26 @@ The following arguments are supported: * `output_file` - (Optional) File name where to save data source results (after running `terraform plan`). * `status` - (Optional, ForceNew) The status of the accelerated domain name. Valid values: `check_failed`, `checking`, `configure_failed`, `configuring`, `offline`, `online`. -## Argument Reference +## Attributes Reference The following attributes are exported in addition to the arguments listed above: * `names` - A list of Dcdn Ipa Domain names. * `domains` - A list of Dcdn Ipa Domains. Each element contains the following attributes: - * `cert_name` - CertName. - * `cname` - The CNAME assigned to the domain name. - * `create_time` - The time when the accelerated domain name was created. - * `description` - The description. - * `domain_name` - The accelerated domain names. - * `id` - The ID of the Ipa Domain. - * `resource_group_id` - The ID of the resource group. - * `scope` - The accelerated region. - * `sources` - The information about the origin server. - * `priority` - The priority of the origin server if multiple origin servers are specified. - * `type` - The type of the origin server. - * `weight` - The weight of the origin server if multiple origin servers are specified. - * `content` - The address of the origin server. - * `port` - The custom port. - * `ssl_protocol` - Indicates whether the Security Socket Layer (SSL) certificate is enabled. - * `ssl_pub` - Indicates the public key of the certificate if the HTTPS protocol is enabled. - * `status` - The status of the accelerated domain name. \ No newline at end of file + * `cert_name` - CertName. + * `cname` - The CNAME assigned to the domain name. + * `create_time` - The time when the accelerated domain name was created. + * `description` - The description. + * `domain_name` - The accelerated domain names. + * `id` - The ID of the Ipa Domain. + * `resource_group_id` - The ID of the resource group. + * `scope` - The accelerated region. + * `sources` - The information about the origin server. + * `priority` - The priority of the origin server if multiple origin servers are specified. + * `type` - The type of the origin server. + * `weight` - The weight of the origin server if multiple origin servers are specified. + * `content` - The address of the origin server. + * `port` - The custom port. + * `ssl_protocol` - Indicates whether the Security Socket Layer (SSL) certificate is enabled. + * `ssl_pub` - Indicates the public key of the certificate if the HTTPS protocol is enabled. + * `status` - The status of the accelerated domain name. \ No newline at end of file diff --git a/website/docs/d/dcdn_kv_account.html.markdown b/website/docs/d/dcdn_kv_account.html.markdown index d604762d120b..fda67027a9a1 100644 --- a/website/docs/d/dcdn_kv_account.html.markdown +++ b/website/docs/d/dcdn_kv_account.html.markdown @@ -4,7 +4,7 @@ layout: "alicloud" page_title: "Alicloud: alicloud_dcdn_kv_account" sidebar_current: "docs-alicloud-datasource-dcdn-kv-account" description: |- - Provides a datasource to open the DCDN kv account automatically. + Provides a datasource to open the DCDN kv account automatically. --- # alicloud_dcdn_kv_account diff --git a/website/docs/d/dcdn_waf_domains.html.markdown b/website/docs/d/dcdn_waf_domains.html.markdown index bd6a7a80b8e6..4fd36695e534 100644 --- a/website/docs/d/dcdn_waf_domains.html.markdown +++ b/website/docs/d/dcdn_waf_domains.html.markdown @@ -7,11 +7,11 @@ description: |- Provides a list of Dcdn Waf Domains to the user. --- -# alicloud\_dcdn\_waf\_domains +# alicloud_dcdn_waf_domains This data source provides the Dcdn Waf Domains of the current Alibaba Cloud user. --> **NOTE:** Available in v1.185.0+. +-> **NOTE:** Available since v1.185.0. ## Example Usage @@ -33,7 +33,7 @@ The following arguments are supported: * `output_file` - (Optional) File name where to save data source results (after running `terraform plan`). * `query_args` - (Optional, ForceNew) The query conditions. You can filter domain names by name. Fuzzy match is supported `QueryArgs={"DomainName":"Accelerated domain name"}`. -## Argument Reference +## Attributes Reference The following attributes are exported in addition to the arguments listed above: diff --git a/website/docs/d/dcdn_waf_policies.html.markdown b/website/docs/d/dcdn_waf_policies.html.markdown index 2589b258239b..4110c3f44b48 100644 --- a/website/docs/d/dcdn_waf_policies.html.markdown +++ b/website/docs/d/dcdn_waf_policies.html.markdown @@ -7,11 +7,11 @@ description: |- Provides a list of Dcdn Waf Policies to the user. --- -# alicloud\_dcdn\_waf\_policies +# alicloud_dcdn_waf_policies This data source provides the Dcdn Waf Policies of the current Alibaba Cloud user. --> **NOTE:** Available in v1.184.0+. +-> **NOTE:** Available since v1.184.0. ## Example Usage @@ -33,7 +33,7 @@ The following arguments are supported: * `query_args` - (Optional, ForceNew) The query conditions. The value is a string in the JSON format. Format: `{"PolicyIds":"The ID of the proteuleIds":"Thection policy","R range of protection rule IDs","PolicyNameLike":"The name of the protection policy","DomainNames":"The protected domain names","PolicyType":"default","DefenseScenes":"waf_group","PolicyStatus":"on","OrderBy":"GmtModified","Desc":"false"}`. * `status` - (Optional, ForceNew) The status of the resource. Valid values: `on`, `off`. -## Argument Reference +## Attributes Reference The following attributes are exported in addition to the arguments listed above: