From c8a98a468cffaead309df1912a4eb2ab64acc9ea Mon Sep 17 00:00:00 2001 From: "guimin.hgm" Date: Thu, 23 Jan 2025 23:54:53 +0800 Subject: [PATCH] resource/alicloud_kms_instance: Improves the invoking api method and supports refreshing credential automatically; data-source/alicloud_kms_instances: improves the invoking api method --- .../data_source_alicloud_kms_instances.go | 10 +- alicloud/resource_alicloud_kms_instance.go | 122 +++++++----------- .../resource_alicloud_kms_instance_test.go | 117 ++++++----------- alicloud/service_alicloud_kms_v2.go | 8 +- .../docs/d/event_bridge_service.html.markdown | 2 +- 5 files changed, 86 insertions(+), 173 deletions(-) diff --git a/alicloud/data_source_alicloud_kms_instances.go b/alicloud/data_source_alicloud_kms_instances.go index 14639411e39f..43d9eb9bf2be 100644 --- a/alicloud/data_source_alicloud_kms_instances.go +++ b/alicloud/data_source_alicloud_kms_instances.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" @@ -71,22 +70,17 @@ func dataSourceAliCloudKmsInstanceRead(d *schema.ResourceData, meta interface{}) var request map[string]interface{} var response map[string]interface{} + var err error var query map[string]interface{} action := "ListKmsInstances" - conn, err := client.NewKmsClient() - if err != nil { - return WrapError(err) - } request = make(map[string]interface{}) query = make(map[string]interface{}) - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) request["PageSize"] = 5 request["PageNumber"] = 1 for { 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("2016-01-20"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("Kms", "2016-01-20", action, query, request, true) if err != nil { if NeedRetry(err) { diff --git a/alicloud/resource_alicloud_kms_instance.go b/alicloud/resource_alicloud_kms_instance.go index 86401f8cfb30..d0020b3e3102 100644 --- a/alicloud/resource_alicloud_kms_instance.go +++ b/alicloud/resource_alicloud_kms_instance.go @@ -8,7 +8,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" @@ -219,11 +218,9 @@ func resourceAliCloudKmsInstanceCreate(d *schema.ResourceData, meta interface{}) action := "CreateInstance" var request map[string]interface{} var response map[string]interface{} + var endpoint string + var err error query := make(map[string]interface{}) - conn, err := client.NewBssopenapiClient() - if err != nil { - return WrapError(err) - } request = make(map[string]interface{}) request["ClientToken"] = buildClientToken(action) @@ -287,30 +284,32 @@ func resourceAliCloudKmsInstanceCreate(d *schema.ResourceData, meta interface{}) request["ProductCode"] = "kms" request["ProductType"] = "kms_ddi_public_cn" + if client.IsInternationalAccount() { + request["ProductType"] = "kms_ddi_public_intl" + } request["SubscriptionType"] = "Subscription" if v, ok := d.GetOk("payment_type"); ok && v == "PayAsYouGo" { - request["ProductCode"] = "kms" request["ProductType"] = "kms_ppi_public_cn" request["SubscriptionType"] = v + if client.IsInternationalAccount() { + request["ProductType"] = "kms_ppi_public_intl" + } } - 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("2017-12-14"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPostWithEndpoint("BssOpenApi", "2017-12-14", action, query, request, true, endpoint) if err != nil { - if IsExpectedErrors(err, []string{"InternalError"}) || NeedRetry(err) { + if NeedRetry(err) { wait() return resource.RetryableError(err) } - if IsExpectedErrors(err, []string{"NotApplicable"}) { - request["ProductCode"] = "kms" + if !client.IsInternationalAccount() && IsExpectedErrors(err, []string{"NotApplicable"}) { request["ProductType"] = "kms_ddi_public_intl" if v, ok := d.GetOk("payment_type"); ok && v == "PayAsYouGo" { - request["ProductCode"] = "kms" request["ProductType"] = "kms_ppi_public_intl" } - conn.Endpoint = String(connectivity.BssOpenAPIEndpointInternational) + endpoint = connectivity.BssOpenAPIEndpointInternational return resource.RetryableError(err) } return resource.NonRetryableError(err) @@ -322,12 +321,6 @@ func resourceAliCloudKmsInstanceCreate(d *schema.ResourceData, meta interface{}) if err != nil { return WrapErrorf(err, DefaultErrorMsg, "alicloud_kms_instance", action, AlibabaCloudSdkGoERROR) } - if fmt.Sprint(response["Success"]) == "nil" { - return WrapError(fmt.Errorf("%s failed, response: %v", action, response)) - } - if fmt.Sprint(response["Success"]) != "true" { - return WrapError(fmt.Errorf("%s failed, response: %v", action, response)) - } id, _ := jsonpath.Get("$.Data.InstanceId", response) d.SetId(fmt.Sprint(id)) @@ -339,10 +332,6 @@ func resourceAliCloudKmsInstanceCreate(d *schema.ResourceData, meta interface{}) } action = "ConnectKmsInstance" - conn, err = client.NewKmsClient() - if err != nil { - return WrapError(err) - } request = make(map[string]interface{}) request["KmsInstanceId"] = d.Id() @@ -358,11 +347,9 @@ func resourceAliCloudKmsInstanceCreate(d *schema.ResourceData, meta interface{}) request["VSwitchIds"] = convertListToCommaSeparate(jsonPathResult2.([]interface{})) } - 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("2016-01-20"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("Kms", "2016-01-20", action, query, request, false) if err != nil { if IsExpectedErrors(err, []string{"Forbidden.RamRoleNotFound"}) || NeedRetry(err) { wait() @@ -471,14 +458,11 @@ func resourceAliCloudKmsInstanceUpdate(d *schema.ResourceData, meta interface{}) client := meta.(*connectivity.AliyunClient) var request map[string]interface{} var response map[string]interface{} + var err error var query map[string]interface{} update := false d.Partial(true) action := "ModifyInstance" - conn, err := client.NewBssopenapiClient() - if err != nil { - return WrapError(err) - } request = make(map[string]interface{}) query = make(map[string]interface{}) request["InstanceId"] = d.Id() @@ -526,31 +510,36 @@ func resourceAliCloudKmsInstanceUpdate(d *schema.ResourceData, meta interface{}) } request["Parameter"] = parameterMapList + request["ProductCode"] = "kms" request["ProductType"] = "kms_ddi_public_cn" + if client.IsInternationalAccount() { + request["ProductType"] = "kms_ddi_public_intl" + } request["SubscriptionType"] = "Subscription" if v, ok := d.GetOk("payment_type"); ok && v == "PayAsYouGo" { request["ProductType"] = "kms_ppi_public_cn" - request["SubscriptionType"] = "PayAsYouGo" + request["SubscriptionType"] = v + if client.IsInternationalAccount() { + request["ProductType"] = "kms_ppi_public_intl" + } } - request["ProductCode"] = "kms" request["ModifyType"] = "Upgrade" if update && request["SubscriptionType"] == "Subscription" { - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) + var endpoint string 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("2017-12-14"), StringPointer("AK"), query, request, &runtime) + err = resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError { + response, err = client.RpcPostWithEndpoint("BssOpenApi", "2017-12-14", action, query, request, true, endpoint) if err != nil { - if IsExpectedErrors(err, []string{"InternalError"}) || NeedRetry(err) { + if NeedRetry(err) { wait() return resource.RetryableError(err) } - if IsExpectedErrors(err, []string{"NotApplicable"}) { - conn.Endpoint = String(connectivity.BssOpenAPIEndpointInternational) + if !client.IsInternationalAccount() && IsExpectedErrors(err, []string{"NotApplicable"}) { request["ProductType"] = "kms_ddi_public_intl" if v, ok := d.GetOk("payment_type"); ok && v == "PayAsYouGo" { request["ProductType"] = "kms_ppi_public_intl" } + endpoint = connectivity.BssOpenAPIEndpointInternational return resource.RetryableError(err) } return resource.NonRetryableError(err) @@ -561,9 +550,7 @@ func resourceAliCloudKmsInstanceUpdate(d *schema.ResourceData, meta interface{}) if err != nil { return WrapErrorf(err, DefaultErrorMsg, d.Id(), action, AlibabaCloudSdkGoERROR) } - if fmt.Sprint(response["Code"]) != "Success" { - return WrapError(fmt.Errorf("%s failed, response: %v", action, response)) - } + kmsServiceV2 := KmsServiceV2{client} stateConf := BuildStateConf([]string{}, []string{fmt.Sprint(d.Get("key_num"))}, d.Timeout(schema.TimeoutUpdate), 10*time.Second, kmsServiceV2.KmsInstanceStateRefreshFunc(d.Id(), "KeyNum", []string{})) if _, err := stateConf.WaitForState(); err != nil { @@ -572,10 +559,6 @@ func resourceAliCloudKmsInstanceUpdate(d *schema.ResourceData, meta interface{}) } update = false action = "UpdateKmsInstanceBindVpc" - conn, err = client.NewKmsClient() - if err != nil { - return WrapError(err) - } request = make(map[string]interface{}) query = make(map[string]interface{}) query["KmsInstanceId"] = d.Id() @@ -611,11 +594,9 @@ func resourceAliCloudKmsInstanceUpdate(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("GET"), StringPointer("2016-01-20"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("Kms", "2016-01-20", action, query, request, false) if err != nil { if NeedRetry(err) { wait() @@ -642,34 +623,30 @@ func resourceAliCloudKmsInstanceDelete(d *schema.ResourceData, meta interface{}) action := "RefundInstance" var request map[string]interface{} var response map[string]interface{} + var err error query := make(map[string]interface{}) - conn, err := client.NewBssopenapiClient() - if err != nil { - return WrapError(err) - } request = make(map[string]interface{}) request["InstanceId"] = d.Id() request["ClientToken"] = buildClientToken(action) - - request["ProductType"] = "kms_ddi_public_cn" request["ProductCode"] = "kms" + request["ProductType"] = "kms_ddi_public_cn" + if client.IsInternationalAccount() { + request["ProductType"] = "kms_ddi_public_intl" + } request["ImmediatelyRelease"] = "1" - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) + var endpoint string 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("2017-12-14"), StringPointer("AK"), query, request, &runtime) - request["ClientToken"] = buildClientToken(action) - + err = resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError { + response, err = client.RpcPostWithEndpoint("BssOpenApi", "2017-12-14", action, query, request, true, endpoint) if err != nil { if NeedRetry(err) { wait() return resource.RetryableError(err) } - if IsExpectedErrors(err, []string{"NotApplicable"}) { - conn.Endpoint = String(connectivity.BssOpenAPIEndpointInternational) + if !client.IsInternationalAccount() && IsExpectedErrors(err, []string{"NotApplicable"}) { request["ProductType"] = "kms_ddi_public_intl" + endpoint = connectivity.BssOpenAPIEndpointInternational return resource.RetryableError(err) } return resource.NonRetryableError(err) @@ -699,22 +676,18 @@ func resourceAliCloudKmsInstanceDelete(d *schema.ResourceData, meta interface{}) action := "ReleaseKmsInstance" var request map[string]interface{} var response map[string]interface{} + var err error query := make(map[string]interface{}) - conn, err := client.NewKmsClient() - if err != nil { - return WrapError(err) - } request = make(map[string]interface{}) request["KmsInstanceId"] = d.Id() if v, ok := d.GetOk("force_delete_without_backup"); ok { request["ForceDeleteWithoutBackup"] = v } - 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("2016-01-20"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("Kms", "2016-01-20", action, query, request, false) if err != nil { if NeedRetry(err) { @@ -738,10 +711,3 @@ func resourceAliCloudKmsInstanceDelete(d *schema.ResourceData, meta interface{}) } return nil } - -func convertKmsInstanceSubscriptionTypeRequest(source interface{}) interface{} { - source = fmt.Sprint(source) - switch source { - } - return source -} diff --git a/alicloud/resource_alicloud_kms_instance_test.go b/alicloud/resource_alicloud_kms_instance_test.go index 66ff378bdd57..3f0fa7715c9f 100644 --- a/alicloud/resource_alicloud_kms_instance_test.go +++ b/alicloud/resource_alicloud_kms_instance_test.go @@ -36,13 +36,13 @@ func TestAccAliCloudKmsInstance_basic4048(t *testing.T) { "secret_num": "0", "spec": "1000", "product_version": "3", - "vpc_id": "${local.vpc_id}", + "vpc_id": "${alicloud_vpc.default.id}", "log": "0", "log_storage": "0", "zone_ids": []string{ "cn-hangzhou-k", "cn-hangzhou-j"}, "vswitch_ids": []string{ - "${local.vsw_id}"}, + "${alicloud_vswitch.vswitch.id}"}, }), Check: resource.ComposeTestCheckFunc( testAccCheck(map[string]string{ @@ -74,19 +74,19 @@ func TestAccAliCloudKmsInstance_basic4048(t *testing.T) { "vpc_id": "${alicloud_vswitch.shareVswitch.vpc_id}", "region_id": "cn-hangzhou", "vswitch_id": "${alicloud_vswitch.shareVswitch.id}", - "vpc_owner_id": "1511928242963727", + "vpc_owner_id": "${data.alicloud_account.current.id}", }, { "vpc_id": "${alicloud_vswitch.share-vswitch2.vpc_id}", "region_id": "cn-hangzhou", "vswitch_id": "${alicloud_vswitch.share-vswitch2.id}", - "vpc_owner_id": "1511928242963727", + "vpc_owner_id": "${data.alicloud_account.current.id}", }, { "vpc_id": "${alicloud_vswitch.share-vsw3.vpc_id}", "region_id": "cn-hangzhou", "vswitch_id": "${alicloud_vswitch.share-vsw3.id}", - "vpc_owner_id": "1511928242963727", + "vpc_owner_id": "${data.alicloud_account.current.id}", }, }, }), @@ -194,11 +194,11 @@ func TestAccAliCloudKmsInstance_basic4048(t *testing.T) { "renew_status": "ManualRenewal", "product_version": "3", "renew_period": "3", - "vpc_id": "${local.vpc_id}", + "vpc_id": "${alicloud_vpc.default.id}", "zone_ids": []string{ "cn-hangzhou-k", "cn-hangzhou-j"}, "vswitch_ids": []string{ - "${local.vsw_id}"}, + "${alicloud_vswitch.vswitch.id}"}, }), Check: resource.ComposeTestCheckFunc( testAccCheck(map[string]string{ @@ -239,47 +239,24 @@ variable "name" { default = "%s" } +data "alicloud_account" "current" {} data "alicloud_zones" "default" { available_resource_creation = "VSwitch" } -data "alicloud_vpcs" "default" { - name_regex = "tf-testacc-kms-instance" - cidr_block = "172.16.0.0/12" -} - resource "alicloud_vpc" "default" { - count = length(data.alicloud_vpcs.default.ids) > 0 ? 0 : 1 cidr_block = "172.16.0.0/12" - vpc_name = "tf-testacc-kms-instance" -} - -data "alicloud_vswitches" "vswitch" { - vpc_id = local.vpc_id - zone_id = "cn-hangzhou-k" -} - -data "alicloud_vswitches" "vswitch-j" { - vpc_id = local.vpc_id - zone_id = "cn-hangzhou-j" -} - -locals { - vpc_id = length(data.alicloud_vpcs.default.ids) > 0 ? data.alicloud_vpcs.default.ids.0 : concat(alicloud_vpc.default[*].id, [""])[0] - vsw_id = length(data.alicloud_vswitches.vswitch.ids) > 0 ? data.alicloud_vswitches.vswitch.ids.0 : concat(alicloud_vswitch.vswitch[*].id, [""])[0] - vswj_id = length(data.alicloud_vswitches.vswitch-j.ids) > 0 ? data.alicloud_vswitches.vswitch-j.ids.0 : concat(alicloud_vswitch.vswitch-j[*].id, [""])[0] + vpc_name = var.name } resource "alicloud_vswitch" "vswitch" { - count = length(data.alicloud_vswitches.vswitch.ids) > 0 ? 0 : 1 - vpc_id = local.vpc_id + vpc_id = alicloud_vpc.default.id zone_id = "cn-hangzhou-k" cidr_block = "172.16.1.0/24" } resource "alicloud_vswitch" "vswitch-j" { - count = length(data.alicloud_vswitches.vswitch-j.ids) > 0 ? 0 : 1 - vpc_id = local.vpc_id + vpc_id = alicloud_vpc.default.id zone_id = "cn-hangzhou-j" cidr_block = "172.16.2.0/24" } @@ -327,47 +304,25 @@ variable "name" { default = "%s" } +data "alicloud_account" "current" {} + data "alicloud_zones" "default" { available_resource_creation = "VSwitch" } -data "alicloud_vpcs" "default" { - name_regex = "tf-testacc-kms-instance" - cidr_block = "172.16.0.0/12" -} - resource "alicloud_vpc" "default" { - count = length(data.alicloud_vpcs.default.ids) > 0 ? 0 : 1 cidr_block = "172.16.0.0/12" - vpc_name = "tf-testacc-kms-instance" -} - -data "alicloud_vswitches" "vswitch" { - vpc_id = local.vpc_id - zone_id = "ap-southeast-1a" -} - -data "alicloud_vswitches" "vswitch-j" { - vpc_id = local.vpc_id - zone_id = "ap-southeast-1b" -} - -locals { - vpc_id = length(data.alicloud_vpcs.default.ids) > 0 ? data.alicloud_vpcs.default.ids.0 : concat(alicloud_vpc.default[*].id, [""])[0] - vsw_id = length(data.alicloud_vswitches.vswitch.ids) > 0 ? data.alicloud_vswitches.vswitch.ids.0 : concat(alicloud_vswitch.vswitch[*].id, [""])[0] - vswj_id = length(data.alicloud_vswitches.vswitch-j.ids) > 0 ? data.alicloud_vswitches.vswitch-j.ids.0 : concat(alicloud_vswitch.vswitch-j[*].id, [""])[0] + vpc_name = var.name } resource "alicloud_vswitch" "vswitch" { - count = length(data.alicloud_vswitches.vswitch.ids) > 0 ? 0 : 1 - vpc_id = local.vpc_id + vpc_id = alicloud_vpc.default.id zone_id = "ap-southeast-1a" cidr_block = "172.16.1.0/24" } resource "alicloud_vswitch" "vswitch-j" { - count = length(data.alicloud_vswitches.vswitch-j.ids) > 0 ? 0 : 1 - vpc_id = local.vpc_id + vpc_id = alicloud_vpc.default.id zone_id = "ap-southeast-1b" cidr_block = "172.16.2.0/24" } @@ -425,6 +380,7 @@ func TestAccAliCloudKmsInstance_basic4048_twin(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) + testAccPreCheckWithAccountSiteType(t, DomesticSite) testAccPreCheckWithRegions(t, true, connectivity.KmsInstanceSupportRegions) }, IDRefreshName: resourceId, @@ -442,23 +398,23 @@ func TestAccAliCloudKmsInstance_basic4048_twin(t *testing.T) { "log": "1", "log_storage": "1000", "period": "2", - "vpc_id": "${local.vpc_id}", + "vpc_id": "${alicloud_vpc.default.id}", "zone_ids": []string{ "cn-hangzhou-k", "cn-hangzhou-j"}, "vswitch_ids": []string{ - "${local.vsw_id}"}, + "${alicloud_vswitch.vswitch.id}"}, "bind_vpcs": []map[string]interface{}{ { "vpc_id": "${alicloud_vpc.shareVPC.id}", "region_id": "cn-hangzhou", "vswitch_id": "${alicloud_vswitch.shareVswitch.id}", - "vpc_owner_id": "1511928242963727", + "vpc_owner_id": "${data.alicloud_account.current.id}", }, { "vpc_id": "${alicloud_vswitch.share-vsw3.vpc_id}", "region_id": "cn-hangzhou", "vswitch_id": "${alicloud_vswitch.share-vsw3.id}", - "vpc_owner_id": "1511928242963727", + "vpc_owner_id": "${data.alicloud_account.current.id}", }, }, }), @@ -513,6 +469,7 @@ func TestAccAliCloudKmsInstance_basic4048_postpaid(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) + testAccPreCheckWithAccountSiteType(t, DomesticSite) testAccPreCheckWithRegions(t, true, connectivity.KmsInstanceSupportRegions) }, IDRefreshName: resourceId, @@ -522,23 +479,23 @@ func TestAccAliCloudKmsInstance_basic4048_postpaid(t *testing.T) { Config: testAccConfig(map[string]interface{}{ "payment_type": "PayAsYouGo", "product_version": "3", - "vpc_id": "${local.vpc_id}", + "vpc_id": "${alicloud_vpc.default.id}", "zone_ids": []string{ "cn-hangzhou-k", "cn-hangzhou-j"}, "vswitch_ids": []string{ - "${local.vsw_id}"}, + "${alicloud_vswitch.vswitch.id}"}, "bind_vpcs": []map[string]interface{}{ { "vpc_id": "${alicloud_vpc.shareVPC.id}", "region_id": "cn-hangzhou", "vswitch_id": "${alicloud_vswitch.shareVswitch.id}", - "vpc_owner_id": "1511928242963727", + "vpc_owner_id": "${data.alicloud_account.current.id}", }, { "vpc_id": "${alicloud_vswitch.share-vsw3.vpc_id}", "region_id": "cn-hangzhou", "vswitch_id": "${alicloud_vswitch.share-vsw3.id}", - "vpc_owner_id": "1511928242963727", + "vpc_owner_id": "${data.alicloud_account.current.id}", }, }, "force_delete_without_backup": "true", @@ -566,19 +523,19 @@ func TestAccAliCloudKmsInstance_basic4048_postpaid(t *testing.T) { "vpc_id": "${alicloud_vswitch.shareVswitch.vpc_id}", "region_id": "cn-hangzhou", "vswitch_id": "${alicloud_vswitch.shareVswitch.id}", - "vpc_owner_id": "1511928242963727", + "vpc_owner_id": "${data.alicloud_account.current.id}", }, { "vpc_id": "${alicloud_vswitch.share-vswitch2.vpc_id}", "region_id": "cn-hangzhou", "vswitch_id": "${alicloud_vswitch.share-vswitch2.id}", - "vpc_owner_id": "1511928242963727", + "vpc_owner_id": "${data.alicloud_account.current.id}", }, { "vpc_id": "${alicloud_vswitch.share-vsw3.vpc_id}", "region_id": "cn-hangzhou", "vswitch_id": "${alicloud_vswitch.share-vsw3.id}", - "vpc_owner_id": "1511928242963727", + "vpc_owner_id": "${data.alicloud_account.current.id}", }, }, }), @@ -652,19 +609,19 @@ func TestAccAliCloudKmsInstance_basic4048_postpaid_intl(t *testing.T) { "vpc_id": "${alicloud_vswitch.shareVswitch.vpc_id}", "region_id": defaultRegionToTest, "vswitch_id": "${alicloud_vswitch.shareVswitch.id}", - "vpc_owner_id": "5806750234758840", + "vpc_owner_id": "${data.alicloud_account.current.id}", }, { "vpc_id": "${alicloud_vswitch.share-vswitch2.vpc_id}", "region_id": defaultRegionToTest, "vswitch_id": "${alicloud_vswitch.share-vswitch2.id}", - "vpc_owner_id": "5806750234758840", + "vpc_owner_id": "${data.alicloud_account.current.id}", }, { "vpc_id": "${alicloud_vswitch.share-vsw3.vpc_id}", "region_id": defaultRegionToTest, "vswitch_id": "${alicloud_vswitch.share-vsw3.id}", - "vpc_owner_id": "5806750234758840", + "vpc_owner_id": "${data.alicloud_account.current.id}", }, }, }), @@ -714,11 +671,11 @@ func TestAccAliCloudKmsInstance_basic4048_intl(t *testing.T) { "renew_status": "ManualRenewal", "product_version": "3", "renew_period": "3", - "vpc_id": "${local.vpc_id}", + "vpc_id": "${alicloud_vpc.default.id}", "zone_ids": []string{ "ap-southeast-1a", "ap-southeast-1b"}, "vswitch_ids": []string{ - "${local.vsw_id}"}, + "${alicloud_vswitch.vswitch.id}"}, }), Check: resource.ComposeTestCheckFunc( testAccCheck(map[string]string{ @@ -931,6 +888,8 @@ variable "name" { default = "%s" } +data "alicloud_account" "current" {} + data "alicloud_zones" "default" { available_resource_creation = "VSwitch" } @@ -943,13 +902,13 @@ resource "alicloud_vpc" "vpc-amp-instance-test" { resource "alicloud_vswitch" "vswitch" { vpc_id = alicloud_vpc.vpc-amp-instance-test.id - zone_id = data.alicloud_zones.default.zones.0.id + zone_id = data.alicloud_zones.default.zones.1.id cidr_block = "172.16.1.0/24" } resource "alicloud_vswitch" "vswitch-j" { vpc_id = alicloud_vpc.vpc-amp-instance-test.id - zone_id = data.alicloud_zones.default.zones.1.id + zone_id = data.alicloud_zones.default.zones.2.id cidr_block = "172.16.2.0/24" } diff --git a/alicloud/service_alicloud_kms_v2.go b/alicloud/service_alicloud_kms_v2.go index 08f426d3ccd0..253d0856d4ee 100644 --- a/alicloud/service_alicloud_kms_v2.go +++ b/alicloud/service_alicloud_kms_v2.go @@ -24,21 +24,15 @@ func (s *KmsServiceV2) DescribeKmsInstance(id string) (object map[string]interfa var request map[string]interface{} var response map[string]interface{} var query map[string]interface{} - conn, err := client.NewKmsClient() - if err != nil { - return object, WrapError(err) - } request = make(map[string]interface{}) query = make(map[string]interface{}) request["KmsInstanceId"] = id action := "GetKmsInstance" - 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("2016-01-20"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("Kms", "2016-01-20", action, query, request, true) if err != nil { if NeedRetry(err) { diff --git a/website/docs/d/event_bridge_service.html.markdown b/website/docs/d/event_bridge_service.html.markdown index 2834f7d1580e..154e1d81a890 100644 --- a/website/docs/d/event_bridge_service.html.markdown +++ b/website/docs/d/event_bridge_service.html.markdown @@ -19,7 +19,7 @@ For information about Event Bridge and how to use it, see [What is Event Bridge] ```terraform data "alicloud_event_bridge_service" "open" { - enable = "On" + enable = "On" } ```