Terraform Templates

What is Terraform

Hashicorp Terraformarrow-up-right is an open source IaC (Infrastructure-as-Code) tool for configuring and deploying cloud infrastructure. It codifies infrastructure in configuration files that describe the desired state for your topology. Terraform enables the management of any infrastructure such as public or private clouds.

What is a Terraform Template

A Terraform Template is a declarative code set written in HashiCorp Configuration Language (HCL), acting as a blueprint to define specific infrastructure resources. This approach ensures efficient and consistent configuration.

Templates are usually composed of multiple files, each dedicated to specific aspects of the overall template. This organization allows grouping diverse resource types, from networks to operating systems, facilitating flexible and scalable infrastructure design.

VM Template

This module is a template for the creation of the particular resources of each instance we are going to deploy, such as the VM, Network Interfaces, OS image, caching and storage type of the OS disk, and more.

The VM resource that you wish to instantiate must have the label "vdi_instance". Otherwise, it will not be recognized as a VDI Resource.

Example based on AWS
resource "aws_instance" "vdi_instance" {
  ami = var.ami
  instance_type = var.instance_type
  network_interface {
    network_interface_id = aws_network_interface.my_nic.id
    device_index = 0
  }
  tags = {
    Name = var.vmname
  }
}

Multiple Instantiation

Manually deploying each VM instance can be time consuming and prone to configuration errors, that's why Cloud Manager offers a solution by automating the provisioning process using Terraform's iterative capabilities.

Begin by defining the configuration for your VM instance in your VM Template. Configure the necessary parameters such as Instance Type, OS image, Networking settings, etc.

Use the for_each construct to iterate over a list of VM configurations. This list needs to use the variable vdi_instances. This will allow you to dynamically create multiple instances based on the specified parameters. The variable vdi_instances can be directly used in resource configurations or other parts of the Terraform code, referencing it as var.vdi_instances.

Shared Template

Consider utilizing a Shared template for provisioning shared resources across multiple instances. This approach allows you to define and manage common infrastructure components such as Network Security Groups, Virtual Networks, Subnets, and more. These resources will be linked to the Main module via output variables, customized according to the specific requirements of the cloud provider.

circle-check

Last updated