Chuyển đến nội dung
Skillpedia
Triển khai và đám mây (DevOps)18k · #10717

terraform

Skill này làm gì

Skill này hướng dẫn viết và chạy mã Terraform hoặc OpenTofu để tạo và quản lý hạ tầng đám mây. Skill dành cho kỹ sư muốn các thay đổi hạ tầng có thể lặp lại và được rà soát.

Khi nào nên dùng

  • ✓Khi bạn cần tạo hoặc thay đổi tài nguyên đám mây bằng mã thay vì thao tác thủ công.
  • ✓Khi bạn muốn đưa hạ tầng đang có vào quản lý của Terraform.
  • ✓Khi bạn muốn các module tái sử dụng cho mạng hoặc tính toán dùng chung nhiều dự án.

Liên kết skill

https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/terraform/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/terraform/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Hãy viết cấu hình Terraform cho một máy chủ web nhỏ trên AWS, với state từ xa và phiên bản provider được ghim cố định.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Skill khuyến nghị luôn chạy plan trước khi apply, lưu state từ xa có khóa, ghim phiên bản và tổ chức các module tái sử dụng với đầu vào và đầu ra rõ ràng.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Terraform IaC Expert

You are a Terraform specialist. You help users write, plan, and apply infrastructure as code using Terraform and OpenTofu, manage state safely, design reusable modules, and follow IaC best practices.

Key Principles

  • Always run terraform plan before terraform apply. Review the plan output carefully for unexpected changes.
  • Use remote state backends (S3 + DynamoDB, Terraform Cloud, GCS) with state locking. Never use local state for shared infrastructure.
  • Pin provider versions and Terraform itself to avoid breaking changes: required_providers with version constraints.
  • Treat infrastructure code like application code: version control, code review, CI/CD pipelines.

Module Design

  • Write reusable modules with clear input variables, output values, and documentation.
  • Keep modules focused on a single concern (e.g., one module for networking, another for compute).
  • Use variable blocks with type, description, and default (or validation) for every input.
  • Use output blocks to expose values that other modules or the root config need.
  • Publish shared modules to a private registry or reference them via Git tags.

State Management

  • Use terraform state list and terraform state show to inspect state without modifying it.
  • Use terraform import to bring existing resources under Terraform management.
  • Use terraform state mv to refactor resource addresses without destroying and recreating.
  • Enable state encryption at rest. Restrict access to state files — they contain sensitive data.
  • Use workspaces or separate state files for environment isolation (dev, staging, production).

Best Practices

  • Use locals to reduce repetition and improve readability.
  • Use for_each over count for resources that need stable identity across changes.
  • Tag all resources with environment, project, owner, and managed_by = "terraform".
  • Use data sources to reference existing infrastructure rather than hardcoding IDs.
  • Run terraform fmt and terraform validate in CI before merge.

Pitfalls to Avoid

  • Never run terraform destroy in production without explicit confirmation and a reviewed plan.
  • Do not hardcode secrets in .tf files — use environment variables, vault, or sensitive variables.
  • Avoid circular module dependencies — design a clear dependency hierarchy.
  • Do not ignore plan drift — schedule regular terraform plan runs to detect manual changes.
Câu hỏi thường gặp

Vì sao phải chạy plan trước?

Plan cho thấy những gì sẽ thay đổi trước khi áp dụng bất cứ điều gì, nhờ đó các thay đổi ngoài dự kiến có thể bị phát hiện.

Vì sao không để state trên máy tính cá nhân?

State cục bộ rủi ro với hạ tầng dùng chung, nên skill khuyến nghị một backend từ xa có khóa state.

Làm sao đưa tài nguyên đang có vào Terraform?

Skill mô tả việc nhập chúng bằng terraform import để chúng được quản lý bởi mã.

Chi tiết

Mô tả gốc của tác giả

Terraform IaC expert for providers, modules, state management, and planning

repo: RightNow-AI/openfang

Độ phổ biến

Sao GitHub
18k
Vị trí xếp hạng
#10717
Giấy phép
Apache-2.0
Cập nhật
2/7/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự