Terraform : Maps and lookups

Today we will be seeing lookups and map functions of Terraform which would help you give the functionality of looking up if there is a map variable in your code (like : Key = Value). You could use this functionality as per the need or requirement, in this post we would be utilizing this function to create Prod and Dev environment with same code check this out : -

Below is the snippet of variable.tf file which shows how you define the environment variable as map.



Below is the snippet of main.tf file which shows how we lookup the map variable :





Now you see how we define the variable and used lookup function in the main-tf & when we run the terraform plan you can see in the below snippet , it would ask env : and apply the code accordingly.




Below is the you-tube video for Variable



So this is how we use the Terrform maps and lookups which is a great way writing a code however its not a great way of keeping it together because "tfstate" file monitor whats in our environment and any info changes or contradict with it it would create a problem now either you can move this file to separate place which would increase the admin task or we would lets see "workspaces" in terraform.





No comments:

Post a Comment

MS Defenders

 Microsoft Defender offers a wide range of security solutions, similar to the ones we've discussed (Defender for Containers, Defender fo...