SlideShare a Scribd company logo
Live
Learn Terraform in 45 min
By Brainboard’s team
(Focus: Variables)
Objective of the training today
✅ Learn everything about Terraform variables and how to use them.
What you will learn
1. How variables works and their types
2. CLI & environment variables
3. Locals
4. How to use variables
5. Variables in CI/CD
6. Secrets
7. Best practices
Variables & locals
Input: means variables
It’s… a block 😀
variable <NAME> {
# Block
}
Arguments
type can be:
1/ string, number, bool.
2/ list, tuple, map, object, set.
3/ any 😀
👉 you can combine types
default if present, the variable is optional
description
validation conditions to accept the variable
sensitive hidden from logs & outputs
nullable can be null or not?
💡Tips
- Start with the simplest form possible and add
constraints organically.
- Use Terraform function
- sensitive is also a Terraform function
Questions 🙋♂️🙋♀️
Variables’ values
Where do we put the values then?
1. In a file:
- terraform.tfvars (terraform.tfvars.json)
- *.auto.tfvars (*.auto.tfvars.json)
2. Command line “-var=’value_1’”
3. Environment variables TF_VAR_*
💡Tips
- Avoid vars in command line if possible
- Pick one method and use it, don’t mix
- Usually *.tfvars is the best way
4. Internal variables:
module.<NAME>.<OUTPUT>
path.module
count.index
each in for_each
Precedence
Env vars
terraform.tfvars
*.auto.tfvars
Command line
💪💪💪💪
💪💪💪
💪💪
💪
Variables in CI/CD
Best practices:
- Never put the values of variables in the *.tf
- Never commit the *.tfvars to git
- Using terraform.tfvars or *.auto.tfvars in your workflow is more useful for complex
structures
- Naming variables is extremely important
variables.tf = containers of the variables vs *.tfvars that are real values
Locals
local: is more like an alias to an expression (that may include variables)
It’s… a block 😀 but a whole block
locals {
cidr = var.cidr
}
💡Tips
- Are extremely flexible compared to vars
- Use it as an alias to access repeatedly the same expression
- Central place for repeated expressions
- Don’t confuse them with variables
Secrets
Secrets should be treated as secrets:
- Lifecycle
- Fetched from an external source
- Should be revoked easily
- Blast radius of a secret
- Secrets ≠ variables
- It’s better to use a vault (Vault, KMS, Azure Key Vault…)
- Use Terraform vault provider to use them
Join our Slack Community 🙋♂️🙋♀️
https://join.slack.com/t/brainboard-community/shared_invite/zt-19hmgmc92-MixDFmaADwxexAPSa5N~pg
Brainboard
Visually build & manage cloud infrastructures.

More Related Content

PPTX
Terraform training 🎒 - Basic
PPTX
Introduction to basics of Terraform.pptx
PDF
Configuration management II - Terraform
PPTX
Terraform
PPTX
DevOps Training - Introduction to Terraform
PPTX
Hashicorp-Certified-Terraform-Associate_V1
PDF
Intro to Terraform
PPTX
Terraform Modules and Continuous Deployment
Terraform training 🎒 - Basic
Introduction to basics of Terraform.pptx
Configuration management II - Terraform
Terraform
DevOps Training - Introduction to Terraform
Hashicorp-Certified-Terraform-Associate_V1
Intro to Terraform
Terraform Modules and Continuous Deployment

Similar to Learn Terraform - Variables (20)

PPTX
Hashicorp-Certified-Terraform-Associate-v3-edited.pptx
PDF
Terraforming
PPTX
Comprehensive Terraform Training
PPTX
Debasihish da final.ppt
PPTX
Terraform - The Road to Self-Service
PDF
Terraform best-practices-and-common-mistakes-dev ops-west-2021
PDF
Terraform Interview Questions By Scholarhat.pdf
PDF
Managing AWS Using Terraform AWS Atlanta 2018-07-18
PPTX
Terraform Best Practices for Infrastructure Scaling
PPTX
Terraform: Tales from the Trenches
PDF
DevOps Braga #9: Introdução ao Terraform
PDF
Introductory Overview to Managing AWS with Terraform
PPTX
Infrastructure as code with terraform and packer
PDF
Managing AWS Using Terraform AWS Chicago-Suburbs 2018-01-18
PDF
leboncoin DataEngineering / Terraform - beginner to advanced
PPTX
Terraform training - Modules 🎒
PPTX
A brief introduction to IaC with Terraform by Kenton Robbins (codeHarbour May...
PPTX
Terraform Modules Restructured
PPTX
Terraform modules restructured
PDF
Hashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdf
Hashicorp-Certified-Terraform-Associate-v3-edited.pptx
Terraforming
Comprehensive Terraform Training
Debasihish da final.ppt
Terraform - The Road to Self-Service
Terraform best-practices-and-common-mistakes-dev ops-west-2021
Terraform Interview Questions By Scholarhat.pdf
Managing AWS Using Terraform AWS Atlanta 2018-07-18
Terraform Best Practices for Infrastructure Scaling
Terraform: Tales from the Trenches
DevOps Braga #9: Introdução ao Terraform
Introductory Overview to Managing AWS with Terraform
Infrastructure as code with terraform and packer
Managing AWS Using Terraform AWS Chicago-Suburbs 2018-01-18
leboncoin DataEngineering / Terraform - beginner to advanced
Terraform training - Modules 🎒
A brief introduction to IaC with Terraform by Kenton Robbins (codeHarbour May...
Terraform Modules Restructured
Terraform modules restructured
Hashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdf
Ad

Recently uploaded (20)

PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
history of c programming in notes for students .pptx
PPTX
Introduction to Artificial Intelligence
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
Essential Infomation Tech presentation.pptx
PDF
Understanding Forklifts - TECH EHS Solution
PDF
System and Network Administraation Chapter 3
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
Reimagine Home Health with the Power of Agentic AI​
PPTX
Transform Your Business with a Software ERP System
PDF
Digital Strategies for Manufacturing Companies
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
ai tools demonstartion for schools and inter college
PDF
Design an Analysis of Algorithms II-SECS-1021-03
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
history of c programming in notes for students .pptx
Introduction to Artificial Intelligence
Upgrade and Innovation Strategies for SAP ERP Customers
Wondershare Filmora 15 Crack With Activation Key [2025
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
CHAPTER 2 - PM Management and IT Context
How to Choose the Right IT Partner for Your Business in Malaysia
Essential Infomation Tech presentation.pptx
Understanding Forklifts - TECH EHS Solution
System and Network Administraation Chapter 3
Design an Analysis of Algorithms I-SECS-1021-03
Reimagine Home Health with the Power of Agentic AI​
Transform Your Business with a Software ERP System
Digital Strategies for Manufacturing Companies
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Navsoft: AI-Powered Business Solutions & Custom Software Development
ai tools demonstartion for schools and inter college
Design an Analysis of Algorithms II-SECS-1021-03
Ad

Learn Terraform - Variables

  • 1. Live Learn Terraform in 45 min By Brainboard’s team (Focus: Variables)
  • 2. Objective of the training today ✅ Learn everything about Terraform variables and how to use them.
  • 3. What you will learn 1. How variables works and their types 2. CLI & environment variables 3. Locals 4. How to use variables 5. Variables in CI/CD 6. Secrets 7. Best practices
  • 4. Variables & locals Input: means variables It’s… a block 😀 variable <NAME> { # Block } Arguments type can be: 1/ string, number, bool. 2/ list, tuple, map, object, set. 3/ any 😀 👉 you can combine types default if present, the variable is optional description validation conditions to accept the variable sensitive hidden from logs & outputs nullable can be null or not? 💡Tips - Start with the simplest form possible and add constraints organically. - Use Terraform function - sensitive is also a Terraform function
  • 6. Variables’ values Where do we put the values then? 1. In a file: - terraform.tfvars (terraform.tfvars.json) - *.auto.tfvars (*.auto.tfvars.json) 2. Command line “-var=’value_1’” 3. Environment variables TF_VAR_* 💡Tips - Avoid vars in command line if possible - Pick one method and use it, don’t mix - Usually *.tfvars is the best way 4. Internal variables: module.<NAME>.<OUTPUT> path.module count.index each in for_each
  • 8. Variables in CI/CD Best practices: - Never put the values of variables in the *.tf - Never commit the *.tfvars to git - Using terraform.tfvars or *.auto.tfvars in your workflow is more useful for complex structures - Naming variables is extremely important variables.tf = containers of the variables vs *.tfvars that are real values
  • 9. Locals local: is more like an alias to an expression (that may include variables) It’s… a block 😀 but a whole block locals { cidr = var.cidr } 💡Tips - Are extremely flexible compared to vars - Use it as an alias to access repeatedly the same expression - Central place for repeated expressions - Don’t confuse them with variables
  • 10. Secrets Secrets should be treated as secrets: - Lifecycle - Fetched from an external source - Should be revoked easily - Blast radius of a secret - Secrets ≠ variables - It’s better to use a vault (Vault, KMS, Azure Key Vault…) - Use Terraform vault provider to use them
  • 11. Join our Slack Community 🙋♂️🙋♀️ https://join.slack.com/t/brainboard-community/shared_invite/zt-19hmgmc92-MixDFmaADwxexAPSa5N~pg
  • 12. Brainboard Visually build & manage cloud infrastructures.

Editor's Notes

  • #2: Thanks everyone for joining us today. As usual we’ll be waiting for 5 min. Put music https://open.spotify.com/playlist/4idpO55zNoCMNTtuqP0rlB?si=56914a0f6fd94054&nd=1#login For future training, webinars and use cases, follow our LinkedIn page. CTA like the Linkedin page -> share the LinkedIn page: https://www.linkedin.com/company/brainboard-co
  • #3: Especially in the CI/CD and automation in general but also cross environments It means we may have errors that we debug together, we may simulate errors to better understand how it works….
  • #4: Explain the different topics quickly We’ll be taking questions regularly, so if you have any questions ask in the chat and the team will handle it
  • #5: How variables are defined and used in the CI/CD pipeline: variables.tf vs *.tfvars To show case the different argument create a vpc + subnet + instance -> this is a real use case The purpose here is also to see the thinking process, start with the simplest form you can and add organically constraints Input = variables & locals Let’s start with variables as they slightly differ from locals Arguments, type: list(string) Map List of map or object list(object({ internal = number external = number protocol = string })) Map or map(string) If default and type are present, the default should be in the specified type. Show an example In validation you can use Terraform functions like. Show an example: length(var.toto) > 4 Sensitive: show an example of a resource containing a sensitive information sensitive in TF is week, it’s better to treat sensitive as secrets and hide them with your vault because if it’s part of the id it will be printed even if it’s sensitive Use random_pet Error messages
  • #7: I know the value of my variable, so where do I put it’s value? tfvars: this is how tf passes vars in their cloud offering and this how bb also do it Show bb separation between variables.tf and variables.tfvars Space around = are not tolerated…. In command line vars TF_VAR_varname=”toto” difference between env vars and files is with env var there are no warnings or error messages
  • #10: How variables are defined and used in the CI/CD pipeline: variables.tf vs *.tfvars To show case the different argument create a vpc + subnet + instance -> this is a real use case The purpose here is also to see the thinking process, start with the simplest form you can and add organically constraints Input = variables & locals Let’s start with variables as they slightly differ from locals Arguments, type: list(string) Map List of map or object list(object({ internal = number external = number protocol = string })) Map or map(string) If default and type are present, the default should be in the specified type. Show an example In validation you can use Terraform functions like. Show an example: length(var.toto) > 4 Sensitive: show an example of a resource containing a sensitive information sensitive in TF is week, it’s better to treat sensitive as secrets and hide them with your vault because if it’s part of the id it will be printed even if it’s sensitive Use random_pet Error messages
  • #13: Quick introduction about what we are working on at Brainboard. Bidirectional way from code to design and vice versa.