Deploy Disk Type Vault
Application Scenario
Cloud Backup and Recovery (CBR) is a data protection service provided by Huawei Cloud, offering simple and easy-to-use backup services for both cloud and on-premises resources. When events such as virus intrusion, accidental deletion, or hardware/software failures occur, data can be restored to any backup point. Disk type vault is a type of vault in CBR service, specifically designed for backing up cloud disk (EVS) volumes.
Disk type vault supports complete backup of cloud disk volumes, ensuring that entire disk data can be quickly restored when failures occur. Cloud disk is a scalable virtual block storage service provided by Huawei Cloud, featuring high reliability, high performance, and easy scalability. Through CBR backup service, important disk data security and recoverability can be ensured. This best practice will introduce how to use Terraform to automatically deploy a CBR disk type vault, including creating cloud disk volumes and vaults.
Related Resources/Data Sources
This best practice involves the following main resources and data sources:
Data Sources
Resources
Resource/Data Source Dependencies
data.huaweicloud_availability_zones.test
└── huaweicloud_evs_volume.test
└── huaweicloud_cbr_vault.testOperation Steps
1. Script Preparation
Prepare the TF file (e.g., 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 "Preparation Before Deploying Huawei Cloud Resources" document for configuration introduction.
2. Query Availability Zones Required for Cloud Disk Volume Resource Creation via Data Source
Add the following script to the TF file (e.g., main.tf) to instruct Terraform to perform a data source query, the result of which will be used to create the cloud disk volume:
Parameter Description:
No special parameters, gets all availability zone information in the current region
3. Create Cloud Disk Volume
Add the following script to the TF file (e.g., main.tf) to instruct Terraform to create a cloud disk volume resource:
Parameter Description:
availability_zone: Availability zone, prioritizes input variable, uses the first result from availability zone list query data source if empty
volume_type: Cloud disk volume type, assigned by referencing the input variable volume_type
name: Cloud disk volume name, assigned by referencing the input variable volume_name
size: Cloud disk volume size, assigned by referencing the input variable volume_size
device_type: Cloud disk volume device type, assigned by referencing the input variable volume_device_type
4. Create CBR Vault
Add the following script to the TF file (e.g., main.tf) to instruct Terraform to create a CBR vault resource:
Parameter Description:
name: Vault name, assigned by referencing the input variable name
type: Vault type, assigned by referencing the input variable type, defaults to "disk" for disk type vault
protection_type: Protection type, assigned by referencing the input variable protection_type
size: Vault size, assigned by referencing the input variable size
enterprise_project_id: Enterprise project ID, assigned by referencing the input variable enterprise_project_id
resources.includes: List of included resource IDs, assigned by referencing the cloud disk volume resource (huaweicloud_evs_volume.test) ID
5. Preset Input Parameters Required for Resource Deployment (Optional)
In this practice, some resources and data sources use input variables to assign values to configuration content. These input parameters need to be manually entered during subsequent deployments. 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
terraform.tfvarsfile in the working directory (this file name allows users to automatically import the content of thistfvarsfile when executing terraform commands; for other names,.autoneeds to be added before tfvars, such asvariables.auto.tfvars)Modify parameter values as needed
When executing
terraform planorterraform apply, Terraform will automatically read the variable values from this file
In addition to using terraform.tfvars file, variable values can also be set in the following ways:
Command line parameters:
terraform apply -var="volume_type=SSD" -var="volume_size=50"Environment variables:
export TF_VAR_volume_type=SSDCustom named variable files:
terraform apply -var-file="custom.tfvars"
Note: If the same variable is set in multiple ways, Terraform will use the variable value according to the following priority: command line parameters > variable files > environment variables > default values.
6. 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 the resource plan is correct, run
terraform applyto start creating the CBR disk type vaultRun
terraform showto view the details of the created CBR disk type vault
Reference Information
Last updated