← スキル一覧に戻る

terraform
by htlin222
terraformは、other分野における実用的なスキルです。複雑な課題への対応力を強化し、業務効率と成果の質を改善します。
⭐ 66🍴 4📅 2026年1月23日
SKILL.md
name: terraform description: Write Terraform modules, manage state, and implement IaC. Use for infrastructure automation or state management.
Terraform
Infrastructure as Code with Terraform.
When to Use
- Creating infrastructure modules
- Managing Terraform state
- Multi-environment deployments
- Importing existing resources
- Troubleshooting drift
Module Structure
modules/
└── vpc/
├── main.tf # Resources
├── variables.tf # Input variables
├── outputs.tf # Output values
└── versions.tf # Provider requirements
Best Practices
Variables
variable "environment" {
description = "Environment name"
type = string
validation {
condition = contains(["dev", "staging", "prod"], var.environment)
error_message = "Environment must be dev, staging, or prod."
}
}
variable "tags" {
description = "Resource tags"
type = map(string)
default = {}
}
Resources
resource "aws_instance" "main" {
ami = data.aws_ami.latest.id
instance_type = var.instance_type
tags = merge(var.tags, {
Name = "${var.project}-${var.environment}"
})
lifecycle {
create_before_destroy = true
}
}
Outputs
output "instance_id" {
description = "EC2 instance ID"
value = aws_instance.main.id
}
State Management
# backend.tf
terraform {
backend "s3" {
bucket = "terraform-state-bucket"
key = "project/terraform.tfstate"
region = "us-east-1"
encrypt = true
dynamodb_table = "terraform-locks"
}
}
Common Commands
# Initialize and plan
terraform init
terraform plan -out=tfplan
# Apply with auto-approve (CI/CD)
terraform apply -auto-approve tfplan
# Import existing resource
terraform import aws_instance.main i-1234567890abcdef0
# State operations
terraform state list
terraform state show aws_instance.main
terraform state mv aws_instance.old aws_instance.new
Workspace Strategy
# Create workspaces per environment
terraform workspace new dev
terraform workspace new prod
# Use in configuration
locals {
env_config = {
dev = { instance_type = "t3.micro" }
prod = { instance_type = "t3.large" }
}
config = local.env_config[terraform.workspace]
}
Examples
Input: "Create a VPC module" Action: Create module with subnets, route tables, NAT gateway, proper outputs
Input: "Fix state drift" Action: Run plan, identify drift, decide refresh vs import vs manual fix
スコア
総合スコア
55/100
リポジトリの品質指標に基づく評価
✓SKILL.md
SKILL.mdファイルが含まれている
+20
○LICENSE
ライセンスが設定されている
0/10
○説明文
100文字以上の説明がある
0/10
○人気
GitHub Stars 100以上
0/15
✓最近の活動
1ヶ月以内に更新
+10
○フォーク
10回以上フォークされている
0/5
✓Issue管理
オープンIssueが50未満
+5
✓言語
プログラミング言語が設定されている
+5
✓タグ
1つ以上のタグが設定されている
+5
レビュー
💬
レビュー機能は近日公開予定です


