Wednesday, December 14, 2022

Types of Input Variables In Terraform ?

Variables are a great way to define centrally controlled reusable values. The information in Terraform variables is saved independently from the deployment plans, which makes the values easy to read and edit from a single file.

Note : All the variables commonly are in a file vars.tf & variable.tf. You also can modify the file name whatever you want.

1) Simple Variables

A simple variable is like a key-value and can be declared as shown below.


Let’s understand what it all means

  • Line 1 Declares the name of the variable – demo_instance_type
  • Line 2 Declares the type of variable string. (Optional)
  • Line 3 Declares the default value of the variable in case no other value is assigned.
  • Line 4 Provide a description of the variable. (Optional)

2) List


Let’s understand what it all means

  • Line 1 Declares the name of the variable – demo_sg_allow_ips_for_SSH
  • Line 2 Declares the type of variable list. (Optional)
  • Line 3 Declares the default list of values.
  • Line 4 Provide a description of the variable. (Optional)


3) Map

Maps are a set of key-value pairs. Similar to map data-structure in various languages. An often used example for maps is about selecting an Instance ID based on Operating Name. It allows us to understand map variables quite easily.


Let’s understand what it all means

  • Line 1 Declares the name of the variable – demo_ami_id
  • Line 2 Declares the type of variable map. (Optional)
  • Line 3 Declares the default map of key-value pairs assigned in case no other maps is assigned.



Example Of Added Variable into Resources.


 

 

 

 

No comments:

Post a Comment

testing