Skip to main content

What is HCP?

HCP (HashiCorp Cloud Platform) = managed cloud service โดย HashiCorp ที่ provide Terraform Cloud, Vault, Consul, Boundary, Packer, Waypoint ในที่เดียว

HCP Platform

Terraform Cloud (TFC) — ส่วนสำคัญที่สุด

managed Terraform service:

  • Remote state — เก็บ state ใน HashiCorp infra
  • Remote runs — apply ใน HashiCorp ไม่ใช่ laptop
  • VCS integration — auto plan ตาม PR
  • Policy as Code (Sentinel)
  • Private module registry
  • Run tasks — integrate third-party tools (security scanners, cost)
  • Workspaces — organize state by project/env

Pricing Tiers

TierFreeStandardPlusEnterprise
Users5UnlimitedUnlimitedUnlimited
WorkspacesFree 500$$$$$Self-hosted
Sentinel
Run Tasks
SSO
Audit logs
Private modules

ดู pricing ล่าสุดที่ hashicorp.com/products/terraform/pricing

When to Use HCP?

✅ ใช้ HCP เมื่อ:

  • ทีม > 5 คนที่ใช้ Terraform
  • ต้องการ centralized state management
  • ต้องการ VCS-driven workflow
  • ต้องการ Policy as Code (Sentinel)
  • ไม่อยาก self-host backend infrastructure
  • ต้องการ private module registry

❌ ไม่ต้อง HCP เมื่อ:

  • 1-2 คนใช้ Terraform
  • ทุกอย่างใน 1 cloud (ใช้ S3 backend ก็พอ)
  • Budget จำกัด
  • มี infrastructure ของตัวเองพร้อม (S3 + DynamoDB + GitHub Actions)

เปรียบเทียบ: TFC vs Self-Hosted

FeatureTerraform Cloud (HCP)Self-Hosted (S3 + GitHub Actions)
Setup5 นาที1 ชั่วโมง
State backendBuilt-inManual setup S3 + DynamoDB
VCS integrationBuilt-inGitHub Actions yaml
Sentinel✅ Easy❌ Need OPA + integrate
Run UI✅ Beautiful❌ GitHub logs
CostPer workspace/userCloud bill (S3, DynamoDB)
Vendor lock-inHighLow
CustomizationLimitedFull control

Sign Up

  1. Go to app.terraform.io
  2. Sign up (free tier)
  3. Create organization
  4. Create first workspace

Connect VCS

Settings → VCS Providers → Connect GitHub/GitLab/Bitbucket

Workspace → Settings → Version Control
└── Repository: myorg/my-terraform-repo
Branch: main
Auto-apply: false
Working directory: ./envs/prod

CLI-Driven vs VCS-Driven

CLI-Driven (similar to local Terraform)

terraform {
cloud {
organization = "my-org"
workspaces {
name = "prod-network"
}
}
}
terraform login    # one-time auth
terraform init
terraform apply # runs in HCP, output shown locally

VCS-Driven (auto on PR/push)

  • Workspace connected to GitHub
  • PR → auto plan + comment
  • Merge → auto apply (or manual approve)

Run Triggers

Workspace A เปลี่ยน → trigger workspace B apply:

Settings → Run Triggers → Source Workspace: prod-network

ใช้ตอน: app workspace ขึ้นกับ network workspace

Private Module Registry

Publish modules ของ org:

module "vpc" {
source = "app.terraform.io/my-org/vpc/aws" # private registry
version = "1.0.0"
}

Sentinel Policy

Org-wide policies ที่ enforce ก่อน apply:

sentinel.hcl
policy "no-public-s3" {
source = "./policies/no-public-s3.sentinel"
enforcement_level = "hard-mandatory"
}

ดูเพิ่มใน Section 18: Compliance & Sentinel

Run Tasks

Integrate third-party services ระหว่าง plan-apply:

ServiceUse Case
SnykSecurity scan
BridgecrewCompliance
InfracostCost estimation
LightlyticsDrift detection
Settings → Run Tasks → Add → Snyk
└── Endpoint: https://...
HMAC Key: ***

→ ทุก plan จะเรียก Snyk → ผลปรากฏใน Run UI

Audit Logs

Standard tier+: ดู:

  • ใคร trigger run
  • Plan/apply history
  • Variable changes
  • Workspace settings changes

SSO

Plus tier+: Connect SAML/OIDC:

  • Okta
  • Azure AD
  • Google Workspace
  • OneLogin

→ ผู้ใช้ org sign in ผ่าน corporate IdP

Terraform Enterprise (Self-Hosted)

ใช้ HCP บน infrastructure ของตัวเอง:

  • Same features as HCP Plus
  • Air-gapped deployment supported
  • Bring your own database (Postgres)
  • ใช้กับ regulated industries (banking, government)

ทางเลือก

ServiceVendorNotes
HCP TerraformHashiCorpOriginal, most features
env0env0Cheaper, similar features
SpaceliftSpaceliftStrong on policy + GitOps
ScalrScalrMulti-tenant, RBAC focus
AtlantisOpen-sourceFree, self-host
Self-built (S3 + GitHub Actions)DIYMost flexible, most work

ตัวอย่าง: Migrate to HCP

Step 1: Create Workspace

# In HCP UI: New Workspace → CLI-Driven

Step 2: Add Cloud Block

terraform {
cloud {
organization = "my-org"
workspaces {
name = "prod-network"
}
}
}

Step 3: Login + Init

terraform login
terraform init
# → migrate state from S3 to HCP

Step 4: Set Variables in HCP UI

Workspace → Variables → Add:

  • aws_access_key_id (sensitive)
  • aws_secret_access_key (sensitive)
  • region (terraform variable)

Step 5: Run Apply

terraform apply
# → runs in HCP, output streams to laptop

Pros & Cons

Pros ✅

  • Easy setup (no S3 bootstrap)
  • Beautiful UI for plans/applies
  • VCS-driven workflow
  • Sentinel + private modules
  • SSO + audit logs (paid tiers)

Cons ❌

  • Cost (above free tier)
  • Vendor lock-in
  • Need internet to apply (vs offline self-hosted)
  • BUSL license concerns (some enterprises avoid)

OpenTofu Alternative

OpenTofu = open-source fork ของ Terraform — รองรับ TFC backend ได้ส่วนใหญ่:

terraform {
cloud {
organization = "my-org"
workspaces { name = "prod" }
}
}
tofu init
tofu apply

(บาง edge case ของ Sentinel / TFC features อาจไม่ work)

สรุป

  • HCP = HashiCorp's managed cloud platform
  • Terraform Cloud (TFC) = managed Terraform service
  • มี Free tier สำหรับ ทีม < 5 คน
  • 2 modes: CLI-driven + VCS-driven
  • Features: state management, run UI, Sentinel, private modules, run tasks
  • ทางเลือก: env0, Spacelift, Atlantis, self-hosted
  • เหมาะกับ ทีม ≥5 คน ที่ใช้ Terraform จริงจัง

ต่อไป → Enterprise Features