الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

الفصل 2الاسم في الدورة: Objective 2: Terraform fundamentals

Install and use providers, and understand state

Providers are the plugins that let Terraform talk to a platform's API. State is Terraform's memory of what it built. This chapter shows how to choose and pin provider versions, use several providers and aliases, and why state matters.

  • 5 الدروس
  • 3 الأوامر

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

$ مستخدم عادي# بصلاحية root (أو مع sudo)

المهارات في هذا الفصل

  • تثبيت المزوّدين وتحديد إصداراتهم واستخدامهم (وعدة مزوّدين)

2.1

Install and pin providers

Declare providers in required_providers with a source and a version constraint. terraform init downloads them and writes the exact versions into .terraform.lock.hcl.

versions.tf
terraform {
  required_version = ">= 1.12"
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "~> 4.20"
    }
    random = {
      source  = "hashicorp/random"
      version = ">= 3.6, < 4.0"
    }
  }
}
ConstraintAllows
= 4.20.0Only this version
>= 4.20This and newer
~> 4.204.20 and newer 4.x (not 5.0)
~> 4.20.14.20.1 and newer 4.20.x
>= 3.6, < 4.0A range
terraform init
terraform init -upgrade
terraform providers
terraform version

تذكّر

Commit .terraform.lock.hcl to Git, so every person and the pipeline use the same provider versions. Do not commit the .terraform/ folder.

الأوامر في هذا الدرس

2.2

Know how Terraform uses providers

A provider turns resources in your code into API calls (create, read, update, delete). Each provider brings its own resource types and data sources.

  • Names are TYPE_NAME: azurerm_virtual_network, aws_s3_bucket, kubernetes_namespace.
  • The source address is HOSTNAME/NAMESPACE/TYPE — registry.terraform.io/hashicorp/azurerm (the hostname is usually left out).
  • Tiers in the Terraform Registry: official (HashiCorp), partner, community.

2.3

Use several providers and aliases

One configuration can use many providers — and the same provider several times with different settings, using an alias.

providers.tf
provider "azurerm" {
  features {}
  subscription_id = var.sub_prod
}
 
provider "azurerm" {
  alias           = "dr"
  features {}
  subscription_id = var.sub_dr
}
 
resource "azurerm_resource_group" "dr" {
  provider = azurerm.dr
  name     = "rg-web-dr"
  location = "northeurope"
}

نصيحة للامتحان

Without provider = …, a resource uses the default (un-aliased) provider of its type.

2.4

Log in providers safely

Never write passwords or keys in .tf files. Use the platform's normal login or environment variables.

az login
export ARM_SUBSCRIPTION_ID=00000000-0000-0000-0000-000000000000
export ARM_USE_OIDC=true

In pipelines, use OIDC (workload identity federation): no secret is stored at all — see Deploy to Azure with OIDC.

الأوامر في هذا الدرس

2.5

Understand state

Terraform saves what it created in a state file (terraform.tfstate): the mapping between your code and the real resource IDs, plus their attributes.

State is used toExample
Map code to real objectsazurerm_resource_group.web = /subscriptions/…/resourceGroups/rg-web-dev
Know what to change or deleteA resource removed from code → destroy it
Speed up plansCached attributes
Track dependenciesDestroy in the right order
terraform state list
terraform show

انتبه

State can contain secrets in plain text (passwords, keys). Store it in a protected remote backend, never in Git. More: Manage state.

الأوامر في هذا الدرس

كل الأوامر في هذا الفصل