Deploy Cloud Application Policy Group
Application Scenario
Huawei Cloud Cloud Desktop (Workspace) is a cloud computing-based desktop virtualization service that provides enterprise users with secure and convenient cloud office solutions. Cloud application policy groups are an important component of the Workspace service's cloud application functionality, used to configure unified management policies for cloud application groups, including client behavior control, session management, security policies, etc.
Through cloud application policy groups, enterprises can achieve fine-grained management and security control of cloud applications, including policy configurations such as automatic reconnection interval, session persistence time, and screen capture prohibition. Policy groups support priority-based application and can set different policies for different application groups or all application groups, meeting diverse enterprise management needs. This best practice will introduce how to use Terraform to automatically deploy Workspace cloud application policy groups, including cloud application server group creation, cloud application group creation, and policy group configuration.
Related Resources/Data Sources
This best practice involves the following main resources and data sources:
Data Sources
Resources
Resource/Data Source Dependencies
data.huaweicloud_workspace_service.test
└── huaweicloud_workspace_app_server_group.test
└── huaweicloud_workspace_app_group.test
└── huaweicloud_workspace_app_policy_group.testImplementation Steps
1. Script Preparation
Prepare the TF file (such as main.tf) in the specified workspace for writing the current best practice script, ensuring that it (or other TF files in the same directory) contains the provider version declaration and Huawei Cloud authentication information required for deploying resources. Refer to the introduction in Preparation Before Deploying Huawei Cloud Resources for configuration introduction.
2. Query Workspace Service Information Through Data Source
Add the following script to the TF file (such as main.tf) to instruct Terraform to perform a data source query, the query results are used to create cloud application server groups:
Parameter Description:
This data source requires no additional parameters and automatically queries Workspace service information in the current region
3. Create Workspace Cloud Application Server Group
Add the following script to the TF file (such as main.tf) to instruct Terraform to create cloud application server group resources:
Parameter Description:
name: Cloud application server group name, assigned by referencing the input variable
app_server_group_nameapp_type: Application type, assigned by referencing the input variable
app_server_group_app_type, default is "SESSION_DESKTOP_APP"os_type: Operating system type, assigned by referencing the input variable
app_server_group_os_type, default is "Windows"flavor_id: Flavor ID, assigned by referencing the input variable
app_server_group_flavor_idimage_type: Image type, fixed as "gold" (golden image)
image_id: Image ID, assigned by referencing the input variable
app_server_group_image_idimage_product_id: Image product ID, assigned by referencing the input variable
app_server_group_image_product_idvpc_id: VPC ID, assigned based on the return results of the Workspace service query data source (data.huaweicloud_workspace_service)
subnet_id: Subnet ID, assigned based on the return results of the Workspace service query data source (data.huaweicloud_workspace_service)
system_disk_type: System disk type, assigned by referencing the input variable
app_server_group_system_disk_type, default is "SAS"system_disk_size: System disk size, assigned by referencing the input variable
app_server_group_system_disk_size, default is 80GBis_vdi: Whether it is VDI mode, fixed as true
4. Create Workspace Cloud Application Group
Add the following script to the TF file to instruct Terraform to create cloud application group resources:
Parameter Description:
depends_on: Explicit dependency declaration, ensuring that the cloud application server group is created before creating the cloud application group
server_group_id: The ID of the cloud application server group, referencing the ID of the cloud application server group resource created earlier
name: Cloud application group name, assigned by referencing the input variable
app_group_nametype: Cloud application group type, fixed as "SESSION_DESKTOP_APP" indicating a session desktop application group
description: Cloud application group description, fixed as "Created APP group by Terraform"
5. Create Workspace Cloud Application Policy Group
Add the following script to the TF file to instruct Terraform to create cloud application policy group resources:
Parameter Description:
depends_on: Explicit dependency declaration, ensuring that the cloud application group is created before creating the policy group
name: Policy group name, assigned by referencing the input variable
policy_group_namepriority: Policy group priority, assigned by referencing the input variable
policy_group_priority, default is 1, smaller values indicate higher prioritydescription: Policy group description, assigned by referencing the input variable
policy_group_description, default is "Created APP policy group by Terraform"targets: Policy group target configuration block
id: Target ID, if target type is "APPGROUP" then use the cloud application group ID, otherwise use "default-apply-all-targets" to indicate applying to all targets
name: Target name, if target type is "APPGROUP" then use the cloud application group name, otherwise use "All-Targets"
type: Target type, assigned by referencing the input variable
target_type, default is "APPGROUP" indicating applying to specified application group, "ALL" indicating applying to all targets
policies: Policy configuration, using jsonencode function to encode policy configuration as JSON string
client.automatic_reconnection_interval: Client automatic reconnection interval (minutes), assigned by referencing the input variable
automatic_reconnection_interval, default is 10 minutesclient.session_persistence_time: Session persistence time (minutes), assigned by referencing the input variable
session_persistence_time, default is 120 minutesclient.forbid_screen_capture: Whether to forbid screen capture, assigned by referencing the input variable
forbid_screen_capture, default is true
Note: Policy groups support priority-based application. When multiple policy groups are applied to the same target, policy groups with higher priority will override those with lower priority. Policy configuration uses JSON format and can be converted from HCL objects to JSON strings using the jsonencode function.
6. Preset Input Parameters Required for Resource Deployment (Optional)
In this practice, some resources and data sources use input variables to assign configuration content. These input parameters need to be manually entered during subsequent deployment. At the same time, Terraform provides a method to preset these configurations through tfvars files, which can avoid repeated input during each execution.
Create a terraform.tfvars file in the working directory with the following example content:
Usage:
Save the above content as a
terraform.tfvarsfile in the working directory (this filename allows users to automatically import the content of thistfvarsfile when executing terraform commands. For other names, you need to add.autobefore tfvars, such asvariables.auto.tfvars)Modify parameter values according to actual needs
When executing
terraform planorterraform apply, Terraform will automatically read the variable values in this file
In addition to using the terraform.tfvars file, you can also set variable values through the following methods:
Command line parameters:
terraform apply -var="app_server_group_name=my-server-group" -var="app_group_name=my-app-group"Environment variables:
export TF_VAR_app_server_group_name=my-server-groupCustom named variable file:
terraform apply -var-file="custom.tfvars"
Note: If the same variable is set through multiple methods, Terraform will use variable values according to the following priority: command line parameters > variable file > environment variables > default values.
7. Initialize and Apply Terraform Configuration
After completing the above script configuration, execute the following steps to create resources:
Run
terraform initto initialize the environmentRun
terraform planto view the resource creation planAfter confirming that the resource plan is correct, run
terraform applyto start creating cloud application server groups, cloud application groups, and cloud application policy groupsRun
terraform showto view the created cloud application policy group details
Reference Information
Last updated