Was ist Infrastructure as Code
Infrastrukturverwaltung durch Code
Infrastructure as Code (IaC) ist ein Ansatz zur Verwaltung und Bereitstellung von Infrastruktur mithilfe maschinenlesbarer Konfigurationsdateien anstelle manueller Konfiguration.
Vorteile
- Versionskontrolle — Infrastruktur in Git, Änderungshistorie
- Reproduzierbarkeit — überall dieselbe Umgebung
- Automatisierung — schnelle Bereitstellung ohne manuelle Aktionen
- Dokumentation — Code dient als Dokumentation
IaC-Tools
- Terraform — Cloud-agnostisch, deklarativ
- AWS CloudFormation — für AWS
- Pulumi — IaC in regulären Sprachen (Python, TypeScript)
- Ansible — Konfigurationsmanagement
Deklarativ vs Imperativ
- Deklarativ (Terraform): beschreibt gewünschten Zustand
- Imperativ (Skripte): beschreibt Schritte zur Erreichung
Praktiken
- Speicherung des Zustands in Remote-Speicher
- Module zur Wiederverwendung von Code
- CI/CD für automatische Anwendung
- Richtlinien und Prüfungen (OPA, Sentinel)
Terraform-Beispiel
resource "aws_instance" "web" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t2.micro"
}