Mengautomasi workflow Terraform menggunakan CI/CD pipeline — dari plan otomatis hingga policy enforcement dan drift detection.
Apa yang Akan Dipelajari? #
CI/CD pipeline memastikan setiap perubahan infrastruktur melalui proses review, testing, dan approval yang konsisten. Section ini membahas berbagai aspek automasi Terraform termasuk pipeline design, approval workflow, policy as code, dan Terraform Cloud.
Artikel dalam Section Ini #
| Artikel | Topik Utama |
|---|---|
| CI Pipeline | Membangun pipeline dasar untuk terraform plan dan validate |
| Plan Approval Strategy | Strategi approval sebelum apply ke production |
| Automated Apply | Mengautomasi apply untuk environment tertentu |
| Policy as Code | Menggunakan Sentinel, OPA, dan tfsec untuk enforce kebijakan |
| Drift Detection Automation | Mendeteksi perubahan di luar Terraform secara otomatis |
| Terraform Cloud | Menggunakan Terraform Cloud/HCP untuk managed workflow |
CI/CD Pipeline Flow #
flowchart TD
A["Developer<br/>Push Code"] --> B["CI Pipeline<br/>Triggered"]
B --> C["terraform fmt -check"]
C --> D["terraform validate"]
D --> E["terraform plan"]
E --> F["Security Scan<br/>tfsec, checkov"]
F --> G{"Policy<br/>Check"}
G -->|"Pass"| H{"Manual<br/>Approval?"}
G -->|"Fail"| I["Block &<br/>Notify"]
H -->|"Approved"| J["terraform apply"]
H -->|"Rejected"| I
J --> K["Post-Deploy<br/>Tests"]
K --> L["Notify Team"]
style B fill:#e3f2fd
style J fill:#c8e6c9
style I fill:#ffcdd2
style L fill:#e8f5e9Approval Strategies #
flowchart LR
subgraph Auto["Auto-Apply"]
A_DEV["Dev Environment<br/>Auto apply on merge"]
end
subgraph Semi["Semi-Auto"]
A_STG["Staging<br/>Auto plan, manual approve"]
end
subgraph Manual["Full Manual"]
A_PROD["Production<br/>Manual plan + approve"]
end
Auto --> Semi --> Manual
style Auto fill:#e8f5e9
style Semi fill:#fff3e0
style Manual fill:#ffebeePolicy as Code Stack #
flowchart TD
subgraph Validation["Validation Layer"]
FMT["terraform fmt<br/>Format check"]
VAL["terraform validate<br/>Syntax check"]
end
subgraph Security["Security Layer"]
TFSEC["tfsec<br/>Security scan"]
CHECKOV["Checkov<br/>Compliance check"]
end
subgraph Policy["Policy Layer"]
SENTINEL["Sentinel<br/>HashiCorp policy"]
OPA["OPA/Rego<br/>Open policy"]
end
Validation --> Security --> Policy
style Validation fill:#e3f2fd
style Security fill:#fff3e0
style Policy fill:#f3e5f5CI/CD pipeline adalah tulang punggung Terraform di production. Lanjutkan ke Security untuk mempelajari best practice keamanan.