run-acceptance-tests

작성자: hashicorp

Terraform 제공자의 Go 승인 테스트를 실행하고 구조화된 문제 해결을 통해 진단합니다. TF_ACC=1 환경 변수와 함께 go test -run=TestAccFeatureHappyPath를 사용하여 집중 승인 테스트를 실행합니다. 실패를 점진적으로 진단합니다: -count=1로 재시도, -v로 상세 출력 활성화, TF_LOG=debug를 통해 디버그 로깅 활성화, TF_ACC_WORKING_DIR_PERSIST=1로 Terraform 작업 공간 유지. TestCheckFunc를 의도적으로 중단시켜 테스트 신뢰성을 검증하고, 테스트를 재실행하여...

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.

hashicorp의 다른 스킬

provider-framework-migration
hashicorp
Terraform 제공자 리소스와 데이터 소스를 Plugin SDKv2에서 Plugin Framework로 마이그레이션: 하나의 제공자에서 두 플러그인을 멀티플렉싱(terraform-plugin-mux, …)
provider-configuration
hashicorp
Terraform provider 구성 및 인증을 Plugin Framework로 구현: 자격 증명을 위한 provider 스키마(Optional + Sensitive 속성),…
provider-ephemeral-resources
hashicorp
Terraform 공급자 임시 리소스를 Plugin Framework로 구현: Open/Renew/Close 수명주기, 임시 스키마 설계, 등록 방법…
terraform-test
hashicorp
Terraform 테스트 작성 및 실행을 위한 종합 가이드로, 어설션, 모킹, 모듈 검증을 포함합니다. .tftest.hcl 구문을 사용하여 테스트 파일을 작성하며, plan 또는 apply 모드로 실행되는 run 블록을 지원하고, 선택적 상태 격리와 함께 순차 및 병렬 실행을 지원합니다. 리소스 속성, 출력, 데이터 소스에 대한 조건을 어설션하고, expect_failures를 사용하여 잘못된 입력이 적절히 거부되는지 검증합니다. Mock 제공자(Terraform 1.7.0+)는 인프라 동작을 시뮬레이션합니다...
terraform-policy
hashicorp
Terraform Policy 파일(.policy.hcl, .policytest.hcl, Sentinel→tfpolicy)을 작성, 테스트 또는 변환합니다. 트리거: policy.hcl, policytest, convert sentinel, tfpolicy,…
terraform-search-import
hashicorp
Terraform Search 쿼리를 사용하여 기존 클라우드 리소스를 검색하고 이를 Terraform 관리로 대량 가져옵니다. 관리되지 않는 인프라를 도입할 때 사용합니다…
aws-ami-builder
hashicorp
Packer의 amazon-ebs 빌더로 사용자 지정 Amazon 머신 이미지를 구축합니다. HCL 템플릿과 프로비저너(셸 스크립트, 파일 업로드, 구성 관리)를 사용해 소스 AMI에서 AMI 생성을 자동화합니다. ami_regions를 통한 다중 리전 AMI 배포와 이름, 소유자, 가상화 유형별 유연한 소스 AMI 필터링을 지원합니다. 환경 변수, AWS 자격 증명 파일 또는 IAM 인스턴스 프로파일을 통해 인증하며 템플릿 검증 및 빌드 명령을 포함합니다...
tfctl
hashicorp
tfctl CLI를 사용하여 HCP Terraform / Terraform Cloud / Terraform Enterprise와 상호작용합니다. 전체 API를 지원합니다. 모든 HCP Terraform 또는 Terraform Cloud 또는…에 사용하세요.