Community生產力與協作github.com

hashicorp/run-acceptance-tests

執行 Terraform provider 的驗收測試指南。當被要求執行驗收測試或執行前綴為 `TestAcc` 的測試時使用此技能。

run-acceptance-tests 是什麼?

此技能提供一個專業指南,用於執行 Terraform provider 的驗收測試(acceptance tests)。當開發者或 AI 代理需要執行以 `TestAcc` 前綴命名的測試時,此技能會提供明確的指示和最佳實踐。驗收測試對於確保 Terraform provider 在真實環境中正確運作至關重要,因為它們會實際建立、修改和銷毀資源。此技能涵蓋了測試環境的設定、必要的環境變數(如 `TF_ACC` 和雲端憑證)以及常見的執行指令與除錯技巧。它支援所有 Terraform provider,並與主要開發平台相容。透過遵循此指南,開發者可以避免常見的測試陷阱,並確保他們的 provider 在整合到正式環境前已通過充分的驗證。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/hashicorp/agent-skills/tree/main/skills/run-acceptance-tests

Installed? Explore more 生產力與協作 skills: steipete/gemini, steipete/gh-issues, steipete/skill-creator · View all 6 →

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

run-acceptance-tests 是做什麼的?

執行 Terraform provider 的驗收測試指南。當被要求執行驗收測試或執行前綴為 TestAcc 的測試時使用此技能。

簡介

驗收測試會實際建立、修改和銷毀真實的基礎架構資源,以驗證 Terraform provider 是否能正常運作。這些測試對於確保 provider 的穩定性和正確性至關重要。

前置需求

  • 已安裝 Go(版本 1.18 或更新)
  • 已安裝 Terraform(版本 1.0 或更新)
  • 設定必要的雲端服務提供者憑證(例如 AWS、Azure、GCP)
  • 已設定環境變數 TF_ACC=1 以啟用驗收測試

執行測試

基本指令

# 執行所有驗收測試
TF_ACC=1 go test ./... -v -run TestAcc

# 執行特定的驗收測試
TF_ACC=1 go test ./... -v -run TestAccExampleResource

# 僅執行特定套件中的驗收測試
TF_ACC=1 go test ./internal/provider/ -v -run TestAcc

重要環境變數

變數名稱說明範例值
TF_ACC啟用驗收測試1
AWS_REGIONAWS 區域(若使用 AWS)us-west-2
AZURE_SUBSCRIPTION_IDAzure 訂閱 ID(若使用 Azure)xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
GOOGLE_PROJECTGCP 專案 ID(若使用 GCP)my-project

常見問題

測試超時

若測試執行時間過長,可以增加超時時間:

TF_ACC=1 go test ./... -v -run TestAcc -timeout 60m

並行執行

驗收測試預設會依序執行,但可以透過設定 PARALLEL 環境變數來啟用並行測試:

TF_ACC=1 PARALLEL=4 go test ./... -v -run TestAcc

參考資源

Individual skills in this repo

This repo contains 15 individual skills — each has its own dedicated page.

hashicorp/aws-ami-builder

Build Amazon Machine Images (AMIs) with Packer using the amazon-ebs builder. Use when creating custom AMIs for EC2 instances.

hashicorp/azure-image-builder

Build Azure managed images and Azure Compute Gallery images with Packer. Use when creating custom images for Azure VMs.

hashicorp/azure-verified-modules

Azure Verified Modules (AVM) requirements and best practices for developing certified Azure Terraform modules. Use when creating or reviewing Azure modules that need AVM certification.

hashicorp/new-terraform-provider

Use this when scaffolding a new Terraform provider.

hashicorp/provider-actions

Implement Terraform Provider actions using the Plugin Framework. Use when developing imperative operations that execute at lifecycle events (before/after create, update, destroy).

hashicorp/provider-docs

Create, update, and review Terraform provider documentation for Terraform Registry using HashiCorp-recommended patterns, tfplugindocs templates, and schema descriptions. Use when adding or changing provider configuration, resources, data sources, ephemeral resources, list resources, functions, or guides; when validating generated docs; and when troubleshooting missing or incorrect Registry documentation.

hashicorp/provider-resources

Implement Terraform Provider resources and data sources using the Plugin Framework. Use when developing CRUD operations, schema design, state management, and acceptance testing for provider resources.

hashicorp/provider-test-patterns

Terraform provider acceptance test patterns using terraform-plugin-testing with the Plugin Framework. Covers test structure, TestCase/TestStep fields, ConfigStateChecks with custom statecheck.StateCheck implementations, plan checks, CompareValue for cross-step assertions, config helpers, import testing with ImportStateKind, sweepers, and scenario patterns (basic, update, disappears, validation, regression), and ephemeral resource testing with the echoprovider package. Use when writing, reviewing, or debugging provider acceptance tests, including questions about statecheck, plancheck, TestCheckFunc, CheckDestroy, ExpectError, import state verification, ephemeral resources, or how to structure test files.

hashicorp/push-to-registry

Push Packer build metadata to HCP Packer registry for tracking and managing image lifecycle. Use when integrating Packer builds with HCP Packer for version control and governance.

hashicorp/refactor-module

Transform monolithic Terraform configurations into reusable, maintainable modules following HashiCorp's module design principles and community best practices.

hashicorp/terraform-search-import

Discover existing cloud resources using Terraform Search queries and bulk import them into Terraform management. Use when bringing unmanaged infrastructure under Terraform control, auditing cloud resources, or migrating to IaC.

hashicorp/terraform-stacks

Comprehensive guide for working with HashiCorp Terraform Stacks. Use when creating, modifying, or validating Terraform Stack configurations (.tfcomponent.hcl, .tfdeploy.hcl files), working with stack components and deployments from local modules, public registry, or private registry sources, managing multi-region or multi-environment infrastructure, or troubleshooting Terraform Stacks syntax and structure.

hashicorp/terraform-style-guide

Generate Terraform HCL code following HashiCorp's official style conventions and best practices. Use when writing, reviewing, or generating Terraform configurations.

hashicorp/terraform-test

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.

hashicorp/windows-builder

Build Windows images with Packer using WinRM communicator and PowerShell provisioners. Use when creating Windows AMIs, Azure images, or VMware templates.

相關技能