Deploy Permission Rule
Application Scenario
Huawei Cloud Scalable File Service (SFS Turbo) permission rule functionality allows users to configure access control rules for SFS Turbo file systems, defining which IP addresses or network segments can access the file system and the permission levels for access. By configuring permission rules, you can implement secure access control, network isolation, and permission management for file systems.
This best practice is particularly suitable for scenarios that require controlling SFS Turbo file system access permissions, implementing network security isolation, managing multi-user access, such as multi-tenant environments, security-sensitive applications, enterprise file sharing, etc. This best practice will introduce how to use Terraform to automatically deploy SFS Turbo permission rules, including VPC network, security group, SFS Turbo file system, and permission rule creation, implementing a complete file system access control solution.
Related Resources/Data Sources
This best practice involves the following main resources and data sources:
Data Sources
Resources
Resource/Data Source Dependencies
Operation 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 Zone Information
Add the following script to the TF file (e.g., main.tf) to instruct Terraform to query availability zone information:
Parameter Description:
This data source requires no additional parameters and automatically queries all availability zones in the current region
3. Create VPC Network
Add the following script to the TF file to instruct Terraform to create a VPC resource:
Parameter Description:
name: VPC name, assigned by referencing the input variable vpc_name
cidr: VPC CIDR block, assigned by referencing the input variable vpc_cidr, default value is "192.168.0.0/16"
4. Create VPC Subnet
Add the following script to the TF file to instruct Terraform to create a VPC subnet resource:
Parameter Description:
vpc_id: VPC ID that the subnet belongs to, referencing the ID of the previously created VPC resource
name: Subnet name, assigned by referencing the input variable subnet_name
cidr: Subnet CIDR block, automatically calculated if subnet_cidr is empty, otherwise uses subnet_cidr value
gateway_ip: Subnet gateway IP, automatically calculated if subnet_gateway_ip is empty, otherwise uses subnet_gateway_ip value
5. Create Security Group
Add the following script to the TF file to instruct Terraform to create a security group resource:
Parameter Description:
name: Security group name, assigned by referencing the input variable security_group_name
delete_default_rules: Whether to delete default rules, set to true to delete default security group rules
6. Create SFS Turbo File System
Add the following script to the TF file to instruct Terraform to create an SFS Turbo file system resource:
Parameter Description:
vpc_id: VPC ID, referencing the ID of the previously created VPC resource
subnet_id: Subnet ID, referencing the ID of the previously created VPC subnet resource
security_group_id: Security group ID, referencing the ID of the previously created security group resource
availability_zone: Availability zone, prioritizes using turbo_availability_zone variable, uses the first queried availability zone if empty
name: SFS Turbo file system name, assigned by referencing the input variable turbo_name
size: File system capacity, assigned by referencing the input variable turbo_size, default value is 500 (GB)
share_proto: Sharing protocol, assigned by referencing the input variable turbo_share_proto, default value is "NFS"
share_type: Sharing type, assigned by referencing the input variable turbo_share_type, default value is "STANDARD"
hpc_bandwidth: HPC bandwidth specification, assigned by referencing the input variable turbo_hpc_bandwidth, default value is empty string
7. Create SFS Turbo Permission Rules
Add the following script to the TF file to instruct Terraform to create an SFS Turbo permission rule resource:
Parameter Description:
share_id: SFS Turbo file system ID, referencing the ID of the previously created SFS Turbo file system resource
ip_cidr: IP address or network segment of the authorized object, assigned by referencing the input variable rule_ip_cidr, default value is "192.168.0.0/16"
rw_type: Read and write permissions for the authorized object, assigned by referencing the input variable rule_rw_type, default value is "rw" (read-write permissions)
user_type: Access permissions of the system users of the authorized object to the file system, assigned by referencing the input variable rule_user_type, default value is "no_root_squash" (no root user restrictions)
8. 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="vpc_name=my-vpc" -var="turbo_name=my-turbo"Environment variables:
export TF_VAR_vpc_name=my-vpcCustom 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.
9. 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 permission rulesRun
terraform showto view the created permission rule details
Reference Information
Last updated