← ClaudeAtlas

terraformlisted

Terraform 基础设施即代码
ryukyagamilight/terminal-skills · ★ 1 · DevOps & Infrastructure · score 79
Install: claude install-skill ryukyagamilight/terminal-skills
# Terraform 基础设施即代码 ## 概述 HCL 编写、状态管理、模块开发等技能。 ## 基础命令 ```bash # 初始化 terraform init terraform init -upgrade # 升级 provider # 格式化 terraform fmt terraform fmt -recursive # 验证 terraform validate # 计划 terraform plan terraform plan -out=plan.tfplan # 应用 terraform apply terraform apply plan.tfplan terraform apply -auto-approve # 销毁 terraform destroy terraform destroy -auto-approve # 查看状态 terraform show terraform state list terraform state show resource_type.name # 输出 terraform output terraform output -json ``` ## HCL 语法 ### Provider 配置 ```hcl # providers.tf terraform { required_version = ">= 1.0" required_providers { aws = { source = "hashicorp/aws" version = "~> 5.0" } } backend "s3" { bucket = "my-terraform-state" key = "prod/terraform.tfstate" region = "us-east-1" } } provider "aws" { region = var.aws_region default_tags { tags = { Environment = var.environment ManagedBy = "Terraform" } } } ``` ### 变量定义 ```hcl # variables.tf variable "aws_region" { description = "AWS region" type = string default = "us-east-1" } variable "instance_type" { description = "EC2 instance type" type = string default = "t3.micro" } variable "environment" { description = "Environment name" type = string validation { condition = contains(["dev", "staging", "prod"], var.environment) error_message = "Environment must be dev, staging, or