هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
$ مستخدم عادي# بصلاحية root (أو مع sudo)
المهارات في هذا الفصل
- شرح البنية ككود وكيف يعمل Terraform عبر السحابات
Know what IaC is
Instead of clicking in a portal, you write the wanted state in files. A tool compares it with reality and makes the changes.
| By hand | With IaC |
|---|---|
| Steps in a wiki, done differently each time | The same files give the same result every time |
| No history of who changed what | Git history, pull requests, reviews |
| Hard to rebuild after a disaster | Rebuild the whole environment with one command |
| Test and production drift apart | One code base, different variables per environment |
تذكّر
Terraform is declarative: you describe what you want (3 VMs, one VNet), not how to create it. Terraform works out the order and the steps.
Know the advantages of IaC
IaC makes infrastructure faster, safer and cheaper to change.
- Repeatable: dev, test and prod from the same code.
- Reviewable: every change is a pull request with a plan.
- Documented: the code is the documentation.
- Testable: format, validate, scan for security problems before anything changes.
- Recoverable: rebuild after a disaster or a mistake.
- Cost control: destroy test environments every evening, create them again in the morning.
See how Terraform works with many platforms
Terraform talks to each platform through a provider (a plugin). The same language and workflow work for Azure, AWS, Google Cloud, Kubernetes, GitHub, DNS services, and hundreds more.
terraform {
required_providers {
azurerm = { source = "hashicorp/azurerm", version = "~> 4.0" }
github = { source = "integrations/github", version = "~> 6.0" }
}
}
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "web" {
name = "rg-web-dev"
location = "westeurope"
}
resource "github_repository" "infra" {
name = "infra-web"
visibility = "private"
}| Case | How Terraform helps |
|---|---|
| Multi-cloud | One tool and one workflow for several clouds |
| Hybrid cloud | Cloud resources and on-premises (VMware, network devices) in one plan |
| Service-agnostic | Not only clouds: DNS, monitoring, Git hosting, identity providers |
Compare Terraform with other tools
Each tool has a main job. They are often used together.
| Tool | Main job |
|---|---|
| Terraform / OpenTofu | Create and change infrastructure (any platform) |
| ARM / Bicep | Azure only (lesson) |
| CloudFormation | AWS only |
| Ansible | Configure servers (packages, files, services) |
| Packer | Build VM images |
في العمل
A common pattern: Packer builds the image, Terraform creates the VMs and network, Ansible (or cloud-init) configures what runs inside.
Install Terraform
Terraform is one binary. Install it from the HashiCorp repository.