Example
Loading...
Naming Conventions Example
In this example, we will create a naming convention for variables in a Terraform codebase. We will use the following naming conventions:
Well-structured variable
1variable "db_instance_name" {2 # ...3}1variable "db_instance_name" {2 # ...3}Leverage Resource Argument Standards
1variable "db_instance_name" {2 description = "The name of the RDS instance."3}1variable "db_instance_name" {2 description = "The name of the RDS instance."3}Types:
Utilize Type any for Flexibility:
1variable "codepipeline_artifact_store" {2 type = any3}Prioritize Simple Types:
1variable "instance_type" {2 type = string3}1variable "instance_type" {2 type = any3}Choose Specific Types for Homogeneous Maps:
1variable "tags" {2 type = map(string)3}1variable "tags" {2 type = map(any)3}Opt for Plural Form in Variable Names
1variable "db_instance_names" {2 type = list(string)3}1variable "db_instance_name" {2 type = string3}Understand Validation Limitations:
1variable "db_instance_name" {2 validation {3 condition = length(var.db_instance_name) > 04 error_message = "The name of the RDS instance cannot be empty."5 }6}1variable "db_instance_name" {2 validation {3 condition = var.db_instance_name != ""4 error_message = "The name of the RDS instance cannot be empty."5 }6}Organize Variable Blocks:
1variable "db_instance_name" {2 type = string3 description = "The name of the RDS instance."4 default = "rds-instance"5 validation {6 condition = length(var.db_instance_name) > 07 error_message = "The name of the RDS instance cannot be empty."8 }9}