Deploy OBS Target Configuration

Application Scenario

Huawei Cloud Scalable File Service (SFS Turbo) OBS target configuration functionality allows users to automatically export data from SFS Turbo file systems to OBS object storage, implementing data backup, archiving, and long-term storage. By configuring OBS targets, you can achieve automated management of file system data, cost optimization, and data flow across storage services.

This best practice is particularly suitable for scenarios that require backing up SFS Turbo data to OBS, implementing data archiving, building hybrid storage architectures, such as HPC data processing, machine learning model storage, big data analysis result preservation, etc. This best practice will introduce how to use Terraform to automatically deploy SFS Turbo OBS target configuration, including VPC network, security group, OBS storage bucket, SFS Turbo file system, and OBS target configuration creation, implementing a complete file storage and object storage integration solution.

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 OBS Storage Bucket

Add the following script to the TF file to instruct Terraform to create an OBS storage bucket resource:

Parameter Description:

  • bucket: OBS storage bucket name, assigned by referencing the input variable target_bucket_name

  • acl: Bucket ACL policy, set to "private" for private access

  • force_destroy: Whether to force delete the bucket, set to true to allow deletion of non-empty buckets

7. 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, using the first queried availability zone

  • name: SFS Turbo file system name, assigned by referencing the input variable turbo_name, default value is empty string

  • size: File system capacity, assigned by referencing the input variable turbo_size, default value is 1228 (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 "HPC"

  • hpc_bandwidth: HPC bandwidth specification, assigned by referencing the input variable turbo_hpc_bandwidth, default value is "40M"

8. Create SFS Turbo OBS Target Configuration

Add the following script to the TF file to instruct Terraform to create an SFS Turbo OBS target resource:

Parameter Description:

  • share_id: SFS Turbo file system ID, referencing the ID of the previously created SFS Turbo file system resource

  • file_system_path: OBS target linkage directory name, assigned by referencing the input variable target_file_path, default value is "testDir"

  • obs: OBS configuration block

    • bucket: OBS storage bucket ID, referencing the ID of the previously created OBS storage bucket resource

    • endpoint: Domain name of the region where the OBS bucket is located, assigned by referencing the input variable target_obs_endpoint, default value is "obs.cn-north-4.myhuaweicloud.com"

    • policy: Policy configuration block

      • auto_export_policy: Auto-export policy configuration block

        • events: Type of data automatically exported to OBS bucket, assigned by referencing the input variable target_events, default value is empty list

        • prefix: Prefix to be matched in the storage backend, assigned by referencing the input variable target_prefix, default value is empty string

        • suffix: Suffix to be matched in the storage backend, assigned by referencing the input variable target_suffix, default value is empty string

    • attributes: Attributes configuration block

      • file_mode: Permissions on the imported file, assigned by referencing the input variable target_file_mode, default value is empty string

      • dir_mode: Permissions on the imported directory, assigned by referencing the input variable target_dir_mode, default value is empty string

      • uid: ID of the user who owns the imported object, assigned by referencing the input variable target_uid, default value is 0

      • gid: ID of the user group to which the imported object belongs, assigned by referencing the input variable target_gid, default value is 0

9. 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:

  1. Save the above content as terraform.tfvars file in the working directory (this file name allows users to automatically import the content of this tfvars file when executing terraform commands; for other names, .auto needs to be added before tfvars, such as variables.auto.tfvars)

  2. Modify parameter values as needed

  3. When executing terraform plan or terraform 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:

  1. Command line parameters: terraform apply -var="vpc_name=my-vpc" -var="turbo_name=my-turbo"

  2. Environment variables: export TF_VAR_vpc_name=my-vpc

  3. Custom 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.

10. Initialize and Apply Terraform Configuration

After completing the above script configuration, execute the following steps to create resources:

  1. Run terraform init to initialize the environment

  2. Run terraform plan to view the resource creation plan

  3. After confirming the resource plan is correct, run terraform apply to start creating OBS target configuration

  4. Run terraform show to view the created OBS target configuration details

Reference Information

Last updated