menu
techminis

A naukri.com initiative

google-web-stories
Home

>

Devops News

>

Introducti...
source image

Dev

1M

read

292

img
dot

Image Credit: Dev

Introduction to Terraform Variables(Input) and Values

  • In this post, we'll explore the basics of Terraform values and Input variables and how they work in modules. Every Terraform configuration is part of a module, even a single .tf file. We will start with the basic example of a Terraform setup with a root module and a child module, then we will move on to the different types of Input Variables and values in Terraform.
  • Terraform modules are building blocks, grouping multiple resources, enabling reuse and organization of cloud infrastructure. Modules help manage complexity by breaking down large infrastructure into smaller, manageable components.
  • Input variables let you customize aspects of Terraform modules without altering the module's own source code, making a module composable and reusable. When you declare variables in the root module, you set their values using CLI options and environment variables. Types of Input Variables include String, Number, Bool, List, Map, Tuple, Object, and Set types.
  • Local Values, on the other hand, reduce duplication within the Terraform code, simplifying complex expressions or calculations. Local values help define reusable expressions that improve the flexibility and readability of the code. When used in the code, local values are reduced to a name and assigned a value.
  • Output Values serve two main purposes: displaying information details about a resource, data source, local value, or variable after deployment and exporting information for use outside the module.
  • The blog post also includes a practical guide to deploying Nginx on an Ubuntu EC2 instance using Terraform modules. The guide features a project in which input variables and local values are passed, and output values are declared to create and remove AWS resources while deploying Nginx on an Ubuntu EC2 instance.
  • The Terraform version is locked in the project to ensure stability and prevent unexpected updates. The root and child modules are defined, and values are passed using input variables and local values. The project is completed with the creation of output values to access the Ubuntu instance's public IP.
  • Terraform Modules and Input variables, together with local and output variables, provide the flexibility to manage complexity in cloud infrastructure by enabling modular and reusable blocks of code.

Read Full Article

like

17 Likes

For uninterrupted reading, download the app