diff --git a/alicloud/connectivity/endpoint.go b/alicloud/connectivity/endpoint.go index 4c31bbf5ae2d..a968e4b10bac 100644 --- a/alicloud/connectivity/endpoint.go +++ b/alicloud/connectivity/endpoint.go @@ -306,6 +306,7 @@ var productCodeToLocationCode = map[string]string{ "gwlb": "gwlb", // GWLB "esa": "dcdnservices", // ESA "live": "live", // Live + "eds_aic": "wycloudphone", // CloudPhone } // irregularProductEndpoint specially records those product codes that @@ -328,6 +329,7 @@ var irregularProductEndpoint = map[string]string{ "cas": "cas.aliyuncs.com", "sas": "tds.aliyuncs.com", "ros": "ros.aliyuncs.com", + "eds_aic": "eds-aic.cn-shanghai.aliyuncs.com", } // irregularProductEndpointForIntlRegion specially records those product codes that @@ -351,6 +353,7 @@ var irregularProductEndpointForIntlAccount = map[string]string{ "resourcecenter": "resourcecenter-intl.aliyuncs.com", "bssopenapi": BssOpenAPIEndpointInternational, "esa": "esa.ap-southeast-1.aliyuncs.com", + "eds_aic": "eds-aic.ap-southeast-1.aliyuncs.com", "ros": "ros-intl.aliyuncs.com", } diff --git a/alicloud/provider.go b/alicloud/provider.go index a98ea1c0eb73..b60958078e67 100644 --- a/alicloud/provider.go +++ b/alicloud/provider.go @@ -888,6 +888,7 @@ func Provider() terraform.ResourceProvider { "alicloud_vpc_ipam_ipams": dataSourceAliCloudVpcIpamIpams(), }, ResourcesMap: map[string]*schema.Resource{ + "alicloud_cloud_phone_policy": resourceAliCloudCloudPhonePolicy(), "alicloud_message_service_endpoint": resourceAliCloudMessageServiceEndpoint(), "alicloud_esa_rewrite_url_rule": resourceAliCloudEsaRewriteUrlRule(), "alicloud_esa_redirect_rule": resourceAliCloudEsaRedirectRule(), diff --git a/alicloud/resource_alicloud_cloud_phone_policy.go b/alicloud/resource_alicloud_cloud_phone_policy.go new file mode 100644 index 000000000000..b4f62fd7b506 --- /dev/null +++ b/alicloud/resource_alicloud_cloud_phone_policy.go @@ -0,0 +1,391 @@ +// Package alicloud. This file is generated automatically. Please do not modify it manually, thank you! +package alicloud + +import ( + "encoding/json" + "fmt" + "log" + "regexp" + "time" + + "github.com/PaesslerAG/jsonpath" + "github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +func resourceAliCloudCloudPhonePolicy() *schema.Resource { + return &schema.Resource{ + Create: resourceAliCloudCloudPhonePolicyCreate, + Read: resourceAliCloudCloudPhonePolicyRead, + Update: resourceAliCloudCloudPhonePolicyUpdate, + Delete: resourceAliCloudCloudPhonePolicyDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(5 * time.Minute), + Update: schema.DefaultTimeout(5 * time.Minute), + Delete: schema.DefaultTimeout(5 * time.Minute), + }, + Schema: map[string]*schema.Schema{ + "camera_redirect": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: StringInSlice([]string{"on", "off"}, false), + }, + "clipboard": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: StringInSlice([]string{"read", "write", "readwrite", "off"}, false), + }, + "lock_resolution": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: StringInSlice([]string{"on", "off"}, false), + }, + "net_redirect_policy": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "proxy_user_name": { + Type: schema.TypeString, + Optional: true, + }, + "port": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: StringMatch(regexp.MustCompile("^\\d+$"), "Transparent proxy port. The Port value range is 1\\~ 65535."), + }, + "net_redirect": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: StringInSlice([]string{"on", "off"}, false), + }, + "proxy_password": { + Type: schema.TypeString, + Optional: true, + }, + "proxy_type": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: StringInSlice([]string{"socks5"}, false), + }, + "host_addr": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: StringMatch(regexp.MustCompile("^(\\d{0,3}\\.){3}\\d{0,3}$"), "The transparent proxy IP address. The format is IPv4 address."), + }, + "custom_proxy": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: StringInSlice([]string{"on", "off"}, false), + }, + }, + }, + }, + "policy_group_name": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "resolution_height": { + Type: schema.TypeInt, + Optional: true, + ValidateFunc: IntInSlice([]int{0, 640, 720, 940, 1280, 1920}), + }, + "resolution_width": { + Type: schema.TypeInt, + Optional: true, + ValidateFunc: IntInSlice([]int{0, 480, 536, 720, 800, 1080}), + }, + }, + } +} + +func resourceAliCloudCloudPhonePolicyCreate(d *schema.ResourceData, meta interface{}) error { + + client := meta.(*connectivity.AliyunClient) + + action := "CreatePolicyGroup" + var request map[string]interface{} + var response map[string]interface{} + query := make(map[string]interface{}) + var err error + request = make(map[string]interface{}) + + if v, ok := d.GetOkExists("resolution_width"); ok { + request["ResolutionWidth"] = v + } + if v, ok := d.GetOk("policy_group_name"); ok { + request["PolicyGroupName"] = v + } + if v, ok := d.GetOk("clipboard"); ok { + request["Clipboard"] = v + } + objectDataLocalMap := make(map[string]interface{}) + + if v := d.Get("net_redirect_policy"); !IsNil(v) { + hostAddr1, _ := jsonpath.Get("$[0].host_addr", v) + if hostAddr1 != nil && hostAddr1 != "" { + objectDataLocalMap["HostAddr"] = hostAddr1 + } + netRedirect1, _ := jsonpath.Get("$[0].net_redirect", v) + if netRedirect1 != nil && netRedirect1 != "" { + objectDataLocalMap["NetRedirect"] = netRedirect1 + } + proxyPassword1, _ := jsonpath.Get("$[0].proxy_password", v) + if proxyPassword1 != nil && proxyPassword1 != "" { + objectDataLocalMap["ProxyPassword"] = proxyPassword1 + } + proxyUserName1, _ := jsonpath.Get("$[0].proxy_user_name", v) + if proxyUserName1 != nil && proxyUserName1 != "" { + objectDataLocalMap["ProxyUserName"] = proxyUserName1 + } + customProxy1, _ := jsonpath.Get("$[0].custom_proxy", v) + if customProxy1 != nil && customProxy1 != "" { + objectDataLocalMap["CustomProxy"] = customProxy1 + } + port1, _ := jsonpath.Get("$[0].port", v) + if port1 != nil && port1 != "" { + objectDataLocalMap["Port"] = port1 + } + proxyType1, _ := jsonpath.Get("$[0].proxy_type", v) + if proxyType1 != nil && proxyType1 != "" { + objectDataLocalMap["ProxyType"] = proxyType1 + } + + objectDataLocalMapJson, err := json.Marshal(objectDataLocalMap) + if err != nil { + return WrapError(err) + } + request["NetRedirectPolicy"] = string(objectDataLocalMapJson) + } + + if v, ok := d.GetOk("camera_redirect"); ok { + request["CameraRedirect"] = v + } + if v, ok := d.GetOk("lock_resolution"); ok { + request["LockResolution"] = v + } + if v, ok := d.GetOkExists("resolution_height"); ok { + request["ResolutionHeight"] = v + } + wait := incrementalWait(3*time.Second, 5*time.Second) + err = resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError { + response, err = client.RpcPost("eds-aic", "2023-09-30", action, query, request, true) + 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, "alicloud_cloud_phone_policy", action, AlibabaCloudSdkGoERROR) + } + + d.SetId(fmt.Sprint(response["PolicyGroupId"])) + + return resourceAliCloudCloudPhonePolicyRead(d, meta) +} + +func resourceAliCloudCloudPhonePolicyRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*connectivity.AliyunClient) + cloudPhoneServiceV2 := CloudPhoneServiceV2{client} + + objectRaw, err := cloudPhoneServiceV2.DescribeCloudPhonePolicy(d.Id()) + if err != nil { + if !d.IsNewResource() && NotFoundError(err) { + log.Printf("[DEBUG] Resource alicloud_cloud_phone_policy DescribeCloudPhonePolicy Failed!!! %s", err) + d.SetId("") + return nil + } + return WrapError(err) + } + + d.Set("camera_redirect", objectRaw["CameraRedirect"]) + d.Set("clipboard", objectRaw["Clipboard"]) + d.Set("lock_resolution", objectRaw["LockResolution"]) + d.Set("policy_group_name", objectRaw["PolicyGroupName"]) + d.Set("resolution_height", objectRaw["SessionResolutionHeight"]) + d.Set("resolution_width", objectRaw["SessionResolutionWidth"]) + + netRedirectPolicyMaps := make([]map[string]interface{}, 0) + netRedirectPolicyMap := make(map[string]interface{}) + netRedirectPolicyRaw := make(map[string]interface{}) + if objectRaw["NetRedirectPolicy"] != nil { + netRedirectPolicyRaw = objectRaw["NetRedirectPolicy"].(map[string]interface{}) + } + if len(netRedirectPolicyRaw) > 0 { + netRedirectPolicyMap["custom_proxy"] = netRedirectPolicyRaw["CustomProxy"] + netRedirectPolicyMap["host_addr"] = netRedirectPolicyRaw["HostAddr"] + netRedirectPolicyMap["net_redirect"] = netRedirectPolicyRaw["NetRedirect"] + netRedirectPolicyMap["port"] = netRedirectPolicyRaw["Port"] + netRedirectPolicyMap["proxy_password"] = netRedirectPolicyRaw["ProxyPassword"] + netRedirectPolicyMap["proxy_type"] = netRedirectPolicyRaw["ProxyType"] + netRedirectPolicyMap["proxy_user_name"] = netRedirectPolicyRaw["ProxyUserName"] + + netRedirectPolicyMaps = append(netRedirectPolicyMaps, netRedirectPolicyMap) + } + if err := d.Set("net_redirect_policy", netRedirectPolicyMaps); err != nil { + return err + } + + return nil +} + +func resourceAliCloudCloudPhonePolicyUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*connectivity.AliyunClient) + var request map[string]interface{} + var response map[string]interface{} + var query map[string]interface{} + update := false + + var err error + action := "ModifyPolicyGroup" + request = make(map[string]interface{}) + query = make(map[string]interface{}) + request["PolicyGroupId"] = d.Id() + + if d.HasChange("resolution_width") { + update = true + } + if v, ok := d.GetOk("resolution_width"); ok || d.HasChange("resolution_width") { + request["ResolutionWidth"] = v + } + if d.HasChange("policy_group_name") { + update = true + } + if v, ok := d.GetOk("policy_group_name"); ok || d.HasChange("policy_group_name") { + request["PolicyGroupName"] = v + } + if d.HasChange("clipboard") { + update = true + } + if v, ok := d.GetOk("clipboard"); ok || d.HasChange("clipboard") { + request["Clipboard"] = v + } + if d.HasChange("net_redirect_policy") { + update = true + } + objectDataLocalMap := make(map[string]interface{}) + + if v := d.Get("net_redirect_policy"); v != nil { + hostAddr1, _ := jsonpath.Get("$[0].host_addr", v) + if hostAddr1 != nil && (d.HasChange("net_redirect_policy.0.host_addr") || hostAddr1 != "") { + objectDataLocalMap["HostAddr"] = hostAddr1 + } + netRedirect1, _ := jsonpath.Get("$[0].net_redirect", v) + if netRedirect1 != nil && (d.HasChange("net_redirect_policy.0.net_redirect") || netRedirect1 != "") { + objectDataLocalMap["NetRedirect"] = netRedirect1 + } + proxyPassword1, _ := jsonpath.Get("$[0].proxy_password", v) + if proxyPassword1 != nil && (d.HasChange("net_redirect_policy.0.proxy_password") || proxyPassword1 != "") { + objectDataLocalMap["ProxyPassword"] = proxyPassword1 + } + proxyUserName1, _ := jsonpath.Get("$[0].proxy_user_name", v) + if proxyUserName1 != nil && (d.HasChange("net_redirect_policy.0.proxy_user_name") || proxyUserName1 != "") { + objectDataLocalMap["ProxyUserName"] = proxyUserName1 + } + customProxy1, _ := jsonpath.Get("$[0].custom_proxy", v) + if customProxy1 != nil && (d.HasChange("net_redirect_policy.0.custom_proxy") || customProxy1 != "") { + objectDataLocalMap["CustomProxy"] = customProxy1 + } + port1, _ := jsonpath.Get("$[0].port", v) + if port1 != nil && (d.HasChange("net_redirect_policy.0.port") || port1 != "") { + objectDataLocalMap["Port"] = port1 + } + proxyType1, _ := jsonpath.Get("$[0].proxy_type", v) + if proxyType1 != nil && (d.HasChange("net_redirect_policy.0.proxy_type") || proxyType1 != "") { + objectDataLocalMap["ProxyType"] = proxyType1 + } + + objectDataLocalMapJson, err := json.Marshal(objectDataLocalMap) + if err != nil { + return WrapError(err) + } + request["NetRedirectPolicy"] = string(objectDataLocalMapJson) + } + + if d.HasChange("camera_redirect") { + update = true + } + if v, ok := d.GetOk("camera_redirect"); ok || d.HasChange("camera_redirect") { + request["CameraRedirect"] = v + } + if d.HasChange("lock_resolution") { + update = true + } + if v, ok := d.GetOk("lock_resolution"); ok || d.HasChange("lock_resolution") { + request["LockResolution"] = v + } + if d.HasChange("resolution_height") { + update = true + } + if v, ok := d.GetOk("resolution_height"); ok || d.HasChange("resolution_height") { + request["ResolutionHeight"] = v + } + if update { + wait := incrementalWait(3*time.Second, 5*time.Second) + err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { + response, err = client.RpcPost("eds-aic", "2023-09-30", action, query, request, true) + 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(), action, AlibabaCloudSdkGoERROR) + } + } + + return resourceAliCloudCloudPhonePolicyRead(d, meta) +} + +func resourceAliCloudCloudPhonePolicyDelete(d *schema.ResourceData, meta interface{}) error { + + client := meta.(*connectivity.AliyunClient) + action := "DeletePolicyGroup" + var request map[string]interface{} + var response map[string]interface{} + query := make(map[string]interface{}) + var err error + request = make(map[string]interface{}) + request["PolicyGroupIds.1"] = d.Id() + + wait := incrementalWait(3*time.Second, 5*time.Second) + err = resource.Retry(d.Timeout(schema.TimeoutDelete), func() *resource.RetryError { + response, err = client.RpcPost("eds-aic", "2023-09-30", action, query, request, true) + + if err != nil { + if NeedRetry(err) { + wait() + return resource.RetryableError(err) + } + return resource.NonRetryableError(err) + } + return nil + }) + addDebug(action, response, request) + + if err != nil { + if NotFoundError(err) { + return nil + } + return WrapErrorf(err, DefaultErrorMsg, d.Id(), action, AlibabaCloudSdkGoERROR) + } + + return nil +} diff --git a/alicloud/resource_alicloud_cloud_phone_policy_test.go b/alicloud/resource_alicloud_cloud_phone_policy_test.go new file mode 100644 index 000000000000..ba04b4b4c210 --- /dev/null +++ b/alicloud/resource_alicloud_cloud_phone_policy_test.go @@ -0,0 +1,194 @@ +package alicloud + +import ( + "fmt" + "testing" + + "github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity" + "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" +) + +// Test CloudPhone Policy. >>> Resource test cases, automatically generated. +// Case chuyuan_createPolicy_prod_all 10062 +func TestAccAliCloudCloudPhonePolicy_basic10062(t *testing.T) { + var v map[string]interface{} + resourceId := "alicloud_cloud_phone_policy.default" + ra := resourceAttrInit(resourceId, AlicloudCloudPhonePolicyMap10062) + rc := resourceCheckInitWithDescribeMethod(resourceId, &v, func() interface{} { + return &CloudPhoneServiceV2{testAccProvider.Meta().(*connectivity.AliyunClient)} + }, "DescribeCloudPhonePolicy") + rac := resourceAttrCheckInit(rc, ra) + testAccCheck := rac.resourceAttrMapUpdateSet() + rand := acctest.RandIntRange(10000, 99999) + name := fmt.Sprintf("tf-testacc%scloudphonepolicy%d", defaultRegionToTest, rand) + testAccConfig := resourceTestAccConfigFunc(resourceId, name, AlicloudCloudPhonePolicyBasicDependence10062) + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + }, + IDRefreshName: resourceId, + Providers: testAccProviders, + CheckDestroy: rac.checkResourceDestroy(), + Steps: []resource.TestStep{ + { + Config: testAccConfig(map[string]interface{}{ + "policy_group_name": "NewPolicyName", + "resolution_width": "720", + "lock_resolution": "on", + "camera_redirect": "on", + "resolution_height": "1280", + "clipboard": "read", + "net_redirect_policy": []map[string]interface{}{ + { + "net_redirect": "on", + "custom_proxy": "on", + "proxy_type": "socks5", + "host_addr": "192.168.12.13", + "port": "8888", + "proxy_user_name": "user1", + "proxy_password": "123456", + }, + }, + }), + Check: resource.ComposeTestCheckFunc( + testAccCheck(map[string]string{ + "policy_group_name": "NewPolicyName", + "resolution_width": "720", + "lock_resolution": "on", + "camera_redirect": "on", + "resolution_height": "1280", + "clipboard": "read", + }), + ), + }, + { + Config: testAccConfig(map[string]interface{}{ + "policy_group_name": "ModifyPolicyName", + "resolution_width": "1080", + "resolution_height": "1920", + "clipboard": "write", + "net_redirect_policy": []map[string]interface{}{ + { + "net_redirect": "on", + "custom_proxy": "on", + "proxy_type": "socks5", + "host_addr": "192.168.16.13", + "port": "9999", + "proxy_user_name": "user2", + "proxy_password": "1234567", + }, + }, + }), + Check: resource.ComposeTestCheckFunc( + testAccCheck(map[string]string{ + "policy_group_name": "ModifyPolicyName", + "resolution_width": "1080", + "resolution_height": "1920", + "clipboard": "write", + }), + ), + }, + { + Config: testAccConfig(map[string]interface{}{ + "policy_group_name": "defaultPolicyGroup", + "resolution_width": "720", + "lock_resolution": "off", + "camera_redirect": "off", + "resolution_height": "1280", + "clipboard": "read", + "net_redirect_policy": []map[string]interface{}{ + { + "net_redirect": "off", + "custom_proxy": "off", + }, + }, + }), + Check: resource.ComposeTestCheckFunc( + testAccCheck(map[string]string{ + "policy_group_name": "defaultPolicyGroup", + "resolution_width": "720", + "lock_resolution": "off", + "camera_redirect": "off", + "resolution_height": "1280", + "clipboard": "read", + }), + ), + }, + { + Config: testAccConfig(map[string]interface{}{ + "resolution_width": "1080", + "lock_resolution": "on", + "camera_redirect": "on", + "resolution_height": "1920", + "clipboard": "write", + "net_redirect_policy": []map[string]interface{}{ + { + "net_redirect": "on", + "custom_proxy": "on", + "proxy_type": "socks5", + "host_addr": "195.2.3.2", + "port": "1234", + "proxy_user_name": "user2", + "proxy_password": "1234567", + }, + }, + }), + Check: resource.ComposeTestCheckFunc( + testAccCheck(map[string]string{ + "resolution_width": "1080", + "lock_resolution": "on", + "camera_redirect": "on", + "resolution_height": "1920", + "clipboard": "write", + }), + ), + }, + { + Config: testAccConfig(map[string]interface{}{ + "resolution_width": "720", + "resolution_height": "1280", + "clipboard": "readwrite", + "net_redirect_policy": []map[string]interface{}{ + { + "net_redirect": "on", + "custom_proxy": "on", + "proxy_type": "socks5", + "host_addr": "123.0.0.1", + "port": "8084", + "proxy_user_name": "user7", + "proxy_password": "1234567", + }, + }, + }), + Check: resource.ComposeTestCheckFunc( + testAccCheck(map[string]string{ + "resolution_width": "720", + "resolution_height": "1280", + "clipboard": "readwrite", + }), + ), + }, + { + ResourceName: resourceId, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{}, + }, + }, + }) +} + +var AlicloudCloudPhonePolicyMap10062 = map[string]string{} + +func AlicloudCloudPhonePolicyBasicDependence10062(name string) string { + return fmt.Sprintf(` +variable "name" { + default = "%s" +} + + +`, name) +} + +// Test CloudPhone Policy. <<< Resource test cases, automatically generated. diff --git a/alicloud/service_alicloud_cloud_phone_v2.go b/alicloud/service_alicloud_cloud_phone_v2.go new file mode 100644 index 000000000000..72c1f673fd5a --- /dev/null +++ b/alicloud/service_alicloud_cloud_phone_v2.go @@ -0,0 +1,92 @@ +package alicloud + +import ( + "fmt" + "strings" + "time" + + "github.com/PaesslerAG/jsonpath" + "github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" +) + +type CloudPhoneServiceV2 struct { + client *connectivity.AliyunClient +} + +// DescribeCloudPhonePolicy <<< Encapsulated get interface for CloudPhone Policy. + +func (s *CloudPhoneServiceV2) DescribeCloudPhonePolicy(id string) (object map[string]interface{}, err error) { + client := s.client + var request map[string]interface{} + var response map[string]interface{} + var query map[string]interface{} + request = make(map[string]interface{}) + query = make(map[string]interface{}) + request["PolicyGroupIds.1"] = id + + action := "ListPolicyGroups" + + wait := incrementalWait(3*time.Second, 5*time.Second) + err = resource.Retry(1*time.Minute, func() *resource.RetryError { + response, err = client.RpcPost("eds-aic", "2023-09-30", action, query, request, true) + + if err != nil { + if NeedRetry(err) { + wait() + return resource.RetryableError(err) + } + return resource.NonRetryableError(err) + } + return nil + }) + addDebug(action, response, request) + if err != nil { + return object, WrapErrorf(err, DefaultErrorMsg, id, action, AlibabaCloudSdkGoERROR) + } + + v, err := jsonpath.Get("$.PolicyGroupModel[*]", response) + if err != nil { + return object, WrapErrorf(err, FailedGetAttributeMsg, id, "$.PolicyGroupModel[*]", response) + } + + if len(v.([]interface{})) == 0 { + return object, WrapErrorf(Error(GetNotFoundMessage("Policy", id)), NotFoundMsg, response) + } + + return v.([]interface{})[0].(map[string]interface{}), nil +} + +func (s *CloudPhoneServiceV2) CloudPhonePolicyStateRefreshFunc(id string, field string, failStates []string) resource.StateRefreshFunc { + return func() (interface{}, string, error) { + object, err := s.DescribeCloudPhonePolicy(id) + if err != nil { + if NotFoundError(err) { + return object, "", nil + } + return nil, "", WrapError(err) + } + + v, err := jsonpath.Get(field, object) + currentStatus := fmt.Sprint(v) + + if strings.HasPrefix(field, "#") { + v, _ := jsonpath.Get(strings.TrimPrefix(field, "#"), object) + if v != nil { + currentStatus = "#CHECKSET" + } + } + + for _, failState := range failStates { + if currentStatus == failState { + return object, currentStatus, WrapError(Error(FailedToReachTargetStatus, currentStatus)) + } + } + return object, currentStatus, nil + } +} + +// DescribeCloudPhonePolicy >>> Encapsulated. + +// Async Api <<< Encapsulated for CloudPhone. +// Async Api >>> Encapsulated. diff --git a/website/docs/r/cloud_phone_policy.html.markdown b/website/docs/r/cloud_phone_policy.html.markdown new file mode 100644 index 000000000000..efac05c0ae22 --- /dev/null +++ b/website/docs/r/cloud_phone_policy.html.markdown @@ -0,0 +1,92 @@ +--- +subcategory: "Cloud Phone" +layout: "alicloud" +page_title: "Alicloud: alicloud_cloud_phone_policy" +description: |- + Provides a Alicloud Cloud Phone Policy resource. +--- + +# alicloud_cloud_phone_policy + +Provides a Cloud Phone Policy resource. + +Cloud phone policy. + +For information about Cloud Phone Policy and how to use it, see [What is Policy](https://next.api.alibabacloud.com/document/eds-aic/2023-09-30/CreatePolicyGroup). + +-> **NOTE:** Available since v1.243.0. + +## Example Usage + +Basic Usage + +```terraform +variable "name" { + default = "terraform-example" +} + +provider "alicloud" { + region = "cn-hangzhou" +} + + +resource "alicloud_cloud_phone_policy" "default" { + policy_group_name = "NewPolicyName" + resolution_width = "720" + lock_resolution = "on" + camera_redirect = "on" + resolution_height = "1280" + clipboard = "read" + net_redirect_policy { + net_redirect = "on" + custom_proxy = "on" + proxy_type = "socks5" + host_addr = "192.168.12.13" + port = "8888" + proxy_user_name = "user1" + proxy_password = "123456" + } +} +``` + +## Argument Reference + +The following arguments are supported: +* `camera_redirect` - (Optional) Whether to turn on local camera redirection. +* `clipboard` - (Optional) Clipboard permissions. +* `lock_resolution` - (Optional) Whether to lock the resolution. +* `net_redirect_policy` - (Optional, List) Network redirection. See [`net_redirect_policy`](#net_redirect_policy) below. +* `policy_group_name` - (Optional, Computed) The policy name. +* `resolution_height` - (Optional, Int) The height of the resolution. Unit: Pixels. +* `resolution_width` - (Optional, Int) The width of the resolution. Unit: Pixels. + +### `net_redirect_policy` + +The net_redirect_policy supports the following: +* `custom_proxy` - (Optional) Whether to manually configure the transparent proxy. +* `host_addr` - (Optional) The transparent proxy IP address. The format is IPv4 address. +* `net_redirect` - (Optional) Whether to enable network redirection. +* `port` - (Optional) Transparent proxy port. The Port value range is 1\~ 65535. +* `proxy_password` - (Optional) The proxy password. The length range is 1\~ 256. Chinese characters and white space characters are not allowed. +* `proxy_type` - (Optional) Agent protocol type. +* `proxy_user_name` - (Optional) The proxy user name. The length range is 1\~ 256. Chinese characters and white space characters are not allowed. + +## Attributes Reference + +The following attributes are exported: +* `id` - The ID of the resource supplied above. + +## Timeouts + +The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration-0-11/resources.html#timeouts) for certain actions: +* `create` - (Defaults to 5 mins) Used when create the Policy. +* `delete` - (Defaults to 5 mins) Used when delete the Policy. +* `update` - (Defaults to 5 mins) Used when update the Policy. + +## Import + +Cloud Phone Policy can be imported using the id, e.g. + +```shell +$ terraform import alicloud_cloud_phone_policy.example +``` \ No newline at end of file