一鍵部署
Vibe Prompt
「幫我用 Terraform 建立完整的 Web 服務架構:VPC + ALB + ECS Fargate + RDS。」
# main.tf - 完整 Web 架構
module "vpc" {
source = "./modules/vpc"
vpc_cidr = "10.0.0.0/16"
environment = "production"
public_subnets = ["10.0.1.0/24", "10.0.2.0/24"]
private_subnets = ["10.0.10.0/24", "10.0.20.0/24"]
}
resource "aws_ecs_cluster" "main" {
name = "web-cluster"
}
resource "aws_ecs_service" "web" {
name = "web-service"
cluster = aws_ecs_cluster.main.id
task_definition = aws_ecs_task_definition.web.arn
desired_count = 2
launch_type = "FARGATE"
network_configuration {
subnets = module.vpc.public_subnet_ids
security_groups = [aws_security_group.web.id]
assign_public_ip = true
}
}
resource "aws_db_instance" "main" {
engine = "postgres"
instance_class = "db.t3.micro"
allocated_storage = 20
db_name = "myapp"
username = "admin"
password = var.db_password
skip_final_snapshot = true
db_subnet_group_name = aws_db_subnet_group.main.name
}
output "alb_dns" {
value = aws_lb.main.dns_name
}
課程總結
Terraform 課程完成!
- ✅ HCL 語法
- ✅ 遠端 State
- ✅ Modules
- ✅ 多環境
- ✅ 一鍵部署