DevOps Exercise

Todo list

  • AWS Management

    • IAM - Roles, Account, …
    • Có tạo ROLE không? Cho từng môi trường
    • Billings
    • Split environment: Dev/STG/PRD
    • Tạo batision host acc
  • AWS terraform

  • GitOps

Tool hỗ trợ

  • aws-nuke - Xóa toàn bộ AWS resource (cho Dev/Test)
  • tflint + terraform fmt
  • checkov - Scan security misconfig (compliance check)
  • Infracost - Ước tính chi phí từ Terraform plan

Step by step

  • Tạo tài khoản root, bật MFA

  • Tạo user mới terraform-deployer, cấp quyền AdministratorAccess tạm thời.

  • Đăng nhập vào terraform-deployer, assign MFA, download access key, setup with aws-vault

  • Init code cho aws-basecamp-admin

    • Tìm cấu trúc cho thư mục

    • Init s3 backend

Tạo riêng cho từng ENVs, chạy terraform sẽ trong này Các thư mục module thì là code từng services, dùng thằng nào thì sẽ lấy từ thằng đó requrie ra bên ngoài

Trong mỗi folder envs/ thì settings variable tương ứng với từng môi trường.

envs/

general monitoring database backend frontend

Notes

resource "aws_s3_bucket" "terraform_state" {
               # ↑ Type    ↑ Name
  bucket = var.bucket_name
  # ↑ Attribute = Value
}

Working Philosophy: Automate what can be automated, minimize human error, and enhance efficiency.

Terraform - AWS latest doc

https://www.terraform-best-practices.com/key-concepts https://developer.hashicorp.com/terraform/language


  • Tạo tài khoản terraform-user Cấp quyền to vào =))
  • Config để chạy aws cli ở local. Add new profile (screenshot-service-prd) with credentials
  • Chạy ./pre-build.sh để tạo s3 backend: echo -e "screenshot-service\nprd\nus-east-1" | ./pre-build.sh

4. Create symlinks for shared variables:
  # For all services in staging
  make symlink_all e=stg

  # Or for specific service
  make symlink e=stg s=general

  5. Now you can initialize Terraform:
  # Initialize specific service
  make init e=stg s=general

  # Or initialize all services
  make init_all e=stg

  6. Plan and apply your VPC design:
  make plan e=stg s=general
  make apply e=stg s=general
make symlink e=prd s=general
make init e=prd s=general
make plan e=prd s=general
make apply -----

Learn: output sẽ được lưu trên s3, hoặc lưu local ở .terraform. terraform output -state=terraform/envs/prd/1.general/terraform.tfstate