docs-terraform-guidelines

Terraform Naming Guidelines

use_snake_case_0nly

All resource or variable names in Terraform code must be written in snake_case. This means allowed characters are lowercase alphanumeric characters, with _ separators when needed.

Why ?

Note : Beware that actual cloud resources often have restrictions in allowed names. Some resources, for example, can’t contain dashes, some must be camelCased. The conventions in this document refer to Terraform names themselves.

Resource and/or data source naming

Variables

Do not reinvent the wheel when naming variables or writing descriptions. If a variable is consumed by a resource or module directly and you don’t need any sort of abstraction, reuse the variable name from the “Argument Reference” section in the resource’s (or module’s) documentation.

module "bucket" {
  source   = "github.com/padok-team/terraform-google-bucket"

  name = "frontend"
  storage_class = local.storage_class

  tags = local.tags
}

If your module is abstracting resource variables in any way, you should find a nam that best suits your parameter.

module "private_bucket" {
  source   = "github.com/padok-team/terraform-google-bucket"

  name = local.name
  private = true
}
module "public_bucket" {
  source   = "github.com/padok-team/terraform-google-bucket"

  name = local.name
  private = false
}

Module outputs

Naming module outputs properly is important for them to be consistent through your codebase, and for them to be understandable outside of their immediate context. From a user’s perspective, it should be trivial what type each attribute has.