DevOps Classroom notes 08/Nov/2025

Terraform contd

Google Style Guide for Terraform

According to Terraform style guide over here https://developer.hashicorp.com/terraform/language/style. How should i name variables

Terraform input variables

  • Terraform allows to define variables and use them (which is better than hardcoding)
  • Syntax
variable "<LABEL>" {
  type        = <TYPE>
  default     = <DEFAULT_VALUE>
  description = "<DESCRIPTION>"
  sensitive   = <true|false>
  nullable    = <true|false>

}

  • Lets create a new tf file called as inputs.tf
variable "vpc_cidr" {
    type = string
    description = "vpc cidr"
    default = "192.168.0.0/16"
}

# -------------------
# Web Subnet Variables
# -------------------

variable "web_subnet_cidr" {
    type = string
    description = "web subnet cidr"
    default = "192.168.0.0/24"
}

variable "web_subnet_az" {
    type = string
    description = "web subnet az"
    default = "ap-south-1a"
}

# -------------------
# App Subnet Variables
# -------------------
variable "app_subnet_cidr" {
  type        = string
  description = "App subnet CIDR block"
  default     = "192.168.1.0/24"
}

variable "app_subnet_az" {
  type        = string
  description = "App subnet Availability Zone"
  default     = "ap-south-1b"
}

# -------------------
# DB Subnet Variables
# -------------------
variable "db_subnet_cidr" {
  type        = string
  description = "DB subnet CIDR block"
  default     = "192.168.2.0/24"
}

variable "db_subnet_az" {
  type        = string
  description = "DB subnet Availability Zone"
  default     = "ap-south-1c"
}

  • default values will be picked up when we dont pass the value
  • variable values can be passed by terraform commands
terraform apply -var 'vpc_cidr=10.0.0.0/16' -var 'web_subnet_cidr=10.0.0.0/24'
  • When we have many variables to pass the above command line becomes difficult to manage. so terraform allows to pass a file with variables which has an extension of .tfvars
  • ideally a tfvars file per environment and execute
 terraform apply -var-file='default.tfvars'

Terraform meta argument count

Terraform functions

Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Animated Social Media Icons by Acurax Responsive Web Designing Company

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube