# Attach a volume to a BMS instance

This example provides best practice code for using Terraform to attach a volume to a BMS instance in HuaweiCloud.
Destroying this resource will detach the volume from the BMS instance.

## Prerequisites

- A HuaweiCloud account
- Terraform installed
- HuaweiCloud access key and secret key (AK/SK)

## Variable Introduction

The following variables need to be configured:

### Authentication Variables

- `region_name` - The region where the resources are located
- `access_key`  - The access key of the IAM user
- `secret_key`  - The secret key of the IAM user

### Resource Variables

#### Required Variables

- `server_id` - The BMS instance ID
- `volume_id` - The ID of the disk to be attached to a BMS instance

#### Optional Variables

- `device` - The mount point, such as **/dev/sda** and **/dev/sdb** (default: null)

## Usage

- Copy this example script to your `main.tf`.

- Create a `terraform.tfvars` file and fill in the required variables:

  ```hcl
  server_id = "your_bms_server_id"
  volume_id = "your_evs_volume_id"
  ```

- Initialize Terraform:

  ```bash
  $ terraform init
  ```

- Review the Terraform plan:

  ```bash
  $ terraform plan
  ```

- Apply the configuration:

  ```bash
  $ terraform apply
  ```

- To clean up the resources:

  ```bash
  $ terraform destroy
  ```

## Note

- Make sure to keep your credentials secure and never commit them to version control
- All resources will be created in the specified region

## Requirements

| Name | Version   |
| ---- |-----------|
| terraform | >= 0.14.0 |
| huaweicloud | >= 1.82.4 |
