Skip to content

Cours - backends

Les backends sont les intégrations terraform pour stocker l’état (terraform.tfstate) de façon idéalement distante, partagée et avec un mechanisme de verrouillage excluant la modification concurrente.

  • s3 - Amazon S3 avec verrouillage DynamoDB
backend "s3" {
bucket = "my-terraform-state"
key = "path/to/terraform.tfstate"
region = "us-east-1"
}
  • azurerm - Azure Blob Storage avec verrouillage natif
backend "azurerm" {
resource_group_name = "StorageAccount-ResourceGroup"
storage_account_name = "abcd1234"
container_name = "tfstate"
key = "prod.terraform.tfstate"
}

Autres providers de cloud.

  • pg - PostgreSQL
backend "pg" {
conn_str = "postgres://user:pass@db.example.com/terraform_backend?sslmode=require"
}
  • kubernetes - Kubernetes Secret
backend "kubernetes" {
secret_suffix = "state"
config_path = "~/.kube/config"
}
  • local - Système de fichiers local (défaut)
backend "local" {
path = "terraform.tfstate"
}
  • remote - Terraform Cloud/Enterprise
backend "remote" {
organization = "example_corp"
workspaces {
name = "my-app-prod"
}
}
  • http - Backend HTTP générique
backend "http" {
address = "https://myrest.api.com/foo"
lock_address = "https://myrest.api.com/foo"
unlock_address = "https://myrest.api.com/foo"
}

MinIO (S3-compatible) :

backend "s3" {
endpoint = "https://minio.example.com"
bucket = "terraform-state"
key = "terraform.tfstate"
skip_credentials_validation = true
skip_metadata_api_check = true
skip_region_validation = true
force_path_style = true
}