Commandes Terraform - Guide complet CLI IaC

Commandes & CLI 07/04/2026 10:00:00 angularforall.com
Terraform Iac Cli Commandes Devops Infrastructure

Référence complète des commandes Terraform : init, plan, apply, destroy, workspace, state, import et providers.

Description :

Initialise le répertoire de travail Terraform

Options :
  • -backend=false
  • -backend-config=path
  • -force-copy ⚠️
  • -from-module=source ⚠️
  • -get=false
  • -get-plugins=false
  • -input=false
  • -lock=false
  • -lock-timeout=0s
  • -migrate-state
  • -no-color
  • -plugin-dir=path
  • -reconfigure ⚠️
  • -upgrade

Description :

Prévisualise les changements à appliquer

Options :
  • -compact-warnings
  • -destroy
  • -detailed-exitcode
  • -generate-config-out=path
  • -input=false
  • -lock=false
  • -lock-timeout=0s
  • -no-color
  • -out=path
  • -parallelism=n
  • -refresh=false ⚠️
  • -refresh-only ⚠️
  • -replace=resource ⚠️
  • -target=resource
  • -var=foo=bar
  • -var-file=foo.tfvars ⚠️

Description :

Applique les changements pour atteindre l'état désiré

Options :
  • -auto-approve
  • -backup=path
  • -compact-warnings
  • -destroy
  • -input=false
  • -lock=false
  • -lock-timeout=0s
  • -no-color
  • -parallelism=n
  • -refresh=false ⚠️
  • -refresh-only ⚠️
  • -replace=resource ⚠️
  • -state=path
  • -state-out=path
  • -target=resource
  • -var=foo=bar
  • -var-file=foo.tfvars ⚠️

Description :

Détruit toute l'infrastructure gérée par Terraform

Options :
  • -auto-approve
  • -backup=path
  • -compact-warnings
  • -input=false
  • -lock=false
  • -lock-timeout=0s
  • -no-color
  • -parallelism=n
  • -refresh=false ⚠️
  • -state=path
  • -state-out=path
  • -target=resource
  • -var=foo=bar
  • -var-file=foo.tfvars ⚠️

Description :

Valide les fichiers de configuration Terraform

Options :
  • -json
  • -no-color

Description :

Formate les fichiers .tf selon le style canonique

Options :
  • -check
  • -diff
  • -list=false
  • -no-color
  • -recursive ⚠️
  • -write=false

Description :

Affiche les valeurs des outputs du state

Options :
  • -json
  • -no-color
  • -raw ⚠️
  • -state=path

Description :

Affiche le state ou le plan en format lisible

Options :
  • -json
  • -no-color

Description :

Liste les ressources dans le state Terraform

Options :
  • -id=ID
  • -state=path

Description :

Affiche les attributs d'une ressource du state

Options :
  • -no-color
  • -state=path

Description :

Déplace une ressource dans le state

Options :
  • -backup=path
  • -backup-out=path
  • -dry-run ⚠️
  • -lock=false
  • -lock-timeout=0s
  • -no-color
  • -state=path
  • -state-out=path

Description :

Supprime des ressources du state sans les détruire

Options :
  • -backup=path
  • -dry-run ⚠️
  • -lock=false
  • -lock-timeout=0s
  • -no-color
  • -state=path
  • -state-out=path

Description :

Importe une ressource existante dans le state

Options :
  • -allow-missing-config
  • -backup=path
  • -config=path
  • -input=false
  • -lock=false
  • -lock-timeout=0s
  • -no-color
  • -parallelism=n
  • -state=path
  • -state-out=path
  • -var=foo=bar
  • -var-file=foo.tfvars ⚠️

Description :

Liste tous les workspaces disponibles

Options :
  • -no-color
  • -state=path

Description :

Crée un nouveau workspace Terraform

Options :
  • -lock=false
  • -lock-timeout=0s
  • -no-color
  • -state=path

Description :

Sélectionne un workspace existant

Options :
  • -no-color
  • -or-create

Description :

Supprime un workspace Terraform

Options :
  • -force ⚠️
  • -lock=false
  • -lock-timeout=0s
  • -no-color

Description :

Synchronise le state avec l'infrastructure réelle

Options :
  • -backup=path
  • -compact-warnings
  • -input=false
  • -lock=false
  • -lock-timeout=0s
  • -no-color
  • -parallelism=n
  • -state=path
  • -state-out=path
  • -target=resource
  • -var=foo=bar
  • -var-file=foo.tfvars ⚠️

Description :

Marque une ressource pour recréation au prochain apply

Options :
  • -allow-missing
  • -backup=path
  • -ignore-remote-version ⚠️
  • -lock=false
  • -lock-timeout=0s
  • -no-color
  • -state=path
  • -state-out=path

Description :

Retire la marque taint d'une ressource

Options :
  • -allow-missing
  • -backup=path
  • -lock=false
  • -lock-timeout=0s
  • -no-color
  • -state=path
  • -state-out=path

Description :

Génère un graphe de dépendances des ressources

Options :
  • -draw-cycles
  • -no-color
  • -plan=path
  • -type=plan

Description :

Affiche les providers requis par la configuration

Options :
  • -no-color

Description :

Verrouille les versions des providers dans .terraform.lock.hcl

Options :
  • -fs-mirror=path ⚠️
  • -net-mirror=url
  • -no-color
  • -platform=os_arch

Description :

Affiche la version de Terraform installée

Options :
  • -json

Description :

Lance une console interactive pour évaluer des expressions

Options :
  • -no-color
  • -plan=path
  • -state=path
  • -var=foo=bar
  • -var-file=foo.tfvars ⚠️

Description :

Libère manuellement un verrou de state bloqué

Options :
  • -force ⚠️
  • -no-color

Description :

Authentifie auprès de Terraform Cloud ou Enterprise

Options :
  • -no-color

Description :

Supprime les credentials stockés localement

Options :
  • -no-color

Description :

Télécharge et installe les modules référencés

Options :
  • -no-color
  • -update

Description :

Exécute les tests d'intégration Terraform (.tftest.hcl)

Options :
  • -cloud-run=module ⚠️
  • -filter=file ⚠️
  • -json
  • -no-color
  • -test-directory=path
  • -var=foo=bar
  • -var-file=foo.tfvars ⚠️
  • -verbose

Partager