Memahami siklus kerja Terraform dari inisialisasi hingga destroy. Setiap tahap memiliki peran penting dalam memastikan infrastruktur dikelola dengan aman dan konsisten.

Apa yang Akan Dipelajari? #

Terraform memiliki workflow yang terstruktur dan berulang. Memahami setiap tahap — init, plan, apply, dan destroy — serta konsep idempotency dan drift detection adalah kunci untuk mengelola infrastruktur dengan percaya diri.

Artikel dalam Section Ini #

ArtikelTopik Utama
InitInisialisasi proyek, download provider dan module
PlanPreview perubahan sebelum diterapkan — tahap kritis untuk review
ApplyMenerapkan perubahan ke infrastruktur aktual
DestroyMenghapus semua resource yang dikelola Terraform
Execution PlanMemahami detail output plan secara mendalam
IdempotencyMenjalankan apply berkali-kali tanpa perubahan yang tidak diinginkan
Drift DetectionMendeteksi perubahan di luar Terraform (manual changes)

Workflow Lifecycle #

flowchart TD
    A["<b>terraform init</b><br/>Inisialisasi proyek"] --> B["<b>terraform plan</b><br/>Preview perubahan"]
    B --> C{"Review<br/>Plan"}
    C -->|"Approve"| D["<b>terraform apply</b><br/>Terapkan perubahan"]
    C -->|"Reject"| E["Edit<br/>Configuration"]
    E --> B
    D --> F{"Perlu<br/>Cleanup?"}
    F -->|"Ya"| G["<b>terraform destroy</b><br/>Hapus semua resource"]
    F -->|"Tidak"| H["Monitoring &<br/>Drift Detection"]
    H --> I{"Drift<br/>Detected?"}
    I -->|"Ya"| E
    I -->|"Tidak"| H

    style A fill:#e1f5fe
    style G fill:#ffebee
    style H fill:#c8e6c9

Perbandingan Tahap #

flowchart LR
    subgraph Safe["Safe Operations"]
        init["init<br/>Tidak mengubah infra"]
        plan["plan<br/>Read-only, preview only"]
    end

    subgraph Destructive["Potentially Destructive"]
        apply["apply<br/>Membuat/mengubah resource"]
        destroy["destroy<br/>Menghapus resource"]
    end

    init --> plan
    plan --> apply
    apply --> destroy

    style Safe fill:#e8f5e9
    style Destructive fill:#fff3e0

Best Practice: Selalu Plan Sebelum Apply #

# Workflow yang benar
terraform init        # Sekali saja (atau saat ada perubahan provider/module)
terraform plan        # SELALU jalankan dulu
terraform apply       # Hanya setelah review plan
terraform destroy     # Hanya saat yakin ingin menghapus

Setelah memahami workflow, lanjutkan ke section Concept untuk mendalami konsep deklaratif dan state management.

About | Author | Content Scope | Editorial Policy | Privacy Policy | Disclaimer | Contact