run-acceptance-tests

bởi hashicorp

Thực thi và chẩn đoán các bài kiểm tra chấp nhận Go cho các nhà cung cấp Terraform với khả năng xử lý sự cố có cấu trúc. Chạy các bài kiểm tra chấp nhận tập trung bằng cách sử dụng go test -run=TestAccFeatureHappyPath với biến môi trường TF_ACC=1. Chẩn đoán lỗi theo từng bước: thử lại với -count=1, bật đầu ra chi tiết với -v, kích hoạt ghi log gỡ lỗi qua TF_LOG=debug, và duy trì không gian làm việc Terraform với TF_ACC_WORKING_DIR_PERSIST=1. Xác thực độ tin cậy của bài kiểm tra bằng cách cố tình phá vỡ một TestCheckFunc, chạy lại bài kiểm tra để...

npx skills add https://github.com/hashicorp/agent-skills --skill run-acceptance-tests

An acceptance test is a Go test function with the prefix TestAcc.

Before running: acceptance tests create real infrastructure against the provider's live API, which may incur cost. Confirm the configured credentials point at a test account before proceeding.

To run a focused acceptance test named TestAccFeatureHappyPath:

  1. Run go test -run=TestAccFeatureHappyPath -timeout 60m with the following environment variables:

    • TF_ACC=1

    Default to non-verbose test output. Always pass an explicit -timeout: go test kills any test run after 10 minutes by default, and acceptance tests routinely exceed that.

  2. The acceptance tests may require additional environment variables for specific providers. To discover which ones:

    • Read the test's PreCheck / testAccPreCheck function and search the test files: grep -rn "os.Getenv" --include="*_test.go".
    • Check the repository's README, CONTRIBUTING, or .env.example for documented test setup.
    • The provider's Configure method shows how credentials are resolved; use the provider-configuration skill (if available) to understand a credential provider chain.

    Set the variables for the single test invocation (EXAMPLE_API_KEY=... TF_ACC=1 go test ...) rather than exporting them into the shell profile, and never write secret values into files inside the repository.

To diagnose a failing acceptance test, use these options, in order. These options are cumulative: each option includes all the options above it.

  1. Run the test again. Use the -count=1 option to ensure that go test does not use a cached result.
  2. Offer verbose go test output. Use the -v option.
  3. Offer debug-level logging. Enable debug-level logging with the environment variable TF_LOG=debug.
  4. Offer to persist the acceptance test's Terraform workspace. Enable persistence with the environment variable TF_ACC_WORKING_DIR_PERSIST=1.

A passing acceptance test may be a false negative. To "flip" a passing acceptance test named TestAccFeatureHappyPath:

  1. Edit the value of one of the TestCheckFuncs in one of the TestSteps in the TestCase.
  2. Run the acceptance test. Expect the test to fail.
  3. If the test fails, then undo the edit and report a successful flip. Else, keep the edit and report an unsuccessful flip.

If a test run is interrupted, real resources may be left behind; run the provider's sweepers if it registers them (see the provider-test-patterns skill's sweeper reference, if available). For writing or restructuring tests, use the provider-test-patterns skill.

Thêm skills từ hashicorp

provider-actions
hashicorp
Implement Terraform Provider actions using the Plugin Framework. Use when developing imperative operations that execute at lifecycle events (before/after…
official
new-terraform-provider
hashicorp
Use this when scaffolding a new Terraform provider with the Plugin Framework: workspace layout, go module setup, provider server main.go, and a provider.go…
official
terraform-test
hashicorp
Hướng dẫn toàn diện để viết và chạy các bài kiểm tra Terraform. Sử dụng khi tạo tệp kiểm tra (.tftest.hcl), viết các kịch bản kiểm tra với run blocks, xác thực…
official
terraform-test
hashicorp
Hướng dẫn toàn diện để viết và chạy các bài kiểm tra Terraform với xác nhận, giả lập và xác thực module. Viết tệp kiểm tra bằng cú pháp .tftest.hcl với các khối run thực thi ở chế độ plan hoặc apply, hỗ trợ thực thi tuần tự và song song với tùy chọn cách ly trạng thái. Xác nhận điều kiện trên các thuộc tính tài nguyên, đầu ra và nguồn dữ liệu; sử dụng expect_failures để xác thực rằng đầu vào không hợp lệ bị từ chối đúng cách. Mock providers (Terraform 1.7.0+) mô phỏng hành vi cơ sở hạ tầng mà không cần...
official
provider-actions
hashicorp
Triển khai các hành động Terraform Provider mệnh lệnh tại các sự kiện vòng đời tài nguyên bằng Plugin Framework. Hỗ trợ các kích hoạt vòng đời trước/sau khi tạo và trước/sau khi cập nhật (sự kiện hủy không khả dụng trong Terraform 1.14.0). Yêu cầu định nghĩa schema phù hợp với các loại framework chính xác, ElementType cho collections, và các trình xác thực cho đầu vào. Bao gồm báo cáo tiến độ, quản lý thời gian chờ, và xử lý lỗi toàn diện cho các hoạt động chạy lâu. Triển khai polling và...
official
aws-ami-builder
hashicorp
Xây dựng các Amazon Machine Images tùy chỉnh với trình xây dựng amazon-ebs của Packer. Tự động hóa việc tạo AMI từ các AMI nguồn bằng cách sử dụng các mẫu HCL với các bộ cung cấp để tùy chỉnh (script shell, tải lên tệp, quản lý cấu hình). Hỗ trợ phân phối AMI đa vùng qua ami_regions và lọc AMI nguồn linh hoạt theo tên, chủ sở hữu và loại ảo hóa. Xác thực qua biến môi trường, tệp thông tin xác thực AWS hoặc hồ sơ phiên bản IAM; bao gồm các lệnh xác thực và xây dựng cho mẫu...
official
new-terraform-provider
hashicorp
Tạo khung cho một Terraform provider mới sử dụng Plugin Framework. Tạo một không gian làm việc module Go mới với quy ước đặt tên chuẩn "terraform-provider-" và khởi tạo các phụ thuộc cần thiết. Cung cấp tệp main.go mẫu tuân theo các mẫu Plugin Framework của HashiCorp, với các điểm đánh dấu TODO để tùy chỉnh. Xác thực thiết lập bằng cách chạy các lệnh build và test để đảm bảo provider biên dịch và vượt qua các kiểm tra ban đầu. Xử lý quản lý không gian làm việc bằng cách xác nhận ý định trước khi tạo một...
official
azure-verified-modules
hashicorp
Các yêu cầu chứng nhận và thực hành tốt nhất cho các mô-đun Azure Terraform nhằm đạt được sự tuân thủ AVM. Áp đặt các ràng buộc về phiên bản nhà cung cấp (azurerm >= 4.0, < 5.0; azapi >= 2.0, < 3.0) và cấm các tham chiếu mô-đun dựa trên git, thay vào đó yêu cầu các nguồn đăng ký Terraform cố định. Bắt buộc sử dụng snake_casing chữ thường cho tất cả các định danh, kiểu biến chính xác, các thuộc tính đầu ra riêng biệt thông qua mẫu lớp chống tham nhũng và các biến cục bộ được sắp xếp theo thứ tự bảng chữ
official