Terraform VM by Anarion Technologies
Terraform is an open-source infrastructure as code (IaC) tool developed by HashiCorp. It enables users to define and provision data center infrastructure through a high-level configuration language known as HashiCorp Configuration Language (HCL), or optionally JSON. This declarative approach allows users to specify the desired state of their infrastructure in configuration files, which Terraform then uses to create an execution plan, previewing changes before they are applied to ensure accuracy.
Terraform constructs a resource dependency graph, enabling it to manage and apply changes to independent resources in parallel, enhancing efficiency. It automates the process of updating the infrastructure to match the desired state, facilitating continuous delivery and integration. Terraform’s robust provider ecosystem supports a wide array of cloud providers and services, allowing seamless management of diverse infrastructure components, from physical servers and virtual machines to containers and network appliances, across different environments including public clouds and on-premises data centers.
This tool’s ability to version, share, and reuse infrastructure configurations significantly improves collaboration among teams and simplifies the management of infrastructure at scale. By using Terraform, teams can ensure that their infrastructure remains consistent and reproducible, making it an essential component in modern DevOps practices.
To subscribe to this product from Azure Marketplace and initiate an instance using the Azure compute service, follow these steps:
1. Navigate to Azure Marketplace and subscribe to the desired product.
2. Search for “virtual machines” and select “Virtual machines” under Services.
3. Click on “Add” in the Virtual machines page, which will lead you to the Create a virtual machine page.
4. In the Basics tab:
- Ensure the correct subscription is chosen under Project details.
- Opt for creating a new resource group by selecting “Create new resource group” and name it as “myResourceGroup.”
5. Under Instance details:
- Enter “myVM” as the Virtual machine name.
- Choose “East US” as the Region.
- Select “Ubuntu 18.04 LTS” as the Image.
- Leave other settings as default.
6. For Administrator account:
- Pick “SSH public key.”
- Provide your user name and paste your public key, ensuring no leading or trailing white spaces.
7. Under Inbound port rules > Public inbound ports:
- Choose “Allow selected ports.”
- Select “SSH (22)” and “HTTP (80)” from the drop-down.
8. Keep the remaining settings at their defaults and click on “Review + create” at the bottom of the page.
9. The “Create a virtual machine” page will display the details of the VM you’re about to create. Once ready, click on “Create.”
10. The deployment process will take a few minutes. Once it’s finished, proceed to the next section.
To connect to the virtual machine:
1. Access the overview page of your VM and click on “Connect.”
2. On the “Connect to virtual machine” page:
- Keep the default options for connecting via IP address over port 22.
- A connection command for logging in will be displayed. Click the button to copy the command. Here’s an example of what the SSH connection command looks like:
“`
ssh [email protected]
“`
3. Using the same bash shell that you used to generate your SSH key pair, you can either reopen the Cloud Shell by selecting >_ again
or going to https://shell.azure.com/bash.
4. Paste the SSH connection command into the shell to initiate an SSH session.
Usage/Deployment Instructions
Anarion Technologies – Terraform
Note: Search product on Azure marketplace and click on “Get it now”
Click on Continue
Click on Create
Creating a Virtual Machine, enter or select appropriate values for zone, machine type, resource group and so on as per your choice.
After Process of Create Virtual Machine. You have got an Option Go to Resource Group Click Go to Resource Group
Copy the Public IP Address
SSH into your Terminal and run these following commands:
To confirm that Terraform is working correctly on your system, you can follow these steps:
$ terraform –version
To initialize a Terraform project, follow these steps:
Create a Directory for Your
Project: Choose a location and create a new directory for your
Terraform configuration files. Navigate to that directory in your terminal.
$ mkdir my-terraform-project
$ cd my-terraform-project
$ nano main.tf
Create Terraform Configuration Files: Create a file with a .tf extension (e.g., main.tf). This file should
contain your Terraform configuration, specifying the provider and resources you want to manage.
Example main.tf file:
# Specify the provider
provider “azurerm” {
features {}
}
# Define an Azure resource group
resource “azurerm_resource_group”
“example” {
name = “example-resources”
location = “West Europe”
}
Configure
Authentication: To authenticate with Azure, you need to set up Azure credentials. You can use Azure CLI or service principal authentication.
· Using Azure CLI: Log in to Azure CLI and set the appropriate subscription:
$ az login
$ az account set –subscription “Your Subscription ID”
Using a Service Principal: If you’re using a service principal, you’ll need to create it and set the environment variables:
$ az ad sp create-for-rbac –role=”Contributor” –scopes=”/subscriptions/{subscription-id}”
This command will output credentials that you can set as environment variables:
export ARM_CLIENT_ID=”<client-id>”
export ARM_CLIENT_SECRET=”<client-secret>”
export ARM_SUBSCRIPTION_ID=”<subscription-id>”
export ARM_TENANT_ID=”<tenant-id>”
Run terraform init
: Initialize your Terraform project:
$ terraform init
Validate Your Configuration: Check if your configuration is valid:
$ terraform validate
Plan and Apply Configuration:Generate an execution plan and apply the configuration:
$ terraform plan
$ terraform apply
Its failed cause we uses example for azure.
Confirm
the changes when prompted.
With these steps, you should have your
Terraform project initialized and ready to manage Azure resources. If you have
specific resources or configurations in mind, you can expand the main.tf
file with additional
resource definitions as needed.