انتقل إلى المحتوى
أمين أبوزيد
MID-058

البنية التحتية كشيفرة (Infrastructure as Code)

  • 6 درس
  • 3 ساعة تدريب (تقدير)
في هذه الصفحة 8 موضوعات

نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.

نظرة عامة

الموضوعات

  • أساسيات Terraform
  • الحالة (state)
  • الوحدات (modules)
  • تغييرات قابلة للمراجعة

تعلّم أولًا

3 ساعة تدريب (تقدير)

مخرجات التعلم

  1. Describe infrastructure declaratively with Terraform and apply changes through plan and review.
  2. Manage remote state with locking and explain state drift.
  3. Structure configuration into reusable modules and environments.
  4. Run Terraform from CI with reviewable plans.

الدروس

  1. 01لماذا نستخدم البنية التحتية كشيفرة
  2. 02أساسيات Terraform
  3. 03الحالة والانحراف (State and drift)
  4. 04الوحدات والبيئات
  5. 05Terraform في CI
  6. 06عرض عملي: إعادة بناء البنية التحتية التي أُنشئت يدويًا كشيفرة

المختبر والتمارين

Lab

MID-058-LAB1 · Shop infrastructure

Outcomes: 1–4 · Time: ~3 h Rebuild the MID-056 environment in Terraform: modules for network, database, and storage; separate dev and staging environments; remote state with locking; a pipeline that runs fmt, validate, and plan on pull requests and posts the plan. Acceptance: destroy and recreate the environment from code alone.

Exercises (assessment: plan review exercise)

IDOutcomeTask
MID-058-EX011Write a Terraform resource for a private object-storage bucket and run plan.
MID-058-EX021Review a given plan: identify the destructive change and propose a safer path.
MID-058-EX032Configure a remote backend with locking and explain what drift is with an example.
MID-058-EX043Refactor one root module into network and database modules with inputs and outputs.
MID-058-EX053Design the folder layout for dev, staging, and prod with separate state.
MID-058-EX064Write the pipeline stages for pull requests and for merge, including approval for prod.
أظهر الحلول
  • EX01 Bucket resource with a private ACL or block-public-access setting; init, then plan shows one resource to add.
  • EX02 A resource with -/+ (forced replacement) on the database means data loss; change the argument that forces replacement, or use a migration or lifecycle { prevent_destroy = true }.
  • EX03 Backend block pointing to remote storage with a lock table or equivalent; drift: someone widens a security group in the console, and the next plan shows the difference.
  • EX04 Move resources into modules/network and modules/database, expose outputs such as private_subnet_ids, and wire them in the environment root.
  • EX05 modules/*, envs/dev, envs/staging, envs/prod, each with its own backend key.
  • EX06 PR: fmt, validate, security scan, plan posted as a comment. Merge: apply the saved plan; production requires approval.

Outcome 4 is also covered by the lab criterion (plans on PRs) and quiz Q09–Q10.

الاختبار

Outcomes: O1 declarative IaC and plan · O2 state and drift · O3 modules and environments · O4 Terraform in CI.

اختبار ذاتي لك: لا توجد درجات، ولا يُحفظ أو يُرسل أي شيء. اختر إجابة ثم تحقق منها، ويمكنك المحاولة مرة أخرى كما تشاء.

  1. 1The main benefit of infrastructure as code is:O1
  2. 2terraform plan does:O1
  3. 3A resource shown with -/+ in a plan means:O1
  4. 4Why use remote state with locking?O2
  5. 5Drift is:O2
  6. 6State files may contain:O2
  7. 7A module is:O3
  8. 8Separate state per environment gives:O3
  9. 9In CI, the plan should be:O4
  10. 10Manual console changes should be:O4

الجزء العملي

Plan review (MID-058-EX02) plus lab MID-058-LAB1. Pass: quiz at least 8/10, remote state with locking, plans posted on PRs, and a full destroy and recreate from code alone.

أخطاء شائعة

Local state files; manual changes in the console; one giant root module.

التقييم

Plan review exercise.

الصلة بالمسار الوظيفي

Infrastructure governance (ARC-020).

اكتب للبحث في المستويات والمراحل والوحدات والدروس.