| runme |
|
|---|
Création d'un bucket S3 de démo avec backend S3
aws s3api create-bucket \
--bucket tf-state-demo-zone-infra \
--region eu-west-3 \
--create-bucket-configuration LocationConstraint=eu-west-3cat main.tf
tf init
tf plan
tf applyTerminal B : tf apply (Le second apply échoue/attend : le state est verrouillé par le lock S3 natif) + idempotence
Suppression manuelle
aws s3 rb s3://tf-demo-zone-infra --forceDétéction du drift
tf plan # le bucket sera recréé
#tf apply👉 Terraform ne répare qu’au prochain plan/apply
Si on veut automatiser, il faut mettre en place un tf plan programmé dans un pipeline CI avec détection de code d'erreurs. Exemple :
- Exit 0 : aucun changement
- Exit 1 : erreur
- Exit 2 : drift détecté (diff entre code et réel)
Puis notification (Slack, e-mail, commentaire MR, création d’issue...)
Alternative : Aller sur des services managés (ex : Terraform Cloud)
Création d'un cluster kind
kind create clusterInstallation de Crossplane
helm repo add crossplane-stable https://charts.crossplane.io/stable
helm repo update
helm upgrade --install crossplane crossplane-stable/crossplane --namespace crossplane-system --create-namespace --waitAjout du Provider AWS
cat ./crossplane/provider.yaml
k apply -f ./crossplane/provider.yamlCréation du secret
kubectl --namespace crossplane-system \
create secret generic aws-creds \
--from-file creds=./aws-creds.confConfiguration du Provider AWS
cat ./crossplane/provider-config.yaml
k apply -f ./crossplane/provider-config.yamlCréation d'un bucket S3 de démo
cat ./crossplane/bucket.yaml
k apply -f ./crossplane/bucket.yaml
k klock bucketsOn peut : Afficher le détail du CRD
k explore buckets # plugin krewOn peut : Décrire comme n'importe quelle autre ressource
k get buckets tf-demo-zone-infra
k describe buckets tf-demo-zone-infraOn peut : Voir la composition
k tree buckets.s3.aws.m.upbound.io tf-demo-zone-infra # plugin krewSuppression manuelle
aws s3 rb s3://tf-demo-zone-infra --force👉 Quand tu supprimes le bucket manuellement : le contrôleur détecte l’écart et recrée automatiquement le bucket ➜ La source de vérité est l’API Kubernetes, maintenue par des controllers en boucle de réconciliation.