Setting up Terraform for IBM Power Virtual Server
IBM Power Virtual Server in IBM data center
IBM Power Virtual Server Private Cloud in Client location
Terraform on IBM Cloud enables predictable and consistent provisioning of IBM Cloud services so that you can rapidly build complex, multitier cloud environments following Infrastructure as Code (IaC) principles. Similar to using the IBM Cloud CLI or API and SDKs, you can automate the provisioning, update, and deletion of your IBM® Power® Virtual Server instances by using HashiCorp Configuration Language (HCL).
Looking for a managed Terraform on IBM Cloud solution? Try out IBM Cloud Schematics. With Schematics, you can use the Terraform scripting language that you are familiar with, but you do not have to worry about setting up and maintaining the Terraform command-line and the IBM Cloud Provider plug-in. Schematics also provides pre-defined Terraform templates that you can easily install from the IBM Cloud catalog.
Installing Terraform and configuring resources for Power Virtual Server
Before you can create an authorization by using Terraform, make sure that you have completed the following prerequisites:
- Make sure that you have the required access to create and work with the Power Virtual Server resources.
- Install the Terraform CLI and configure the IBM Cloud Provider plug-in for Terraform. For more information, see the tutorial for Getting started with Terraform on IBM Cloud. The plug-in abstracts the IBM Cloud APIs that are used to complete this task.
- Create a Terraform configuration file that is named
main.tf
. In this file, you define resources by using HashiCorp Configuration Language. For more information, see the Terraform documentation.
-
Create a Power Virtual Server instance by using the
ibm_resource_instance
resource argument in yourmain.tf
file. The Power Virtual Server instance in the following example is namedtest_instance
and the resource isibm_pi_instance
.resource "ibm_pi_instance" "test-instance" { pi_memory = "4" pi_processors = "2" pi_instance_name = "test-vm" pi_proc_type = "shared" pi_image_id = "${data.ibm_pi_image.powerimages.id}" pi_key_pair_name = ibm_pi_key.key.key_id pi_sys_type = "s922" pi_cloud_instance_id = "51e1879c-bcbe-4ee1-a008-49cdba0eaf60" pi_pin_policy = "none" pi_health_status = "WARNING" pi_network { network_id = data.ibm_pi_public_network.dsnetwork.id } }
-
#After you finish building your configuration file, initialize the Terraform CLI. For more information, see Initializing Working Directories.
# terraform init
-
Create a Terraform execution plan. The Terraform execution plan summarizes all the actions that need to be run to create the Power Virtual Server instances:
# terraform plan
-
Create the Power Virtual Server instances in IBM Cloud.
# terraform apply
-
From the IBM Cloud resource list, select the Power Virtual Server instance that you created and note the instance ID.
What's next?
Now that you have successfully created your Power Virtual Server instance with Terraform on IBM Cloud, you can visit the Power Terraform registry to perform more tasks by using Terraform.