IBM Power Systems is known for its high-performance capabilities, ideal for handling demanding workloads such as large-scale databases, AI/ML applications, and enterprise platforms like SAP HANA. As more organizations transition towards cloud and hybrid environments, IBM introduced the IBM Power Virtual Server (PowerVS), offering a seamless hybrid cloud experience for IBM POWER systems, utilizing IBM Cloud infrastructure. With this shift towards hybrid cloud environments, the need for automated and efficient infrastructure management has become more critical. This is where Terraform plays a pivotal role. Terraform, an open-source Infrastructure as Code (IaC) tool, empowers organizations to define, provision, and manage IBM Power Virtual Server resources consistently and predictably.
In this blog, we will explore how to leverage Terraform to streamline the management of IBM Power Virtual Server infrastructure.
Before diving into how Terraform can be used for IBM Power Virtual Server, let’s look at a few reasons why it is beneficial:
• Automation: Manual provisioning is time-consuming and error prone. Terraform automates the creation, management, and decommissioning of infrastructure, ensuring consistency across environments.
• Infrastructure as Code (IaC): With Terraform, infrastructure configurations are stored as code. This allows for version control, collaboration, and better visibility into infrastructure changes.
• Declarative Syntax: Terraform’s declarative syntax makes it easy to define what you want (the end state) without worrying about how to achieve it.
• Consistency: By using Terraform, you can ensure that your Power Virtual Server infrastructure is consistently provisioned across multiple environments.
• Multi-cloud Management: Terraform supports multiple cloud platforms, making it easier to integrate IBM PowerVS into hybrid or multi-cloud strategies.
Terraform basic Workflow:
Terraform’s workflow consists of three main steps: write, plan, and apply. Initially, you define your infrastructure as code using configuration files, specifying resources like virtual machines, networks, and storage. After writing the configurations, you run "terraform plan", which generates an execution plan that outlines the changes Terraform will implement, allowing you to review and confirm them. Finally, you execute "terraform apply" to provision or update the specified resources in your cloud environment. This systematic approach ensures that your infrastructure is consistent, reproducible, and easily manageable, enabling you to efficiently handle infrastructure changes over time.
Prerequisites:
Before we begin, ensure the following prerequisites are complete:
1.IBM Cloud Account with IBM Power Virtual Server (PowerVS) services enabled.
2.IBM Cloud CLI and Terraform installed on your machine.
3.Terraform IBM Cloud Provider Plugin installed.
Configuring Terraform for IBM Cloud
Install Terraform: To begin using Terraform with IBM PowerVS, the initial step is to install Terraform on your local machine. Terraform is compatible with macOS, Windows, and Linux operating systems. You can download the version suitable for your system from the official Terraform website.
After the installation is complete, you can confirm that Terraform is installed correctly by executing the following command in your terminal:
Install IBM PowerVS Provider: Terraform uses providers to communicate with different infrastructure platforms. The IBM Power virtual server provider allows you to interact with IBM Power Virtual Server (VS) environments. To install the IBM Power VS provider, add the following block to your Terraform configuration to specify the provider:
Then, initialize the configuration by running "terraform init" command on console.
Authenticating Terraform with IBM Cloud: Generate an IBM Cloud API key and add the generated API key to your Terraform code like the below
Essential Terraform Operations on IBM PowerVS: Compute, Storage, and Network
You can now define the terraform configuration files (.tf files) by using HashiCorp Configuration Language (HCL) to create resources on IBM Power Virtual Servers.
Let us look into how we can use terraform in PowerVS for doing basic infrastructure stack like compute, storage and network. In this blog, we are taking create, update, delete operations in each of compute, storage and network components of PowerVS.
Compute operations using terraform
Create: To create a virtual server instance on IBM PowerVS, we need to use "ibm_pi_instance" resource block. For example you can have a look on the below example.This block will create an instance with specific configurations such as instance name, image, and machine type.
Update: Open your existing .tf configuration file where you defined your PowerVS instance and make the necessary changes, after making the changes in configuration files, you need to save it and then need to run "terraform plan" to review the proposed changes and after that "terraform apply" to apply the changes. For example, to increase the memory and the number of processors, you might adjust the values like this:
In this example, we are changing memory from 4GB to 8GB , processor from 2 to 4 and modifying SSH Keypair name.
Delete: To delete an IBM Power Virtual Server (PowerVS) instance that you created using Terraform, you can follow these steps:
1. Navigate to Your Terraform Configuration: Make sure you are in the directory where your Terraform configuration file(e.g., main.tf) is located.
2. Remove or Comment Out the Resource Definition: If you want to delete the PowerVS instance managed by Terraform, you have two options:
Option 1: Remove the resource block: Open your .tf file and either delete or comment out the resource block for the PowerVS instance you want to delete.
Option 2: Keep the resource block: If you prefer to keep the configuration file for reference and want to manage the deletion directly, you can skip this step.
3. Run Terraform Commands: Use the following commands to delete the instance:
Storage operations using terraform
Create: For creating new storage volume we need to use "ibm_pi_volume" resource block.The below example can be used to created new storage volume using the IBM Cloud Power Systems Virtual Server (PowerVS) Terraform provider.
You can use the below configuration for attaching a Storage Volume to a Virtual Server, here we need to use "ibm_pi_volume_attach" resource block.
Update: Here’s an example showing how to increase the size of an existing storage volume, after making the changes in terraform configuration files, you need to save it and then need to run "terraform plan" to review the proposed changes and after that "terraform apply" to apply the changes
Delete: To delete a storage volume, simply use the "terraform destroy" command or remove the storage volume resource from your Terraform configuration like the way we have done for compute resource deletion step.
Network operations using terraform
Create: ibm_pi_network resource block can be used to created subnet in IBM PowerVS, for example the below configuration can be used as per your need.
Update: If you want to update the subnet by changing the CIDR block (pi_cidr), suppose from 10.0.0.0/24 to 10.1.0.0/24, the gateway, and the IP address range, the updated configuration will look like the below and after changing the configuration file, you need to execute “terraform plan” to review and “terraform apply” to execute the change
Delete: To delete a subnet, simply use the terraform destroy command or remove the subnet creation resources from your Terraform configuration like the way we have done for compute resource deletion step
Now, let us create a simple terraform configuration to do basic Virtual Machine deployment in PowerVS. Below is the sample terraform configuration file which includes compute, storage and network operations:
The above configuration file created Subnet, Volume, PowerVS Instance and attach created volume with the PowerVS Instance like the below:
Conclusion:
Terraform streamlines the orchestration and lifecycle management of IBM PowerVS infrastructure by abstracting the complexities of provisioning, scaling, and configuring virtual servers, networks, and storage. Through its declarative approach, Terraform enables you to codify your infrastructure, empowering version control, collaborative development workflows, and enhanced repeatability across environments.
By adhering to the methodologies presented in this blog, you have now gained foundational proficiency in leveraging Terraform to deploy and manage IBM PowerVS resources. As you delve deeper into Terraform’s advanced functionalities, you will unlock the capability to architect modular, scalable, and resilient infrastructure solutions that adapt to evolving enterprise demands.
References: https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/