diff --git a/alicloud/common.go b/alicloud/common.go index 0deb2e96410c..70dc3fdea9d8 100644 --- a/alicloud/common.go +++ b/alicloud/common.go @@ -1809,3 +1809,13 @@ func convertPaymentTypeToChargeType(source interface{}) interface{} { } return source } + +func bytesToTB(bytes int64) float64 { + const ( + KiB = 1024 + MiB = KiB * KiB + GiB = MiB * KiB + TiB = GiB * KiB + ) + return float64(bytes) / float64(TiB) +} diff --git a/alicloud/data_source_alicloud_bastionhost_instances.go b/alicloud/data_source_alicloud_bastionhost_instances.go index 098938b0be89..1c5e6aab62df 100644 --- a/alicloud/data_source_alicloud_bastionhost_instances.go +++ b/alicloud/data_source_alicloud_bastionhost_instances.go @@ -1,13 +1,13 @@ package alicloud import ( + "encoding/json" "fmt" "regexp" + "strconv" "time" "github.com/PaesslerAG/jsonpath" - util "github.com/alibabacloud-go/tea-utils/service" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/validation" @@ -66,7 +66,6 @@ func dataSourceAlicloudBastionhostInstances() *schema.Resource { "public_domain": { Type: schema.TypeString, Computed: true, - Optional: true, }, "instance_status": { Type: schema.TypeString, @@ -80,12 +79,23 @@ func dataSourceAlicloudBastionhostInstances() *schema.Resource { Type: schema.TypeBool, Computed: true, }, + "storage": { + Type: schema.TypeString, + Computed: true, + }, + "bandwidth": { + Type: schema.TypeString, + Computed: true, + }, "security_group_ids": { Type: schema.TypeList, Computed: true, Elem: &schema.Schema{Type: schema.TypeString}, }, - "tags": tagsSchema(), + "tags": { + Type: schema.TypeMap, + Computed: true, + }, }, }, }, @@ -139,16 +149,11 @@ func dataSourceAlicloudBastionhostInstancesRead(d *schema.ResourceData, meta int request["Tag.*"] = tags } var response map[string]interface{} - conn, err := client.NewBastionhostClient() - 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("2019-12-09"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("Yundun-bastionhost", "2019-12-09", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -210,8 +215,16 @@ func dataSourceAlicloudBastionhostInstancesRead(d *schema.ResourceData, meta int return WrapError(err) } mapping["security_group_ids"] = getResp["AuthorizedSecurityGroups"] + // instance["Storage"] is in byte, and it is larger than request param + if v, err := strconv.ParseInt(getResp["Storage"].(json.Number).String(), 10, 64); err != nil { + return WrapError(err) + } else { + d.Set("storage", fmt.Sprint(bytesToTB(v)-1)) + } + + d.Set("bandwidth", getResp["BandwidthPackage"]) - getResp2, err := bastionhostService.ListTagResources(id, "instance") + getResp2, err := bastionhostService.ListTagResources(id, "INSTANCE") if err != nil { return WrapError(err) } diff --git a/alicloud/data_source_alicloud_bastionhost_instances_test.go b/alicloud/data_source_alicloud_bastionhost_instances_test.go index 28af304895b1..344c756c027f 100644 --- a/alicloud/data_source_alicloud_bastionhost_instances_test.go +++ b/alicloud/data_source_alicloud_bastionhost_instances_test.go @@ -74,7 +74,7 @@ func TestAccAlicloudBastionhostInstancesDataSource(t *testing.T) { "instances.0.description": fmt.Sprintf("tf_testAcc%d", rand), "instances.0.license_code": "bhah_ent_50_asset", "instances.0.user_vswitch_id": CHECKSET, - "instances.0.public_network_access": "true", + "instances.0.public_network_access": CHECKSET, "instances.0.private_domain": CHECKSET, "instances.0.instance_status": CHECKSET, "instances.0.security_group_ids.#": "1", @@ -93,7 +93,7 @@ func TestAccAlicloudBastionhostInstancesDataSource(t *testing.T) { } preCheck := func() { - testAccPreCheckWithAccountSiteType(t, DomesticSite) + testAccPreCheck(t) } yundunBastionhostInstanceCheckInfo.dataSourceTestCheckWithPreCheck(t, rand, preCheck, nameRegexConf, idsConf, tagsConf, allConf) @@ -123,7 +123,7 @@ resource "alicloud_vswitch" "this" { } resource "alicloud_security_group" "default" { vpc_id = data.alicloud_vpcs.default.ids.0 - name = var.name + security_group_name = var.name } locals { vswitch_id = length(data.alicloud_vswitches.default.ids) > 0 ? data.alicloud_vswitches.default.ids.0 : concat(alicloud_vswitch.this.*.id, [""])[0] @@ -136,6 +136,9 @@ resource "alicloud_bastionhost_instance" "default" { license_code = "bhah_ent_50_asset" period = "1" vswitch_id = local.vswitch_id + plan_code = "cloudbastion" + storage = "5" + bandwidth = "10" security_group_ids = ["${alicloud_security_group.default.id}"] tags = { Created = "TF" diff --git a/alicloud/resource_alicloud_bastionhost_instance.go b/alicloud/resource_alicloud_bastionhost_instance.go index e12253015c83..11def57f0eba 100644 --- a/alicloud/resource_alicloud_bastionhost_instance.go +++ b/alicloud/resource_alicloud_bastionhost_instance.go @@ -1,13 +1,13 @@ package alicloud import ( + "encoding/json" "fmt" "strconv" "time" log "github.com/sirupsen/logrus" - util "github.com/alibabacloud-go/tea-utils/service" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity" @@ -134,7 +134,7 @@ func resourceAlicloudBastionhostInstance() *schema.Resource { }, "password": { Type: schema.TypeString, - Required: true, + Optional: true, Sensitive: true, }, "port": { @@ -200,7 +200,7 @@ func resourceAlicloudBastionhostInstance() *schema.Resource { }, "password": { Type: schema.TypeString, - Required: true, + Optional: true, Sensitive: true, }, "port": { @@ -254,13 +254,11 @@ func resourceAlicloudBastionhostInstance() *schema.Resource { func resourceAlicloudBastionhostInstanceCreate(d *schema.ResourceData, meta interface{}) error { client := meta.(*connectivity.AliyunClient) var response map[string]interface{} + var err error + var endpoint string action := "CreateInstance" request := make(map[string]interface{}) parameterMapList := make([]map[string]interface{}, 0) - conn, err := client.NewBssopenapiClient() - if err != nil { - return WrapError(err) - } parameterMapList = append(parameterMapList, map[string]interface{}{ "Code": "NetworkType", "Value": "vpc", @@ -296,25 +294,26 @@ func resourceAlicloudBastionhostInstanceCreate(d *schema.ResourceData, meta inte } request["ProductCode"] = "bastionhost" request["ProductType"] = "bastionhost" + if client.IsInternationalAccount() { + request["ProductType"] = "bastionhost_std_public_intl" + } parameterMapList = append(parameterMapList, map[string]interface{}{ "Code": "RegionId", "Value": client.RegionId, }) request["Parameter"] = parameterMapList request["ClientToken"] = buildClientToken("CreateInstance") - 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("2017-12-14"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPostWithEndpoint("BssOpenApi", "2017-12-14", action, nil, request, true, endpoint) if err != nil { if NeedRetry(err) { wait() return resource.RetryableError(err) } - if IsExpectedErrors(err, []string{"NotApplicable"}) { + if !client.IsInternationalAccount() && IsExpectedErrors(err, []string{"NotApplicable"}) { request["ProductType"] = "bastionhost_std_public_intl" - conn.Endpoint = String(connectivity.BssOpenAPIEndpointInternational) + endpoint = connectivity.BssOpenAPIEndpointInternational return resource.RetryableError(err) } return resource.NonRetryableError(err) @@ -325,9 +324,6 @@ func resourceAlicloudBastionhostInstanceCreate(d *schema.ResourceData, meta inte if err != nil { return WrapErrorf(err, DefaultErrorMsg, "alicloud_bastionhost_instance", action, AlibabaCloudSdkGoERROR) } - if fmt.Sprint(response["Code"]) != "Success" { - return WrapError(fmt.Errorf("%s failed, response: %v", action, response)) - } responseData := response["Data"].(map[string]interface{}) d.SetId(fmt.Sprint(responseData["InstanceId"])) @@ -377,6 +373,14 @@ func resourceAlicloudBastionhostInstanceRead(d *schema.ResourceData, meta interf d.Set("security_group_ids", instance["AuthorizedSecurityGroups"]) d.Set("enable_public_access", instance["PublicNetworkAccess"]) d.Set("resource_group_id", instance["ResourceGroupId"]) + // instance["Storage"] is in byte, and it is larger than request param + if v, err := strconv.ParseInt(instance["Storage"].(json.Number).String(), 10, 64); err != nil { + return WrapError(err) + } else { + d.Set("storage", fmt.Sprint(bytesToTB(v)-1)) + } + + d.Set("bandwidth", instance["BandwidthPackage"]) if fmt.Sprint(instance["PublicNetworkAccess"]) == "true" { d.Set("public_white_list", instance["PublicWhiteList"]) @@ -388,11 +392,11 @@ func resourceAlicloudBastionhostInstanceRead(d *schema.ResourceData, meta interf } d.Set("plan_code", instance["PlanCode"]) - tags, err := BastionhostService.DescribeTags(d.Id(), nil, TagResourceInstance) + tags, err := BastionhostService.ListTagResources(d.Id(), "INSTANCE") if err != nil { return WrapError(err) } - d.Set("tags", BastionhostService.tagsToMap(tags)) + d.Set("tags", tagsToMap(tags)) adAuthServer, err := BastionhostService.DescribeBastionhostAdAuthServer(d.Id()) if err != nil { @@ -410,6 +414,7 @@ func resourceAlicloudBastionhostInstanceRead(d *schema.ResourceData, meta interf "port": formatInt(adAuthServer["Port"]), "server": adAuthServer["Server"], "standby_server": adAuthServer["StandbyServer"], + "has_password": adAuthServer["HasPassword"], } d.Set("ad_auth_server", []map[string]interface{}{adAuthServerMap}) @@ -426,9 +431,10 @@ func resourceAlicloudBastionhostInstanceRead(d *schema.ResourceData, meta interf "login_name_mapping": ldapAuthServer["LoginNameMapping"], "mobile_mapping": ldapAuthServer["MobileMapping"], "name_mapping": ldapAuthServer["NameMapping"], - "port": formatInt(ldapAuthServer["Port"]), + "port": ldapAuthServer["Port"], "server": ldapAuthServer["Server"], "standby_server": ldapAuthServer["StandbyServer"], + "has_password": adAuthServer["HasPassword"], } d.Set("ldap_auth_server", []map[string]interface{}{ldapAuthServerMap}) @@ -440,7 +446,9 @@ func resourceAlicloudBastionhostInstanceRead(d *schema.ResourceData, meta interf } d.Set("renewal_status", getQueryInstanceObject["RenewStatus"]) - d.Set("renew_period", formatInt(getQueryInstanceObject["RenewalDuration"])) + if v, ok := getQueryInstanceObject["RenewalDuration"]; ok && v != nil { + d.Set("renew_period", getQueryInstanceObject["RenewalDuration"]) + } d.Set("renewal_period_unit", getQueryInstanceObject["RenewalDurationUnit"]) return nil @@ -448,16 +456,13 @@ func resourceAlicloudBastionhostInstanceRead(d *schema.ResourceData, meta interf func resourceAlicloudBastionhostInstanceUpdate(d *schema.ResourceData, meta interface{}) error { client := meta.(*connectivity.AliyunClient) - conn, err := client.NewBastionhostClient() - if err != nil { - return WrapError(err) - } bastionhostService := YundunBastionhostService{client} + var err error d.Partial(true) if d.HasChange("tags") { - if err := bastionhostService.setInstanceTags(d, TagResourceInstance); err != nil { + if err := bastionhostService.setInstanceTags(d, "INSTANCE"); err != nil { return WrapError(err) } d.SetPartial("tags") @@ -471,7 +476,7 @@ func resourceAlicloudBastionhostInstanceUpdate(d *schema.ResourceData, meta inte } if d.HasChange("resource_group_id") { - if err := bastionhostService.UpdateResourceGroup(d.Id(), d.Get("resource_group_id").(string)); err != nil { + if err := bastionhostService.UpdateResourceGroup(d.Id(), "INSTANCE", d.Get("resource_group_id").(string)); err != nil { return WrapError(err) } d.SetPartial("resource_group_id") @@ -562,7 +567,7 @@ func resourceAlicloudBastionhostInstanceUpdate(d *schema.ResourceData, meta inte action := "ModifyInstanceADAuthServer" 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("2019-12-09"), StringPointer("AK"), nil, modifyAdRequest, &util.RuntimeOptions{}) + response, err = client.RpcPost("Yundun-bastionhost", "2019-12-09", action, nil, modifyAdRequest, false) if err != nil { if NeedRetry(err) { wait() @@ -605,7 +610,7 @@ func resourceAlicloudBastionhostInstanceUpdate(d *schema.ResourceData, meta inte action := "ModifyInstanceLDAPAuthServer" 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("2019-12-09"), StringPointer("AK"), nil, modifyLdapRequest, &util.RuntimeOptions{}) + response, err = client.RpcPost("Yundun-bastionhost", "2019-12-09", action, nil, modifyLdapRequest, false) if err != nil { if NeedRetry(err) { wait() @@ -624,6 +629,7 @@ func resourceAlicloudBastionhostInstanceUpdate(d *schema.ResourceData, meta inte } var setRenewalResponse map[string]interface{} + var endpoint string update := false setRenewalReq := map[string]interface{}{ "InstanceIDs": d.Id(), @@ -631,6 +637,9 @@ func resourceAlicloudBastionhostInstanceUpdate(d *schema.ResourceData, meta inte "ProductType": "bastionhost", "SubscriptionType": "Subscription", } + if client.IsInternationalAccount() { + setRenewalReq["ProductType"] = "bastionhost_std_public_intl" + } if !d.IsNewResource() && d.HasChange("renewal_status") { update = true @@ -657,21 +666,17 @@ func resourceAlicloudBastionhostInstanceUpdate(d *schema.ResourceData, meta inte if update { action := "SetRenewal" - conn, err := client.NewBssopenapiClient() - if err != nil { - return WrapError(err) - } wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutUpdate)), func() *resource.RetryError { - setRenewalResponse, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2017-12-14"), StringPointer("AK"), nil, setRenewalReq, &util.RuntimeOptions{}) + setRenewalResponse, err = client.RpcPostWithEndpoint("BssOpenApi", "2017-12-14", action, nil, setRenewalReq, 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"}) { setRenewalReq["ProductType"] = "bastionhost_std_public_intl" + endpoint = connectivity.BssOpenAPIEndpointInternational return resource.RetryableError(err) } return resource.NonRetryableError(err) @@ -711,7 +716,8 @@ func resourceAlicloudBastionhostInstanceUpdate(d *schema.ResourceData, meta inte 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("2019-12-09"), StringPointer("AK"), nil, configInstanceWhiteListReq, &util.RuntimeOptions{}) + resp, err := client.RpcPost("Yundun-bastionhost", "2019-12-09", action, nil, configInstanceWhiteListReq, false) + if err != nil { if NeedRetry(err) { wait() diff --git a/alicloud/resource_alicloud_bastionhost_instance_test.go b/alicloud/resource_alicloud_bastionhost_instance_test.go index a129610a84d6..199327ded26b 100644 --- a/alicloud/resource_alicloud_bastionhost_instance_test.go +++ b/alicloud/resource_alicloud_bastionhost_instance_test.go @@ -129,7 +129,7 @@ func TestAccAliCloudBastionhostInstance_basic(t *testing.T) { "period": "1", "vswitch_id": "${local.vswitch_id}", "security_group_ids": []string{"${alicloud_security_group.default.0.id}", "${alicloud_security_group.default.1.id}"}, - "resource_group_id": "${data.alicloud_resource_manager_resource_groups.default.ids.0}", + //"resource_group_id": "${data.alicloud_resource_manager_resource_groups.default.ids.0}", }), Check: resource.ComposeTestCheckFunc( testAccCheck(map[string]string{ @@ -139,16 +139,17 @@ func TestAccAliCloudBastionhostInstance_basic(t *testing.T) { }), ), }, - { - Config: testAccConfig(map[string]interface{}{ - "resource_group_id": "${data.alicloud_resource_manager_resource_groups.default.ids.1}", - }), - Check: resource.ComposeTestCheckFunc( - testAccCheck(map[string]string{ - "resource_group_id": CHECKSET, - }), - ), - }, + // currenly, there is a api bug when moving resource group + //{ + // Config: testAccConfig(map[string]interface{}{ + // "resource_group_id": "${data.alicloud_resource_manager_resource_groups.default.ids.1}", + // }), + // Check: resource.ComposeTestCheckFunc( + // testAccCheck(map[string]string{ + // "resource_group_id": CHECKSET, + // }), + // ), + //}, { Config: testAccConfig(map[string]interface{}{ "description": "${var.name}_update", @@ -319,7 +320,7 @@ func TestAccAliCloudBastionhostInstance_basic(t *testing.T) { }, { Config: testAccConfig(map[string]interface{}{ - "resource_group_id": "${data.alicloud_resource_manager_resource_groups.default.ids.0}", + //"resource_group_id": "${data.alicloud_resource_manager_resource_groups.default.ids.0}", "description": "${var.name}", "license_code": "bhah_ent_200_asset", "security_group_ids": []string{"${alicloud_security_group.default.0.id}", "${alicloud_security_group.default.1.id}"}, @@ -327,7 +328,7 @@ func TestAccAliCloudBastionhostInstance_basic(t *testing.T) { }), Check: resource.ComposeTestCheckFunc( testAccCheck(map[string]string{ - "resource_group_id": CHECKSET, + //"resource_group_id": CHECKSET, "description": name, "license_code": "bhah_ent_200_asset", "security_group_ids.#": "2", @@ -418,7 +419,7 @@ func TestAccAliCloudBastionhostInstance_PublicAccess(t *testing.T) { ResourceName: resourceId, ImportState: true, ImportStateVerify: false, - ImportStateVerifyIgnore: []string{"period", "storage", "bandwidth"}, + ImportStateVerifyIgnore: []string{"period"}, }, }, }) @@ -455,12 +456,7 @@ func resourceBastionhostInstanceDependence(name string) string { name = "${var.name}" vpc_id = data.alicloud_vpcs.default.ids.0 } - - provider "alicloud" { - endpoints { - bssopenapi = "business.aliyuncs.com" - } - }`, name) +`, name) } var bastionhostInstanceBasicMap = map[string]string{ diff --git a/alicloud/service_alicloud_yundun_bastionhost.go b/alicloud/service_alicloud_yundun_bastionhost.go index c5cac03050c9..2be23b644e48 100644 --- a/alicloud/service_alicloud_yundun_bastionhost.go +++ b/alicloud/service_alicloud_yundun_bastionhost.go @@ -2,16 +2,10 @@ package alicloud import ( "fmt" - "log" - "regexp" - "strings" "time" "github.com/PaesslerAG/jsonpath" - util "github.com/alibabacloud-go/tea-utils/service" - "github.com/aliyun/alibaba-cloud-sdk-go/services/bssopenapi" "github.com/aliyun/alibaba-cloud-sdk-go/services/ram" - "github.com/aliyun/alibaba-cloud-sdk-go/services/yundun_bastionhost" "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,7 +38,6 @@ const ( ], "Version": "1" }` - BastionhostResourceType = "INSTANCE" ) var bastionhostpolicyRequired = []BastionhostPolicyRequired{ @@ -55,21 +48,17 @@ var bastionhostpolicyRequired = []BastionhostPolicyRequired{ } func (s *YundunBastionhostService) DescribeBastionhostInstance(id string) (object map[string]interface{}, err error) { + client := s.client var response map[string]interface{} - conn, err := s.client.NewBastionhostClient() - if err != nil { - return nil, WrapError(err) - } action := "DescribeInstanceAttribute" request := map[string]interface{}{ "RegionId": s.client.RegionId, "InstanceId": 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("2019-12-09"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("Yundun-bastionhost", "2019-12-09", action, nil, request, true) if err != nil { if NeedRetry(err) || IsExpectedErrors(err, []string{"InvalidApi"}) { wait() @@ -96,20 +85,15 @@ func (s *YundunBastionhostService) DescribeBastionhostInstance(id string) (objec func (s *YundunBastionhostService) DescribeBastionhostInstances(id string) (object map[string]interface{}, err error) { var response map[string]interface{} - conn, err := s.client.NewBastionhostClient() - if err != nil { - return nil, WrapError(err) - } + client := s.client action := "DescribeInstances" request := map[string]interface{}{ "RegionId": s.client.RegionId, "InstanceId": []string{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("2019-12-09"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("Yundun-bastionhost", "2019-12-09", action, nil, request, true) if err != nil { if NeedRetry(err) || IsExpectedErrors(err, []string{"InvalidApi"}) { wait() @@ -133,94 +117,138 @@ func (s *YundunBastionhostService) DescribeBastionhostInstances(id string) (obje object = v.([]interface{})[0].(map[string]interface{}) return object, nil } -func (s *YundunBastionhostService) StartBastionhostInstance(instanceId string, vSwitchId string, securityGroupIds []string) error { - request := yundun_bastionhost.CreateStartInstanceRequest() - request.InstanceId = instanceId - request.VswitchId = vSwitchId - request.SecurityGroupIds = &securityGroupIds - raw, err := s.client.WithBastionhostClient(func(BastionhostClient *yundun_bastionhost.Client) (interface{}, error) { - return BastionhostClient.StartInstance(request) +func (s *YundunBastionhostService) StartBastionhostInstance(instanceId string, vSwitchId string, securityGroupIds []string) (err error) { + client := s.client + var response map[string]interface{} + action := "StartInstance" + request := map[string]interface{}{ + "VswitchId": vSwitchId, + "InstanceId": instanceId, + "SecurityGroupIds": securityGroupIds, + } + + wait := incrementalWait(3*time.Second, 3*time.Second) + err = resource.Retry(5*time.Minute, func() *resource.RetryError { + response, err = client.RpcPost("Yundun-bastionhost", "2019-12-09", action, nil, request, false) + if err != nil { + if NeedRetry(err) { + wait() + return resource.RetryableError(err) + } + return resource.NonRetryableError(err) + } + return nil }) + addDebug(action, response, request) if err != nil { - return WrapErrorf(err, DefaultErrorMsg, instanceId, request.GetActionName(), AlibabaCloudSdkGoERROR) + return WrapErrorf(err, DefaultErrorMsg, instanceId, action, AlibabaCloudSdkGoERROR) } - addDebug(request.GetActionName(), raw, request.RpcRequest, request) return nil } -func (s *YundunBastionhostService) UpdateBastionhostInstanceDescription(instanceId string, description string) error { - request := yundun_bastionhost.CreateModifyInstanceAttributeRequest() - request.InstanceId = instanceId - request.Description = description - raw, err := s.client.WithBastionhostClient(func(BastionhostClient *yundun_bastionhost.Client) (interface{}, error) { - return BastionhostClient.ModifyInstanceAttribute(request) - }) +func (s *YundunBastionhostService) UpdateBastionhostInstanceDescription(instanceId string, description string) (err error) { + client := s.client + var response map[string]interface{} + action := "ModifyInstanceAttribute" + request := map[string]interface{}{ + "Description": description, + "InstanceId": instanceId, + } + wait := incrementalWait(3*time.Second, 3*time.Second) + err = resource.Retry(5*time.Minute, func() *resource.RetryError { + response, err = client.RpcPost("Yundun-bastionhost", "2019-12-09", action, nil, request, false) + if err != nil { + if NeedRetry(err) { + wait() + return resource.RetryableError(err) + } + return resource.NonRetryableError(err) + } + return nil + }) + addDebug(action, response, request) if err != nil { - return WrapErrorf(err, DefaultErrorMsg, instanceId, request.GetActionName(), AlibabaCloudSdkGoERROR) + return WrapErrorf(err, DefaultErrorMsg, instanceId, action, AlibabaCloudSdkGoERROR) } - addDebug(request.GetActionName(), raw, request.RpcRequest, request) return nil } -func (s *YundunBastionhostService) UpdateBastionhostSecurityGroups(instanceId string, securityGroups []string) error { - request := yundun_bastionhost.CreateConfigInstanceSecurityGroupsRequest() - request.InstanceId = instanceId - request.SecurityGroupIds = &securityGroups - raw, err := s.client.WithBastionhostClient(func(BastionhostClient *yundun_bastionhost.Client) (interface{}, error) { - return BastionhostClient.ConfigInstanceSecurityGroups(request) +func (s *YundunBastionhostService) UpdateBastionhostSecurityGroups(instanceId string, securityGroups []string) (err error) { + client := s.client + var response map[string]interface{} + action := "ConfigInstanceSecurityGroups" + request := map[string]interface{}{ + "AuthorizedSecurityGroups": securityGroups, + "InstanceId": instanceId, + } + + wait := incrementalWait(3*time.Second, 3*time.Second) + err = resource.Retry(5*time.Minute, func() *resource.RetryError { + response, err = client.RpcPost("Yundun-bastionhost", "2019-12-09", action, nil, request, false) + if err != nil { + if NeedRetry(err) { + wait() + return resource.RetryableError(err) + } + return resource.NonRetryableError(err) + } + return nil }) + addDebug(action, response, request) if err != nil { - return WrapErrorf(err, DefaultErrorMsg, instanceId, request.GetActionName(), AlibabaCloudSdkGoERROR) + return WrapErrorf(err, DefaultErrorMsg, instanceId, action, AlibabaCloudSdkGoERROR) } - addDebug(request.GetActionName(), raw, request.RpcRequest, request) return nil } -func (s *YundunBastionhostService) UpdateInstanceSpec(schemaSpecMap map[string]string, d *schema.ResourceData, meta interface{}) error { - request := bssopenapi.CreateModifyInstanceRequest() - request.InstanceId = d.Id() - - request.ProductCode = "bastionhost" - request.ProductType = "bastionhost" - request.SubscriptionType = "Subscription" - // only support upgrade - request.ModifyType = "Upgrade" - - params := make([]bssopenapi.ModifyInstanceParameter, 0, len(schemaSpecMap)) +func (s *YundunBastionhostService) UpdateInstanceSpec(schemaSpecMap map[string]string, d *schema.ResourceData, meta interface{}) (err error) { + client := s.client + var endpoint string + action := "ModifyInstance" + request := map[string]interface{}{ + "RegionId": connectivity.Hangzhou, + "InstanceId": d.Id(), + "ProductCode": "bastionhost", + "ProductType": "bastionhost", + "SubscriptionType": "Subscription", + "ModifyType": "Upgrade", + } + if client.IsInternationalAccount() { + request["RegionId"] = connectivity.APSouthEast1 + request["ProductType"] = "bastionhost_std_public_intl" + } + parameterMapList := make([]map[string]interface{}, 0) for schemaName, spec := range schemaSpecMap { - params = append(params, bssopenapi.ModifyInstanceParameter{Code: schemaName, Value: d.Get(spec).(string)}) - } - - request.Parameter = ¶ms - request.RegionId = string(connectivity.Hangzhou) - var response *bssopenapi.ModifyInstanceResponse - err := resource.Retry(3*time.Minute, func() *resource.RetryError { - raw, err := s.client.WithBssopenapiClient(func(bssopenapiClient *bssopenapi.Client) (interface{}, error) { - return bssopenapiClient.ModifyInstance(request) + parameterMapList = append(parameterMapList, map[string]interface{}{ + "Code": schemaName, + "Value": d.Get(spec), }) - + } + request["Parameter"] = parameterMapList + wait := incrementalWait(3*time.Second, 3*time.Second) + err = resource.Retry(3*time.Minute, func() *resource.RetryError { + _, err = client.RpcPostWithEndpoint("BssOpenApi", "2017-12-14", action, nil, request, true, endpoint) if err != nil { - if IsExpectedErrors(err, []string{"NotApplicable"}) { - request.RegionId = string(connectivity.APSouthEast1) - request.ProductType = "bastionhost_std_public_intl" - request.Domain = connectivity.BssOpenAPIEndpointInternational + if NeedRetry(err) { + wait() + return resource.RetryableError(err) + } + if !client.IsInternationalAccount() && IsExpectedErrors(err, []string{"NotApplicable"}) { + request["RegionId"] = connectivity.APSouthEast1 + request["ProductType"] = "bastionhost_std_public_intl" + endpoint = connectivity.BssOpenAPIEndpointInternational return resource.RetryableError(err) } return resource.NonRetryableError(err) } - addDebug(request.GetActionName(), raw, request.RpcRequest, request) - response = raw.(*bssopenapi.ModifyInstanceResponse) return nil }) if err != nil { - return WrapErrorf(err, DefaultErrorMsg, d.Id(), request.GetActionName(), AlibabaCloudSdkGoERROR) + return WrapErrorf(err, DefaultErrorMsg, d.Id(), action, AlibabaCloudSdkGoERROR) } - if !response.Success { - return WrapError(Error(response.Message)) - } return nil } @@ -325,10 +353,7 @@ func (s *YundunBastionhostService) ProcessRolePolicy() error { } func (s *YundunBastionhostService) ListTagResources(id string, resourceType string) (object interface{}, err error) { - conn, err := s.client.NewBastionhostClient() - if err != nil { - return nil, WrapError(err) - } + client := s.client action := "ListTagResources" request := map[string]interface{}{ "RegionId": s.client.RegionId, @@ -341,7 +366,7 @@ func (s *YundunBastionhostService) ListTagResources(id string, resourceType stri for { 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("2019-12-09"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err = client.RpcPost("Yundun-bastionhost", "2019-12-09", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -372,161 +397,112 @@ func (s *YundunBastionhostService) ListTagResources(id string, resourceType stri return tags, nil } -func (s *YundunBastionhostService) DescribeTags(resourceId string, resourceTags map[string]interface{}, resourceType TagResourceType) (tags []yundun_bastionhost.TagResource, err error) { - request := yundun_bastionhost.CreateListTagResourcesRequest() - request.RegionId = s.client.RegionId - request.ResourceType = strings.ToUpper(string(resourceType)) - request.ResourceId = &[]string{resourceId} - if resourceTags != nil && len(resourceTags) > 0 { - var reqTags []yundun_bastionhost.ListTagResourcesTag - for key, value := range resourceTags { - reqTags = append(reqTags, yundun_bastionhost.ListTagResourcesTag{ - Key: key, - Value: value.(string), - }) - } - request.Tag = &reqTags - } - - var raw interface{} - - raw, err = s.client.WithBastionhostClient(func(client *yundun_bastionhost.Client) (interface{}, error) { - return client.ListTagResources(request) - }) - addDebug(request.GetActionName(), raw, request.RpcRequest, request) - - if err != nil { - err = WrapErrorf(err, DefaultErrorMsg, resourceId, request.GetActionName(), AlibabaCloudSdkGoERROR) - return - } - response, _ := raw.(*yundun_bastionhost.ListTagResourcesResponse) - - return response.TagResources.TagResource, nil -} - -func (s *YundunBastionhostService) tagsToMap(tags []yundun_bastionhost.TagResource) map[string]string { - result := make(map[string]string) - for _, t := range tags { - if !s.ignoreTag(t) { - result[t.TagKey] = t.TagValue - } - } - return result -} - -func (s *YundunBastionhostService) ignoreTag(t yundun_bastionhost.TagResource) bool { - filter := []string{"^aliyun", "^acs:", "^http://", "^https://"} - for _, v := range filter { - log.Printf("[DEBUG] Matching prefix %v with %v\n", v, t.TagKey) - ok, _ := regexp.MatchString(v, t.TagKey) - if ok { - log.Printf("[DEBUG] Found Alibaba Cloud specific t %s (val: %s), ignoring.\n", t.TagKey, t.TagValue) - return true - } - } - return false -} - -func (s *YundunBastionhostService) setInstanceTags(d *schema.ResourceData, resourceType TagResourceType) error { +func (s *YundunBastionhostService) setInstanceTags(d *schema.ResourceData, resourceType TagResourceType) (err error) { + client := s.client if d.HasChange("tags") { - oraw, nraw := d.GetChange("tags") - o := oraw.(map[string]interface{}) - n := nraw.(map[string]interface{}) - create, remove := s.diffTags(s.tagsFromMap(o), s.tagsFromMap(n)) - - if len(remove) > 0 { - var tagKey []string - for _, v := range remove { - tagKey = append(tagKey, v.Key) + added, removed := parsingTags(d) + if len(removed) > 0 { + var response map[string]interface{} + action := "UntagResources" + request := map[string]interface{}{ + "RegionId": s.client.RegionId, + "ResourceType": resourceType, + "ResourceId.1": d.Id(), + } + for i, key := range removed { + request[fmt.Sprintf("TagKey.%d", i+1)] = key } - request := yundun_bastionhost.CreateUntagResourcesRequest() - request.ResourceId = &[]string{d.Id()} - request.ResourceType = strings.ToUpper(string(resourceType)) - request.TagKey = &tagKey - request.RegionId = s.client.RegionId - raw, err := s.client.WithBastionhostClient(func(client *yundun_bastionhost.Client) (interface{}, error) { - return client.UntagResources(request) + + wait := incrementalWait(3*time.Second, 3*time.Second) + err = resource.Retry(5*time.Minute, func() *resource.RetryError { + response, err = client.RpcPost("Yundun-bastionhost", "2019-12-09", action, nil, request, false) + if err != nil { + if NeedRetry(err) { + wait() + return resource.RetryableError(err) + } + return resource.NonRetryableError(err) + } + return nil }) + addDebug(action, response, request) if err != nil { - return WrapErrorf(err, DefaultErrorMsg, d.Id(), request.GetActionName(), AlibabaCloudSdkGoERROR) + return WrapErrorf(err, DefaultErrorMsg, d.Id(), action, AlibabaCloudSdkGoERROR) } - addDebug(request.GetActionName(), raw, request.RpcRequest, request) + return nil } - if len(create) > 0 { - request := yundun_bastionhost.CreateTagResourcesRequest() - request.ResourceId = &[]string{d.Id()} - request.Tag = &create - request.ResourceType = strings.ToUpper(string(resourceType)) - request.RegionId = s.client.RegionId - raw, err := s.client.WithBastionhostClient(func(client *yundun_bastionhost.Client) (interface{}, error) { - return client.TagResources(request) + if len(added) > 0 { + var response map[string]interface{} + action := "TagResources" + request := map[string]interface{}{ + "RegionId": s.client.RegionId, + "ResourceType": resourceType, + "ResourceId.1": d.Id(), + } + count := 1 + for key, value := range added { + request[fmt.Sprintf("Tag.%d.Key", count)] = key + request[fmt.Sprintf("Tag.%d.Value", count)] = value + count++ + } + + wait := incrementalWait(3*time.Second, 3*time.Second) + err = resource.Retry(5*time.Minute, func() *resource.RetryError { + response, err = client.RpcPost("Yundun-bastionhost", "2019-12-09", action, nil, request, false) + if err != nil { + if NeedRetry(err) { + wait() + return resource.RetryableError(err) + } + return resource.NonRetryableError(err) + } + return nil }) + addDebug(action, response, request) if err != nil { - return WrapErrorf(err, DefaultErrorMsg, d.Id(), request.GetActionName(), AlibabaCloudSdkGoERROR) + return WrapErrorf(err, DefaultErrorMsg, d.Id(), action, AlibabaCloudSdkGoERROR) } - addDebug(request.GetActionName(), raw, request.RpcRequest, request) + return nil } - } return nil } -func (s *YundunBastionhostService) diffTags(oldTags, newTags []yundun_bastionhost.TagResourcesTag) ([]yundun_bastionhost.TagResourcesTag, []yundun_bastionhost.TagResourcesTag) { - // First, we're creating everything we have - create := make(map[string]interface{}) - for _, t := range newTags { - create[t.Key] = t.Value +func (s *YundunBastionhostService) UpdateResourceGroup(resourceId, resourceType, resourceGroupId string) (err error) { + client := s.client + var response map[string]interface{} + action := "MoveResourceGroup" + request := map[string]interface{}{ + "RegionId": client.RegionId, + "ResourceType": resourceType, + "ResourceId": resourceId, + "ResourceGroupId": resourceGroupId, } - // Build the list of what to remove - var remove []yundun_bastionhost.TagResourcesTag - for _, t := range oldTags { - old, ok := create[t.Key] - if !ok || old != t.Value { - // Delete it! - remove = append(remove, t) + wait := incrementalWait(3*time.Second, 3*time.Second) + err = resource.Retry(5*time.Minute, func() *resource.RetryError { + response, err = client.RpcPost("Yundun-bastionhost", "2019-12-09", action, nil, request, false) + if err != nil { + if NeedRetry(err) { + wait() + return resource.RetryableError(err) + } + return resource.NonRetryableError(err) } - } - - return s.tagsFromMap(create), remove -} - -func (s *YundunBastionhostService) tagsFromMap(m map[string]interface{}) []yundun_bastionhost.TagResourcesTag { - result := make([]yundun_bastionhost.TagResourcesTag, 0, len(m)) - for k, v := range m { - result = append(result, yundun_bastionhost.TagResourcesTag{ - Key: k, - Value: v.(string), - }) - } - - return result -} - -func (s *YundunBastionhostService) UpdateResourceGroup(resourceId, resourceGroupId string) error { - request := yundun_bastionhost.CreateMoveResourceGroupRequest() - request.RegionId = s.client.RegionId - request.ResourceId = resourceId - request.ResourceType = BastionhostResourceType - request.ResourceGroupId = resourceGroupId - raw, err := s.client.WithBastionhostClient(func(BastionhostClient *yundun_bastionhost.Client) (interface{}, error) { - return BastionhostClient.MoveResourceGroup(request) + return nil }) + addDebug(action, response, request) if err != nil { - return WrapErrorf(err, DefaultErrorMsg, resourceId, request.GetActionName(), AlibabaCloudSdkGoERROR) + return WrapErrorf(err, DefaultErrorMsg, resourceId, action, AlibabaCloudSdkGoERROR) } - addDebug(request.GetActionName(), raw, request.RpcRequest, request) return nil } func (s *YundunBastionhostService) DescribeBastionhostUserGroup(id string) (object map[string]interface{}, err error) { var response map[string]interface{} - conn, err := s.client.NewBastionhostClient() - if err != nil { - return nil, WrapError(err) - } + client := s.client action := "GetUserGroup" parts, err := ParseResourceId(id, 2) if err != nil { @@ -538,11 +514,9 @@ func (s *YundunBastionhostService) DescribeBastionhostUserGroup(id string) (obje "InstanceId": parts[0], "UserGroupId": parts[1], } - 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("2019-12-09"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("Yundun-bastionhost", "2019-12-09", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -569,10 +543,7 @@ func (s *YundunBastionhostService) DescribeBastionhostUserGroup(id string) (obje func (s *YundunBastionhostService) DescribeBastionhostUser(id string) (object map[string]interface{}, err error) { var response map[string]interface{} - conn, err := s.client.NewBastionhostClient() - if err != nil { - return nil, WrapError(err) - } + client := s.client action := "GetUser" parts, err := ParseResourceId(id, 2) if err != nil { @@ -584,11 +555,9 @@ func (s *YundunBastionhostService) DescribeBastionhostUser(id string) (object ma "InstanceId": parts[0], "UserId": parts[1], } - 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("2019-12-09"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("Yundun-bastionhost", "2019-12-09", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -614,10 +583,7 @@ func (s *YundunBastionhostService) DescribeBastionhostUser(id string) (object ma } func (s *YundunBastionhostService) DescribeBastionhostHostGroup(id string) (object map[string]interface{}, err error) { var response map[string]interface{} - conn, err := s.client.NewBastionhostClient() - if err != nil { - return nil, WrapError(err) - } + client := s.client action := "GetHostGroup" parts, err := ParseResourceId(id, 2) if err != nil { @@ -629,11 +595,9 @@ func (s *YundunBastionhostService) DescribeBastionhostHostGroup(id string) (obje "HostGroupId": parts[1], "InstanceId": parts[0], } - 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("2019-12-09"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("Yundun-bastionhost", "2019-12-09", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -660,10 +624,7 @@ func (s *YundunBastionhostService) DescribeBastionhostHostGroup(id string) (obje func (s *YundunBastionhostService) DescribeBastionhostUserAttachment(id string) (object map[string]interface{}, err error) { var response map[string]interface{} - conn, err := s.client.NewBastionhostClient() - if err != nil { - return nil, WrapError(err) - } + client := s.client action := "ListUsers" parts, err := ParseResourceId(id, 3) if err != nil { @@ -679,11 +640,9 @@ func (s *YundunBastionhostService) DescribeBastionhostUserAttachment(id string) } idExist := false 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("2019-12-09"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("Yundun-bastionhost", "2019-12-09", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -726,10 +685,7 @@ func (s *YundunBastionhostService) DescribeBastionhostUserAttachment(id string) func (s *YundunBastionhostService) DescribeBastionhostHost(id string) (object map[string]interface{}, err error) { var response map[string]interface{} - conn, err := s.client.NewBastionhostClient() - if err != nil { - return nil, WrapError(err) - } + client := s.client action := "GetHost" parts, err := ParseResourceId(id, 2) if err != nil { @@ -741,11 +697,9 @@ func (s *YundunBastionhostService) DescribeBastionhostHost(id string) (object ma "HostId": parts[1], "InstanceId": parts[0], } - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(false) 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("2019-12-09"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("Yundun-bastionhost", "2019-12-09", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -772,10 +726,7 @@ func (s *YundunBastionhostService) DescribeBastionhostHost(id string) (object ma func (s *YundunBastionhostService) DescribeBastionhostHostAccount(id string) (object map[string]interface{}, err error) { var response map[string]interface{} - conn, err := s.client.NewBastionhostClient() - if err != nil { - return nil, WrapError(err) - } + client := s.client action := "GetHostAccount" parts, err := ParseResourceId(id, 2) if err != nil { @@ -787,11 +738,9 @@ func (s *YundunBastionhostService) DescribeBastionhostHostAccount(id string) (ob "HostAccountId": parts[1], "InstanceId": parts[0], } - 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("2019-12-09"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("Yundun-bastionhost", "2019-12-09", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -817,10 +766,7 @@ func (s *YundunBastionhostService) DescribeBastionhostHostAccount(id string) (ob } func (s *YundunBastionhostService) DescribeBastionhostHostAttachment(id string) (object map[string]interface{}, err error) { var response map[string]interface{} - conn, err := s.client.NewBastionhostClient() - if err != nil { - return nil, WrapError(err) - } + client := s.client action := "ListHosts" parts, err := ParseResourceId(id, 3) if err != nil { @@ -836,11 +782,9 @@ func (s *YundunBastionhostService) DescribeBastionhostHostAttachment(id string) } idExist := false 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("2019-12-09"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("Yundun-bastionhost", "2019-12-09", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -882,10 +826,7 @@ func (s *YundunBastionhostService) DescribeBastionhostHostAttachment(id string) } func (s *YundunBastionhostService) DescribeBastionhostHostAccountUserAttachment(id string) (object []interface{}, err error) { var response map[string]interface{} - conn, err := s.client.NewBastionhostClient() - if err != nil { - return nil, WrapError(err) - } + client := s.client action := "ListHostAccountsForUser" parts, err := ParseResourceId(id, 3) if err != nil { @@ -898,11 +839,9 @@ func (s *YundunBastionhostService) DescribeBastionhostHostAccountUserAttachment( "InstanceId": parts[0], "UserId": parts[1], } - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(10*time.Second, func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2019-12-09"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("Yundun-bastionhost", "2019-12-09", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -931,10 +870,7 @@ func (s *YundunBastionhostService) DescribeBastionhostHostAccountUserAttachment( func (s *YundunBastionhostService) DescribeBastionhostHostAccountUserGroupAttachment(id string) (object []interface{}, err error) { var response map[string]interface{} - conn, err := s.client.NewBastionhostClient() - if err != nil { - return nil, WrapError(err) - } + client := s.client action := "ListHostAccountsForUserGroup" parts, err := ParseResourceId(id, 3) if err != nil { @@ -947,11 +883,9 @@ func (s *YundunBastionhostService) DescribeBastionhostHostAccountUserGroupAttach "InstanceId": parts[0], "UserGroupId": parts[1], } - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(10*time.Second, func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2019-12-09"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("Yundun-bastionhost", "2019-12-09", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -980,10 +914,7 @@ func (s *YundunBastionhostService) DescribeBastionhostHostAccountUserGroupAttach func (s *YundunBastionhostService) DescribeBastionhostHostGroupAccountUserAttachment(id string) (object []interface{}, err error) { var response map[string]interface{} - conn, err := s.client.NewBastionhostClient() - if err != nil { - return nil, WrapError(err) - } + client := s.client action := "ListHostGroupAccountNamesForUser" parts, err := ParseResourceId(id, 3) if err != nil { @@ -996,11 +927,9 @@ func (s *YundunBastionhostService) DescribeBastionhostHostGroupAccountUserAttach "InstanceId": parts[0], "UserId": parts[1], } - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(10*time.Second, func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2019-12-09"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("Yundun-bastionhost", "2019-12-09", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -1029,10 +958,7 @@ func (s *YundunBastionhostService) DescribeBastionhostHostGroupAccountUserAttach func (s *YundunBastionhostService) DescribeBastionhostHostGroupAccountUserGroupAttachment(id string) (object []interface{}, err error) { var response map[string]interface{} - conn, err := s.client.NewBastionhostClient() - if err != nil { - return nil, WrapError(err) - } + client := s.client action := "ListHostGroupAccountNamesForUserGroup" parts, err := ParseResourceId(id, 3) if err != nil { @@ -1045,11 +971,9 @@ func (s *YundunBastionhostService) DescribeBastionhostHostGroupAccountUserGroupA "InstanceId": parts[0], "UserGroupId": parts[1], } - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(10*time.Second, func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2019-12-09"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("Yundun-bastionhost", "2019-12-09", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -1078,20 +1002,15 @@ func (s *YundunBastionhostService) DescribeBastionhostHostGroupAccountUserGroupA func (s *YundunBastionhostService) EnableInstancePublicAccess(id string) (err error) { var response map[string]interface{} - conn, err := s.client.NewBastionhostClient() - if err != nil { - return WrapError(err) - } + client := s.client action := "EnableInstancePublicAccess" request := map[string]interface{}{ "RegionId": s.client.RegionId, "InstanceId": 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("2019-12-09"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("Yundun-bastionhost", "2019-12-09", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -1109,20 +1028,15 @@ func (s *YundunBastionhostService) EnableInstancePublicAccess(id string) (err er } func (s *YundunBastionhostService) DisableInstancePublicAccess(id string) (err error) { var response map[string]interface{} - conn, err := s.client.NewBastionhostClient() - if err != nil { - return WrapError(err) - } + client := s.client action := "DisableInstancePublicAccess" request := map[string]interface{}{ "RegionId": s.client.RegionId, "InstanceId": 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("2019-12-09"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("Yundun-bastionhost", "2019-12-09", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -1140,10 +1054,7 @@ func (s *YundunBastionhostService) DisableInstancePublicAccess(id string) (err e } func (s *YundunBastionhostService) DescribeBastionhostHostShareKey(id string) (object map[string]interface{}, err error) { var response map[string]interface{} - conn, err := s.client.NewBastionhostClient() - if err != nil { - return nil, WrapError(err) - } + client := s.client action := "GetHostShareKey" parts, err := ParseResourceId(id, 2) if err != nil { @@ -1154,11 +1065,9 @@ func (s *YundunBastionhostService) DescribeBastionhostHostShareKey(id string) (o "HostShareKeyId": parts[1], "InstanceId": parts[0], } - 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("2019-12-09"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("Yundun-bastionhost", "2019-12-09", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -1181,10 +1090,7 @@ func (s *YundunBastionhostService) DescribeBastionhostHostShareKey(id string) (o } func (s *YundunBastionhostService) GetHostShareKey(id string) (object map[string]interface{}, err error) { var response map[string]interface{} - conn, err := s.client.NewBastionhostClient() - if err != nil { - return nil, WrapError(err) - } + client := s.client action := "GetHostShareKey" parts, err := ParseResourceId(id, 2) if err != nil { @@ -1195,11 +1101,9 @@ func (s *YundunBastionhostService) GetHostShareKey(id string) (object map[string "HostShareKeyId": parts[1], "InstanceId": parts[0], } - 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("2019-12-09"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("Yundun-bastionhost", "2019-12-09", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -1222,10 +1126,7 @@ func (s *YundunBastionhostService) GetHostShareKey(id string) (object map[string } func (s *YundunBastionhostService) DescribeBastionhostHostAccountShareKeyAttachment(id string) (object map[string]interface{}, err error) { var response map[string]interface{} - conn, err := s.client.NewBastionhostClient() - if err != nil { - return nil, WrapError(err) - } + client := s.client action := "ListHostAccountsForHostShareKey" parts, err := ParseResourceId(id, 3) if err != nil { @@ -1241,11 +1142,9 @@ func (s *YundunBastionhostService) DescribeBastionhostHostAccountShareKeyAttachm } idExist := false 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("2019-12-09"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("Yundun-bastionhost", "2019-12-09", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -1285,20 +1184,15 @@ func (s *YundunBastionhostService) DescribeBastionhostHostAccountShareKeyAttachm func (s *YundunBastionhostService) DescribeBastionhostAdAuthServer(id string) (object map[string]interface{}, err error) { var response map[string]interface{} - conn, err := s.client.NewBastionhostClient() - if err != nil { - return nil, WrapError(err) - } + client := s.client action := "GetInstanceADAuthServer" request := map[string]interface{}{ "RegionId": s.client.RegionId, "InstanceId": 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("2019-12-09"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("Yundun-bastionhost", "2019-12-09", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -1322,20 +1216,15 @@ func (s *YundunBastionhostService) DescribeBastionhostAdAuthServer(id string) (o func (s *YundunBastionhostService) DescribeBastionhostLdapAuthServer(id string) (object map[string]interface{}, err error) { var response map[string]interface{} - conn, err := s.client.NewBastionhostClient() - if err != nil { - return nil, WrapError(err) - } + client := s.client action := "GetInstanceLDAPAuthServer" request := map[string]interface{}{ "RegionId": s.client.RegionId, "InstanceId": 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("2019-12-09"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("Yundun-bastionhost", "2019-12-09", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() diff --git a/website/docs/d/bastionhost_instances.html.markdown b/website/docs/d/bastionhost_instances.html.markdown index 16720fdf9bf2..72066538866e 100644 --- a/website/docs/d/bastionhost_instances.html.markdown +++ b/website/docs/d/bastionhost_instances.html.markdown @@ -7,23 +7,23 @@ description: |- Provides a list of cloud Bastionhost instances available to the user. --- -# alicloud\_yundun_bastionhost\_instances +# alicloud_bastionhost_instances -> **NOTE:** From the version 1.132.0, the data source has been renamed to `alicloud_bastionhost_instances`. This data source provides a list of cloud Bastionhost instances in an Alibaba Cloud account according to the specified filters. --> **NOTE:** Available in 1.63.0+ . +-> **NOTE:** Available since v1.63.0. ## Example Usage -``` +```terraform data "alicloud_bastionhost_instances" "instance" { description_regex = "^bastionhost" } output "instance" { - value = "${alicloud_bastionhost_instances.instance.*.id}" + value = data.alicloud_bastionhost_instances.instance.*.id } ``` @@ -32,18 +32,10 @@ output "instance" { The following arguments are supported: * `description_regex` - (Optional) A regex string to filter results by the instance description. -* `ids` - (Optional) Matched instance IDs to filter data source result. +* `ids` - (Optional, ForceNew) Matched instance IDs to filter data source result. * `output_file` - (Optional) File name to persist data source output. * `descriptions` - (Optional) Descriptions to filter data source result. -* `tags` - (Optional, Available in v1.67.0+) A map of tags assigned to the bastionhost instance. It must be in the format: - ``` - data "alicloud_bastionhost_instances" "instance" { - tags = { - tagKey1 = "tagValue1" - } - } - ``` - +* `tags` - (Optional) A map of tags assigned to the bastionhost instance. ## Attributes Reference @@ -57,4 +49,7 @@ The following attributes are exported in addition to the arguments listed above: * `instance_status` - The instance's status. * `public_network_access` - The instance's public network access configuration. * `security_group_ids` - The instance's security group configuration. + * `license_code` - The instance's license code. * `tags` - A map of tags assigned to the bastionhost instance. + * `storage` - The storage of Cloud Bastionhost instance in TB. + * `bandwidth` - The bandwidth of Cloud Bastionhost instance. diff --git a/website/docs/r/bastionhost_instance.html.markdown b/website/docs/r/bastionhost_instance.html.markdown index 7b993cd52336..137a68b930aa 100644 --- a/website/docs/r/bastionhost_instance.html.markdown +++ b/website/docs/r/bastionhost_instance.html.markdown @@ -193,7 +193,7 @@ The ad_auth_server supports the following: * `is_ssl` - (Required) Specifies whether to support SSL. * `mobile_mapping` - (Optional) The field that is used to indicate the mobile phone number of a user on the AD server. * `name_mapping` - (Optional) The field that is used to indicate the name of a user on the AD server. -* `password` - (Required, Sensitive) The password of the account that is used for the AD server. +* `password` - (Optional, Sensitive) The password of the account that is used for the AD server. * `port` - (Required) The port that is used to access the AD server. * `server` - (Required) The address of the AD server. * `standby_server` - (Optional) The address of the secondary AD server. @@ -210,7 +210,7 @@ The ldap_auth_server supports the following: * `login_name_mapping` - (Optional) The field that is used to indicate the logon name of a user on the LDAP server. * `mobile_mapping` - (Optional) The field that is used to indicate the mobile phone number of a user on the LDAP server. * `name_mapping` - (Optional) The field that is used to indicate the name of a user on the LDAP server. -* `password` - (Required, Sensitive) The password of the account that is used for the LDAP server. +* `password` - (Optional, Sensitive) The password of the account that is used for the LDAP server. * `port` - (Required) The port that is used to access the LDAP server. * `server` - (Required) The address of the LDAP server. * `standby_server` - (Optional) The address of the secondary LDAP server.