We can deploy cloud Infrastructure on IDrive® Compute with the help of widely used open-source infrastructure as code software Terraform. While we can deploy various virtual resources on IDrive® Compute with Terraform, In this article we will try to concentrate on creating IDrive® Compute Volumes.
Pre-requisite:
We need to install the following software on your local system.
Terraform code:
Here are the terraform files required for the creation.
Here are the terraform files required for the creation.
1) Providers file:
Create a file named main.tf and write the file with the below code.
$ touch main.tf
Append the following configuration to the main.tf file.
# Configure the OpenStack Provider
terraform {
required_providers {
openstack = {
source = "terraform-provider-openstack/openstack"
}
}
}
2) Deployment file: deploy.tf
$ touch deploy.tf
Add the below code to deploy.tf file.
resource "openstack_blockstorage_volume_v3" "volume_1" {
region = "LA3"
name = "volume_1"
description = "first test volume"
size = 3
}
Here we are creating a volume by the name "First test volume" of size "3 GB" in the region "LA3". Please change the parameters as per your requirement.
Using Terraform to create a Volume
we execute the below operations:
- terraform init ( Needs to be executed only once for initializing)
- terraform plan ( To see what's being deployed)
- terraform deploy (creates the requested resources)
Initializing terraform:
$ terraform init
Output:
Initializing the backend...
Initializing provider plugins...
- Finding latest version of terraform-provider-openstack/openstack...
- Installing terraform-provider-openstack/openstack v1.49.0...
- Installed terraform-provider-openstack/openstack v1.49.0 (self-signed, key ID 4F80527A391BEFD2)
Partner and community providers are signed by their developers.
If you'd like to know more about provider signing, you can read about it here:
https://www.terraform.io/docs/cli/plugins/signing.html
Terraform has created a lock file .terraform.lock.hcl to record the provider
selections it made above. Include this file in your version control repository
so that Terraform can guarantee to make the same selections by default when
you run "terraform init" in the future.
Terraform has been successfully initialized!
You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.
If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
Applying terraform plan:
$ terraform plan
Output:
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# openstack_blockstorage_volume_v3.volume_1 will be created
+ resource "openstack_blockstorage_volume_v3" "volume_1" {
+ attachment = (known after apply)
+ availability_zone = (known after apply)
+ description = "first test volume"
+ id = (known after apply)
+ metadata = (known after apply)
+ name = "volume_1"
+ region = "LA3"
+ size = 3
+ volume_type = (known after apply)
}
Plan: 1 to add, 0 to change, 0 to destroy.
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to take exactly these actions if you run "terraform apply" now.
Applying the configuration:
$ terraform apply
Output:
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# openstack_blockstorage_volume_v3.volume_1 will be created
+ resource "openstack_blockstorage_volume_v3" "volume_1" {
+ attachment = (known after apply)
+ availability_zone = (known after apply)
+ description = "first test volume"
+ id = (known after apply)
+ metadata = (known after apply)
+ name = "volume_1"
+ region = "LA3"
+ size = 3
+ volume_type = (known after apply)
}
Plan: 1 to add, 0 to change, 0 to destroy.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
openstack_blockstorage_volume_v3.volume_1: Creating...
openstack_blockstorage_volume_v3.volume_1: Still creating... [10s elapsed]
openstack_blockstorage_volume_v3.volume_1: Creation complete after 12s [id=e3dd59b5-d9f6-43af-8ec2-4fd4172d5a27]
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
Verification:
You can verify the creation of the volume by the below openstack command.
$ openstack volume show volume_1 -f json
Output:
{
"attachments": [],
"availability_zone": "nova",
"bootable": "false",
"consistencygroup_id": null,
"created_at": "2023-02-06T07:01:26.000000",
"description": "first test volume",
"encrypted": false,
"id": "6eb7bb58-9b63-4ac9-8d8c-dac4bf1674eb",
"multiattach": false,
"name": "volume_1",
"os-vol-tenant-attr:tenant_id": "b88176b3de3f4771aa183e8bd7e1edc7",
"properties": {},
"replication_status": null,
"size": 3,
"snapshot_id": null,
"source_volid": null,
"status": "available",
"type": "__DEFAULT__",
"updated_at": "2023-02-06T07:01:26.000000",
"user_id": "191931bc755f410784fe42594c8e588d"
}