|
| 1 | +# Attach, format, and mount a Block Storage Volume to an Instance |
| 2 | + |
| 3 | +This provides a template for attaching, formating, and mounting a Block Storage Volume to an Instance. |
| 4 | + |
| 5 | +## Usage |
| 6 | + |
| 7 | +Download and install [Terraform](https://www.terraform.io/downloads.html): |
| 8 | + |
| 9 | +```sh |
| 10 | +wget -P /tmp/ https://releases.hashicorp.com/terraform/0.12.9/terraform_0.12.9_linux_amd64.zip |
| 11 | +unzip /tmp/terraform_0.12.9_linux_amd64.zip |
| 12 | +sudo mv terraform /usr/local/bin/ |
| 13 | +terraform --version |
| 14 | +``` |
| 15 | + |
| 16 | +Log in to the OpenStack dashboard, choose the project for which you want to download the OpenStack RC file, and run the following commands: |
| 17 | + |
| 18 | +```sh |
| 19 | +source ~/Downloads/PROJECT-openrc.sh |
| 20 | +Please enter your OpenStack Password for project PROJECT as user username: |
| 21 | +``` |
| 22 | + |
| 23 | +### Initialize providers |
| 24 | + |
| 25 | +```sh |
| 26 | +terraform init |
| 27 | +``` |
| 28 | + |
| 29 | +### Generate an execution plan |
| 30 | + |
| 31 | +```sh |
| 32 | +terraform plan |
| 33 | +# or with specific variables |
| 34 | +terraform plan -var 'pool=gateway' \ |
| 35 | + -var 'flavor=m02.c02.d20' \ |
| 36 | + -var 'volume_size=3' \ |
| 37 | + -var 'network_name=my-network' \ |
| 38 | + -var 'ssh_key_file=./id_rsa_os' |
| 39 | +``` |
| 40 | + |
| 41 | +### Apply the plan |
| 42 | + |
| 43 | +```sh |
| 44 | +terraform apply -auto-approve |
| 45 | +# or with specific variables |
| 46 | +terraform apply -auto-approve \ |
| 47 | + -var 'pool=gateway' \ |
| 48 | + -var 'flavor=m02.c02.d20' \ |
| 49 | + -var 'volume_size=3' \ |
| 50 | + -var 'network_name=my-network' \ |
| 51 | + -var 'ssh_key_file=./id_rsa_os' |
| 52 | +``` |
| 53 | + |
| 54 | +Upon completion,the instances floating IP can be viewed in `instance_ip.txt`. |
| 55 | + |
| 56 | +### Destroy |
| 57 | + |
| 58 | + > watch the `-force` will not ask for any confirmation. |
| 59 | +
|
| 60 | +```sh |
| 61 | +terraform destroy -force |
| 62 | +# or with specific variables |
| 63 | +terraform destroy -force \ |
| 64 | + -var 'pool=gateway' \ |
| 65 | + -var 'flavor=m02.c02.d20' \ |
| 66 | + -var 'volume_size=3' \ |
| 67 | + -var 'network_name=my-network' \ |
| 68 | + -var 'ssh_key_file=./id_rsa_os' |
| 69 | +``` |
0 commit comments