Phase 6 - Infrastructure as Code¶
Objectif¶
Automatiser le provisionnement de l'infrastructure OpenStack avec Terraform et la configuration avec Ansible.
Architecture IaC¶
graph LR
dev["👤 DevOps Engineer"]
ci["🔄 GitLab CI/CD"]
git["📁 Git Repository"]
terraform["🏗️ Terraform"]
ansible["⚙️ Ansible"]
openstack["☁️ OpenStack"]
dev -->|Push code| git
ci -->|Trigger on push| git
ci -->|terraform apply| terraform
ci -->|ansible-playbook| ansible
terraform -->|API calls| openstack
ansible -->|Configure VMs| openstack
Sujets de cette phase¶
| # | Sujet | Description | Durée estimée |
|---|---|---|---|
| 01 | Terraform Provider | Configuration OpenStack | 2-3 heures |
| 02 | Modules réseau | Networks, subnets, security | 3-4 heures |
| 03 | Modules compute | Instances, volumes | 3-4 heures |
| 04 | Ansible post-deploy | Configuration VMs | 2-3 heures |
| 05 | Pipelines CI/CD | GitOps automation | 3-4 heures |
Structure projet Terraform¶
terraform/
├── environments/
│ ├── dev/
│ │ ├── main.tf
│ │ ├── variables.tf
│ │ └── terraform.tfvars
│ └── prod/
├── modules/
│ ├── network/
│ │ ├── main.tf
│ │ ├── variables.tf
│ │ └── outputs.tf
│ ├── compute/
│ └── security/
└── README.md
Exemple Terraform¶
# main.tf
terraform {
required_providers {
openstack = {
source = "terraform-provider-openstack/openstack"
version = "~> 2.0"
}
}
}
provider "openstack" {
cloud = "mycloud" # Référence clouds.yaml
}
module "network" {
source = "../modules/network"
environment = var.environment
cidr = "10.10.0.0/24"
}
module "web_servers" {
source = "../modules/compute"
count = 3
name = "web-${count.index + 1}"
flavor = "m1.small"
image = "Ubuntu 24.04"
network_id = module.network.network_id
security_groups = [module.security.web_sg_id]
}
Checkpoint de validation¶
- Provider Terraform configuré
- Modules réseau et compute fonctionnels
- Déploiement d'infrastructure en une commande
- Pipeline CI/CD opérationnel