Agent Skills by ALSEL
Anthropic Claudeデータ・分析⭐ リポ 0品質スコア 50/100

terraform-test

Terraformテストの作成・実行に関する包括的なガイド。テストファイル(.tftest.hcl)の作成、runブロックを使ったテストシナリオの記述、アサーションによるインフラ動作の検証、プロバイダーやデータソースのモック化、モジュール出力やリソース設定のテスト、またはTerraformテストの構文やエラーのトラブルシューティングを行う際に活用してください。

description の原文を見る

Comprehensive guide for writing and running Terraform tests. Use when creating test files (.tftest.hcl), writing test scenarios with run blocks, validating infrastructure behavior with assertions, mocking providers and data sources, testing module outputs and resource configurations, or troubleshooting Terraform test syntax and execution.

SKILL.md 本文

Terraform テスト

Terraform の組み込みテストフレームワークは、設定の更新が破壊的な変更をもたらさないことを検証します。テストは一時的なリソースに対して実行されるため、既存のインフラストラクチャと状態ファイルを保護します。

リファレンスファイル

  • references/MOCK_PROVIDERS.md — モックプロバイダーの構文、一般的なデフォルト、モックの使用時期 (Terraform 1.7.0+ のみ — ユーザーのバージョンが 1.7 以下の場合はスキップ)
  • references/CI_CD.md — GitHub Actions と GitLab CI パイプラインの例
  • references/EXAMPLES.md — 完全なテストスイートの例 (VPC モジュールのユニット、統合、モックテスト)

ユーザーがモッキング、CI/CD 統合について質問する場合、または完全な例を希望する場合は関連するリファレンスファイルを読んでください。

コア概念

  • テストファイル (.tftest.hcl / .tftest.json): 設定を検証する run ブロックを含みます
  • Run ブロック: オプションの変数、プロバイダー、アサーションを含む単一のテストシナリオ
  • Assert ブロック: テストが成功するために真である必要がある条件
  • モックプロバイダー: 実際のインフラストラクチャなしにプロバイダーの動作をシミュレート (Terraform 1.7.0+)
  • テストモード: apply (デフォルト、実リソースを作成) または plan (ロジックのみを検証)

ファイル構造

my-module/
├── main.tf
├── variables.tf
├── outputs.tf
└── tests/
    ├── defaults_unit_test.tftest.hcl         # plan モード — 高速、リソースなし
    ├── validation_unit_test.tftest.hcl        # plan モード
    └── full_stack_integration_test.tftest.hcl # apply モード — 実リソースを作成

plan モードテストは *_unit_test.tftest.hcl、apply モードテストは *_integration_test.tftest.hcl を使用することで、CI で別々にフィルタリングできます。

テストファイル構造

# オプション: テスト全体の設定
test {
  parallel = true  # すべての run ブロックの並列実行を有効化 (デフォルト: false)
}

# オプション: ファイルレベルの変数 (最高優先度、他のすべてのソースをオーバーライド)
variables {
  aws_region    = "us-west-2"
  instance_type = "t2.micro"
}

# オプション: プロバイダー設定
provider "aws" {
  region = var.aws_region
}

# 必須: 最低 1 つの run ブロック
run "test_default_configuration" {
  command = plan

  assert {
    condition     = aws_instance.example.instance_type == "t2.micro"
    error_message = "Instance type should be t2.micro by default"
  }
}

Run ブロック

run "test_name" {
  command  = plan  # または apply (デフォルト)
  parallel = true  # オプション、v1.9.0 以降

  # ファイルレベルの変数をオーバーライド
  variables {
    instance_type = "t3.large"
  }

  # 特定のモジュールを参照
  module {
    source  = "./modules/vpc"  # ローカルまたはレジストリのみ (git/http ではない)
    version = "5.0.0"          # レジストリモジュールのみ
  }

  # 状態の分離を制御
  state_key = "shared_state"  # v1.9.0 以降

  # Plan の動作
  plan_options {
    mode    = refresh-only  # または normal (デフォルト)
    refresh = true
    replace = [aws_instance.example]
    target  = [aws_instance.example]
  }

  # アサーション
  assert {
    condition     = aws_instance.example.id != ""
    error_message = "Instance should have a valid ID"
  }

  # 予期される失敗 (これらが失敗すればテストは成功)
  expect_failures = [
    var.instance_count
  ]
}

一般的なテストパターン

出力の検証

run "test_outputs" {
  command = plan

  assert {
    condition     = output.vpc_id != null
    error_message = "VPC ID output must be defined"
  }

  assert {
    condition     = can(regex("^vpc-", output.vpc_id))
    error_message = "VPC ID should start with 'vpc-'"
  }
}

条件付きリソース

run "test_nat_gateway_disabled" {
  command = plan

  variables {
    create_nat_gateway = false
  }

  assert {
    condition     = length(aws_nat_gateway.main) == 0
    error_message = "NAT gateway should not be created when disabled"
  }
}

リソース数

run "test_resource_count" {
  command = plan

  variables {
    instance_count = 3
  }

  assert {
    condition     = length(aws_instance.workers) == 3
    error_message = "Should create exactly 3 worker instances"
  }
}

タグ

run "test_resource_tags" {
  command = plan

  variables {
    common_tags = {
      Environment = "production"
      ManagedBy   = "Terraform"
    }
  }

  assert {
    condition     = aws_instance.example.tags["Environment"] == "production"
    error_message = "Environment tag should be set correctly"
  }

  assert {
    condition     = aws_instance.example.tags["ManagedBy"] == "Terraform"
    error_message = "ManagedBy tag should be set correctly"
  }
}

データソース

run "test_data_source_lookup" {
  command = plan

  assert {
    condition     = data.aws_ami.ubuntu.id != ""
    error_message = "Should find a valid Ubuntu AMI"
  }

  assert {
    condition     = can(regex("^ami-", data.aws_ami.ubuntu.id))
    error_message = "AMI ID should be in correct format"
  }
}

検証ルール

run "test_invalid_environment" {
  command = plan

  variables {
    environment = "invalid"
  }

  expect_failures = [
    var.environment
  ]
}

依存関係のある連続テスト

run "setup_vpc" {
  command = apply

  assert {
    condition     = output.vpc_id != ""
    error_message = "VPC should be created"
  }
}

run "test_subnet_in_vpc" {
  command = plan

  variables {
    vpc_id = run.setup_vpc.vpc_id
  }

  assert {
    condition     = aws_subnet.example.vpc_id == run.setup_vpc.vpc_id
    error_message = "Subnet should be in the VPC from setup_vpc"
  }
}

Plan オプション (refresh-only、ターゲット指定)

run "test_refresh_only" {
  command = plan

  plan_options {
    mode = refresh-only
  }

  assert {
    condition     = aws_instance.example.tags["Environment"] == "production"
    error_message = "Tags should be refreshed correctly"
  }
}

run "test_specific_resource" {
  command = plan

  plan_options {
    target = [aws_instance.example]
  }

  assert {
    condition     = aws_instance.example.instance_type == "t2.micro"
    error_message = "Targeted resource should be planned"
  }
}

並列モジュール

run "test_networking_module" {
  command  = plan
  parallel = true

  module {
    source = "./modules/networking"
  }

  assert {
    condition     = output.vpc_id != ""
    error_message = "VPC should be created"
  }
}

run "test_compute_module" {
  command  = plan
  parallel = true

  module {
    source = "./modules/compute"
  }

  assert {
    condition     = output.instance_id != ""
    error_message = "Instance should be created"
  }
}

状態キーの共有

run "create_foundation" {
  command   = apply
  state_key = "foundation"

  assert {
    condition     = aws_vpc.main.id != ""
    error_message = "Foundation VPC should be created"
  }
}

run "create_application" {
  command   = apply
  state_key = "foundation"

  variables {
    vpc_id = run.create_foundation.vpc_id
  }

  assert {
    condition     = aws_instance.app.vpc_id == run.create_foundation.vpc_id
    error_message = "Application should use foundation VPC"
  }
}

クリーンアップの順序 (バケット前にS3 オブジェクト)

run "create_bucket" {
  command = apply

  assert {
    condition     = aws_s3_bucket.example.id != ""
    error_message = "Bucket should be created"
  }
}

run "add_objects" {
  command = apply

  assert {
    condition     = length(aws_s3_object.files) > 0
    error_message = "Objects should be added"
  }
}

# クリーンアップは逆順で破棄: 最初にオブジェクト、次にバケット

複数のエイリアス付きプロバイダー

provider "aws" {
  alias  = "primary"
  region = "us-west-2"
}

provider "aws" {
  alias  = "secondary"
  region = "us-east-1"
}

run "test_with_specific_provider" {
  command = plan

  providers = {
    aws = provider.aws.secondary
  }

  assert {
    condition     = aws_instance.example.availability_zone == "us-east-1a"
    error_message = "Instance should be in us-east-1 region"
  }
}

複雑な条件

assert {
  condition = alltrue([
    for subnet in aws_subnet.private :
    can(regex("^10\\.0\\.", subnet.cidr_block))
  ])
  error_message = "All private subnets should use 10.0.0.0/8 CIDR range"
}

クリーンアップ

リソースはテスト完了後に run ブロックの逆順 で破棄されます。これは依存関係 (例: バケット前のS3 オブジェクト) に関して重要です。デバッグのため terraform test -no-cleanup を使用してクリーンアップをスキップできます。

テストの実行

terraform test                                        # すべてのテスト
terraform test tests/defaults.tftest.hcl             # 特定のファイル
terraform test -filter=test_vpc_configuration        # run ブロック名で指定
terraform test -test-directory=integration-tests     # カスタムディレクトリ
terraform test -verbose                              # 詳細出力
terraform test -no-cleanup                           # リソースクリーンアップをスキップ

ベストプラクティス

  1. 命名: plan モードは *_unit_test.tftest.hcl、apply モードは *_integration_test.tftest.hcl
  2. テスト命名: テストしているシナリオを説明する説明的な run ブロック名を使用
  3. デフォルトは plan: 実リソースの動作をテストする必要がない限り command = plan を使用
  4. モックを使用: 外部依存関係の場合 — より高速で認証情報不要 (references/MOCK_PROVIDERS.md を参照)
  5. エラーメッセージ: テストを再度実行せずに障害を診断できるほど具体的に
  6. ネガティブテスト: expect_failures を使用して検証ルールが不正な入力を拒否することを確認
  7. 変数カバレッジ: すべてのコードパスを検証するために異なる変数の組み合わせをテスト — テスト変数は最高優先度で他のすべてのソースをオーバーライド
  8. モジュールソース: テストファイルはローカルパスとレジストリモジュールのみをサポート — git や HTTP URL ではない
  9. 並列実行: 異なる状態ファイルを持つ独立したテストに parallel = true を使用
  10. クリーンアップ: 統合テストはリソースを run ブロックの逆順で自動的に破棄; デバッグの場合は -no-cleanup を使用
  11. CI/CD: すべての PR でユニットテストを実行、マージ時に統合テストを実行 (references/CI_CD.md を参照)

トラブルシューティング

問題解決策
アサーション失敗-verbose を使用して実際値と期待値を確認
認証情報が不足ユニットテストではモックプロバイダーを使用
サポートされていないモジュールソースgit/HTTP ソースをローカルモジュールに変換
テスト間の干渉分離のため state_key または別々のモジュールを使用
テストが遅いcommand = plan とモックを使用; 統合テストは別々に実行

参照

ライセンス: MPL-2.0(寛容ライセンスのため全文を引用しています) · 原本リポジトリ

詳細情報

作者
hashicorp
リポジトリ
hashicorp/agent-skills
ライセンス
MPL-2.0
最終更新
不明

Source: https://github.com/hashicorp/agent-skills / ライセンス: MPL-2.0

関連スキル

OpenAIデータ・分析⭐ リポ 1,451

hugging-face-trackio

Trackioを使用してMLトレーニング実験を追跡・可視化できます。トレーニング中のメトリクスログ記録(Python API)、トレーニング診断のアラート発火、ログされたメトリクスの取得・分析(CLI)が必要な場合に活用してください。リアルタイムダッシュボード表示、Webhookを使用したアラート、HF Space同期、自動化向けのJSON出力に対応しています。

by gradio-app
汎用データ・分析⭐ リポ 855

btc-bottom-model

ビットコインのサイクルタイミングモデルで、加重スコアリングシステムを搭載しています。日次パルス(4指標、32ポイント)とウィークリー構造(9指標、68ポイント)の2カテゴリーにわたる13の指標を追跡し、0~100のマーケットヒートスコアを算出します。ETFフロー、ファンディングレート、ロング/ショート比率、恐怖・貪欲指数、LTH-MVRV、NUPL、SOPR(LTH+STH)、LTH供給率、移動平均倍率(365日MA、200週MA)、週次RSI、出来高トレンドに対応します。市場サイクル全体を通じて買いと売りの両方の推奨を提供します。ビットコインの底値拾い、BTCサイクルポジション、買い時・売り時、オンチェーン指標、MVRV、NUPL、SOPR、LTH動向、ETFの流出入、ファンディングレート、恐怖指数、ビットコインが過熱状態か、マイナーコスト、暗号資産市場のセンチメント、BTCのポジションサイジング、「今ビットコインを買うべきか」「BTCが天井をつけているか」「オンチェーン指標は何を示しているか」といった質問の際にこのスキルを活用します。

by star23
Anthropic Claudeデータ・分析⭐ リポ 380

protein_solubility_optimization

タンパク質の溶解性最適化 - タンパク質の溶解性を最適化します。タンパク質の特性を計算し、溶解性と親水性を予測し、有効な変異を提案します。タンパク質配列の特性計算、タンパク質機能の予測、親水性計算、ゼロショット配列予測を含むタンパク質エンジニアリング業務に使用できます。3つのSCPサーバーから4つのツールを統合しています。

by SpectrAI-Initiative
Anthropic Claudeデータ・分析⭐ リポ 1,743

research-lookup

Parallel Chat APIまたはPerplexity sonar-pro-searchを使用して、最新の研究情報を検索できます。学術論文の検索にも対応しています。クエリは自動的に最適なバックエンドにルーティングされるため、論文の検索、研究データの収集、科学情報の検証に活用できます。

by K-Dense-AI
Anthropic Claudeデータ・分析⭐ リポ 299

tree-formatting

ggtree(R)またはiTOL(ウェブ)を使用して、系統樹の可視化とフォーマットを行います。系統樹を図として描画する際、ツリーレイアウトの選択、分類学に基づく枝やラベルの色付け、クレードの折りたたみ、サポート値の表示、またはツリーへのオーバーレイ追加が必要な場合に使用してください。系統推定(protein-phylogenyスキルを使用)やドメイン注釈(今後の独立したスキル)には使用しないでください。

by majiayu000
汎用データ・分析⭐ リポ 145

querying-indonesian-gov-data

インドネシア政府の50以上のAPIとデータソースに接続できます。BPJPH(ハラール認証)、BOM(食品安全)、OJK(金融適正性)、BPS(統計)、BMKG(気象・地震)、インドネシア中央銀行(為替レート)、IDX(株式)、CKAN公開データポータル、pasal.id(第三者法MCP)に対応しています。インドネシア政府データを活用したアプリ開発、.go.idウェブサイトのスクレイピング、ハラール認証の確認、企業の法的適正性の検証、金融機関ステータスの照会、またはインドネシアMCPサーバーへの接続時に使用できます。CSRF処理、CKAN API使用方法、IP制限回避など、すぐに実行可能なPythonパターンを含んでいます。

by suryast
本サイトは GitHub 上で公開されているオープンソースの SKILL.md ファイルをクロール・インデックス化したものです。 各スキルの著作権は原作者に帰属します。掲載に問題がある場合は info@alsel.co.jp または /takedown フォームよりご連絡ください。
原作者: hashicorp · hashicorp/agent-skills · ライセンス: MPL-2.0