📚 Cheatsheet

Une collection organisée de snippets de code pour accélérer votre développement. Parcourez, recherchez et copiez en un clic.

Snippets 8

Retour
Déclarer une sortie (output)
Facile
output "instance_ip_addr" {
  value = aws_instance.server.private_ip
}
Sortie sensible (sensitive)
Intermédiaire
output "db_password" {
  value     = aws_db_instance.default.password
  sensitive = true
}
Validation de variable
Avancé
variable "ami_id" {
  type = string
  validation {
    condition     = can(regex("^ami-", var.ami_id))
    error_message = "Doit être un ID d'AMI valide, commençant par 'ami-'."
  }
}
Variable d'entrée simple
Facile
variable "region" {
  description = "La région AWS à utiliser."
  type        = string
  default     = "us-west-2"
}
Variable d'objet complexe
Intermédiaire
variable "users" {
  type = map(object({
    name  = string
    admin = bool
  }))
}
Variable de type liste
Facile
variable "subnet_ids" {
  type    = list(string)
  default = []
}
Variable de type map
Facile
variable "tags" {
  type    = map(string)
  default = {
    Environment = "Dev"
    Project     = "MonApp"
  }
}
Variables locales
Facile
locals {
  common_tags = {
    Owner = "EquipeDev"
  }
}