How to create an instance with Terraform?
Learn how to launch an instance using Terraform with this step-by-step tutorial.
What is a Terraform?
Terraform is an infrastructure provisioning tool that allows you to construct infrastructure using code, often called Infrastructure as Code. Terraform, as a result, enables you to automate and maintain your infrastructure, platform, and applications that operate on that platform.
How does Terraform function?
Terraform uses configuration files and version control to define and manage your whole infrastructure. This is accomplished by utilizing the two primary components of Terraform architecture: Core and Providers.
Read and follow these instructions carefully. The instructions below describe how to create an instance with Terraform on Ubuntu.
Get Sarted
Step 1: Install Terraform
(a) Add the HashiCorp GPG key.
(b) For Terraform Repository.
(c) Run the system update command and install Terraform.
(d) Check if Terraform is installed correctly or not.
Step 2: Creating a provider
You specify "providers" for your cloud environment in Terraform. Your OpenStack infrastructure resources are hosted by a "provider." Make a file called provider.tf.
Step 3: Paste the following code
The OpenStack provider is used to communicate with the numerous OpenStack resources. Before it can be utilized, the provider must be set up with the appropriate credentials.
Step 4: Initialize the Terraform environment
Now, you need to initialize the working directory, which actually contains the terraform .tf file.
Step 5: Create a variable file
Step 6: Paste the following variables and edit as per your usage
Step 7: Create the main file
Step 8: Paste the following command
Step 9: Create an execution plan
This command is a quick method to see if the execution plan for a set of modifications fits your expectations without affecting actual resources or the state.
After executing the command, enter your console username, password, and project name.
Step 10: Execute the actions
After executing the command, enter your console username, password, and project name again and enter yes to confirm.
Now instance has been created, you can verify it on the portal.
Step 11: Delete the instance
After executing the command, enter yes to confirm. Your instance will be deleted.
Last updated