🔁 DevOps

terraform-guide

Guide Terraform pour l'Infrastructure as Code — modules, state management, workspaces et bonnes pratiques.

⚡ Installation & lancement en 1 commande

Copiez-collez dans votre terminal : le skill s'installe dans ~/.claude/skills et Claude Code se lance directement dessus.

macOS / Linux
curl -fsSL https://raw.githubusercontent.com/khalilbenaz/claude-skills-collection/main/install.sh | sh -s -- terraform-guide --launch
Windows (PowerShell)
iex "& { $(iwr -useb https://raw.githubusercontent.com/khalilbenaz/claude-skills-collection/main/install.ps1) } terraform-guide -Launch"

🚀 Déjà installé ?

claude "/terraform-guide"

Ou tapez /terraform-guide dans une session Claude Code, ou décrivez simplement votre besoin — le skill se déclenche automatiquement via le skill-router.

🔑 Déclencheurs automatiques

Le skill s'active automatiquement quand votre demande contient :

terraforminfrastructure as codeterraform planterraform applymodule terraformtfstateHCL

📦 Installation manuelle

git clone https://github.com/khalilbenaz/claude-skills-collection.git cp -r claude-skills-collection/devops-skills/terraform-guide ~/.claude/skills/

Source : devops-skills/terraform-guide

📖 Manuel

Guide Terraform

Workflow

  1. Concevoir : identifier les ressources, organiser en modules.
  2. Écrire : fichiers HCL avec variables, outputs et data sources.
  3. Planifier : terraform plan pour prévisualiser les changements.
  4. Appliquer : terraform apply avec review et approbation.
  5. Maintenir : state management, drift detection, mises à jour.

Structure d'un projet

infrastructure/
├── environments/
│   ├── dev/
│   │   ├── main.tf
│   │   ├── variables.tf
│   │   ├── terraform.tfvars
│   │   └── backend.tf
│   ├── staging/
│   └── production/
├── modules/
│   ├── networking/
│   │   ├── main.tf
│   │   ├── variables.tf
│   │   └── outputs.tf
│   ├── database/
│   └── app-service/
└── shared/
    └── providers.tf

Module réutilisable

# modules/app-service/main.tf
variable "app_name" {
  type        = string
  description = "Nom de l'application"
}

variable "environment" {
  type        = string
  description = "Environnement (dev, staging, production)"
  validation {
    condition     = contains(["dev", "staging", "production"], var.environment)
    error_message = "L'environnement doit être dev, staging ou production."
  }
}

variable "sku" {
  type    = string
  default = "B1"
}

resource "azurerm_service_plan" "main" {
  name                = "plan-${var.app_name}-${var.environment}"
  location            = var.location
  resource_group_name = var.resource_group_name
  os_type             = "Linux"
  sku_name            = var.sku

  tags = local.common_tags
}

resource "azurerm_linux_web_app" "main" {
  name                = "app-${var.app_name}-${var.environment}"
  location            = var.location
  resource_group_name = var.resource_group_name
  service_plan_id     = azurerm_service_plan.main.id

  site_config {
    always_on = var.environment == "production"

    application_stack {
      dotnet_version = "8.0"
    }
  }

  app_settings = var.app_settings

  tags = local.common_tags
}

output "app_url" {
  value = "https://${azurerm_linux_web_app.main.default_hostname}"
}

locals {
  common_tags = {
    Environment = var.environment
    ManagedBy   = "terraform"
    Application = var.app_name
  }
}

State Management

Backend distant (recommandé)

# backend.tf
terraform {
  backend "azurerm" {
    resource_group_name  = "rg-terraform-state"
    storage_account_name = "stterraformstate"
    container_name       = "tfstate"
    key                  = "myapp.dev.tfstate"
  }
}

Commandes utiles

terraform init              # Initialiser le backend et les providers
terraform plan -out=plan.tf # Planifier et sauvegarder
terraform apply plan.tf     # Appliquer le plan sauvegardé
terraform state list        # Lister les ressources dans le state
terraform state show        # Afficher une ressource spécifique
terraform import            # Importer une ressource existante

Bonnes pratiques

À faire

À éviter

Règles