Skip to content

softcat477/openstack-terraform-instance

Repository files navigation

openstack instances with terraform

Use Terraform to create four instances and volumes on OpenStack with combinations:

  1. Boot an instance from an image. Nothing is left after you terminate the instance.
  2. Boot an instance from an image and attach a volume to it.
    • The volume is not destroyed if you terminate the instance.
  3. 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
  4. 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.

Steps to run

  1. source the openrc.sh file.
  2. terraform init
  3. 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>'
  1. 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>'
  1. 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>'

Verify Changes with openstack-cli

Check Instance

# 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                                 |
+-------------------------------+-------------------------------------------------+

Check Volume

# 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                |
+----------------------------------------+-----------+---------------------------------------------------------------+

Commands that might help

Check Flavor

$ openstack flavor list -c Name -c VCPUs -c RAM -c Disk
+------------------+--------+------+-------+
| Name             |    RAM | Disk | VCPUs |
+------------------+--------+------+-------+
| p1-1.5gb         |   1536 |   20 |     1 |
+------------------+--------+------+-------+

Check Keypair

$ openstack keypair list
+---------+
| Name    |
+---------+
| <name>  |
+---------+

Check Security Group

$ openstack security group list -c Name -c Description
+-------------------+---------------------------------------------------------------+
| Name              | Description                                                   |
+-------------------+---------------------------------------------------------------+
| default           | Default security group                                        |
+-------------------+---------------------------------------------------------------+

Check Image

$ openstack image list -c ID -c Name
+--------------------------------------+-------------------------------------------------+
| ID                                   | Name                                            |
+--------------------------------------+-------------------------------------------------+
| c5cc203c-c163-455d-97c7-566cc62bc130 | kali_2024-03-01                                 |
+--------------------------------------+-------------------------------------------------+

Check Network

$ openstack network list -c Name
+--------------------+
| Name               |
+--------------------+
|  <Network Name>    |
+--------------------+

About

Openstack instance and volume with terraform

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages