Use Terraform
to create four instances and volumes on OpenStack
with combinations:
- Boot an instance from an image. Nothing is left after you terminate the instance.
- Boot an instance from an image and attach a volume to it.
- The volume is not destroyed if you terminate the instance.
- Boot an instance from a bootable volume.
- The bootable volume is not destroyed after you terminate the instance.
- Since the bootable volume is not destroyed. You can boot another instance from the bootable volume. The changes you made in the terminated instance, like editing files, will be in the new instance.
- The name of the bootable instance is generated by
OpenStack
. You get something like this:b4258073-186d-4023-a763-6fe13e7750c2
- Boot an instance from a bootable volume, name the bootable volume, and attach another volume (non-bootable) to it.
- Almost like case 3, but you can name both volumes (bootable and non-bootable)
- Both volumes are not destroyed after you terminate the instances, so you can reuse them. Any changes made inside will remain.
- source the
openrc.sh
file. terraform init
- Show changes
terraform plan -var 'flavor=<flavor>' \
-var 'keypair=<keypair>' \
-var 'sg=["<security group name>"]' \
-var 'image-id=<image id>' \
-var 'network-name=<network name>'
- Apply changes
terraform apply -var 'flavor=<flavor>' \
-var 'keypair=<keypair>' \
-var 'sg=["<security group name>"]' \
-var 'image-id=<image id>' \
-var 'network-name=<network name>'
- Destroy changes
terraform destroy -var 'flavor=<flavor>' \
-var 'keypair=<keypair>' \
-var 'sg=["<security group name>"]' \
-var 'image-id=<image id>' \
-var 'network-name=<network name>'
# Should see four instances. Two booted from a volume, two from an image.
$ openstack server list -c Name -c Image
+-------------------------------+-------------------------------------------------+
| Name | Image |
+-------------------------------+-------------------------------------------------+
| boot-from-named-volume | N/A (booted from volume) |
| boot-from-unnamed-volume | N/A (booted from volume) |
| boot-from-image | kali_2024-03-01 |
| boot-from-image-attach-volume | kali_2024-03-01 |
+-------------------------------+-------------------------------------------------+
# Should see four volumes
$ openstack volume list -c Name -c Status -c "Attached to"
+----------------------------------------+-----------+---------------------------------------------------------------+
| Name | Status | Attached to |
+----------------------------------------+-----------+---------------------------------------------------------------+
| | in-use | Attached to boot-from-unnamed-volume on /dev/vda |
| boot-from-named-volume-bootable-volume | in-use | Attached to boot-from-named-volume on /dev/vda |
| boot-from-image-attached-volume | in-use | Attached to boot-from-image-attach-volume on /dev/vdb |
| boot-from-named-volume-attached-volume | in-use | Attached to boot-from-named-volume on /dev/vdb |
+----------------------------------------+-----------+---------------------------------------------------------------+
$ openstack flavor list -c Name -c VCPUs -c RAM -c Disk
+------------------+--------+------+-------+
| Name | RAM | Disk | VCPUs |
+------------------+--------+------+-------+
| p1-1.5gb | 1536 | 20 | 1 |
+------------------+--------+------+-------+
$ openstack keypair list
+---------+
| Name |
+---------+
| <name> |
+---------+
$ openstack security group list -c Name -c Description
+-------------------+---------------------------------------------------------------+
| Name | Description |
+-------------------+---------------------------------------------------------------+
| default | Default security group |
+-------------------+---------------------------------------------------------------+
$ openstack image list -c ID -c Name
+--------------------------------------+-------------------------------------------------+
| ID | Name |
+--------------------------------------+-------------------------------------------------+
| c5cc203c-c163-455d-97c7-566cc62bc130 | kali_2024-03-01 |
+--------------------------------------+-------------------------------------------------+
$ openstack network list -c Name
+--------------------+
| Name |
+--------------------+
| <Network Name> |
+--------------------+