### Acceptance Test Example Usage Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/testing-case-and-step.md Example of how to use the resource.Test function to configure and run an acceptance test, including setting up provider factories and defining test steps. ```go func TestAccExampleResource(t *testing.T) { resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "examplecloud": providerserver.NewProviderServer(provider.New()), }, Steps: []resource.TestStep{ // ... test steps ... }, }) } ``` -------------------------------- ### Complete Import Test Example Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/import-state-testing.md This example demonstrates a comprehensive import test for a resource, including creating the resource, importing it, and then updating and re-importing. It shows how to use `ImportState`, `ImportStateId`, and `ImportStateVerify` with optional `ImportStateVerifyIgnore` for attributes not managed by the provider. ```go func TestAccExampleResource_Import(t *testing.T) { resourceName := "examplecloud_resource.test" resourceId := "test-resource-123" resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, ProtoV6ProviderFactories: providerFactories, CheckDestroy: testAccCheckExampleResourceDestroyed, Steps: []resource.TestStep{ // Create resource { Config: testAccExampleResourceConfig_basic(resourceId), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet(resourceName, "id"), resource.TestCheckResourceAttr(resourceName, "name", "example"), ), }, // Import the resource { ResourceName: resourceName, ImportState: true, ImportStateId: resourceId, ImportStateVerify: true, ImportStateVerifyIgnore: []string{ "password", // not returned by API "force_delete", // provider-only argument }, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet(resourceName, "id"), resource.TestCheckResourceAttr(resourceName, "name", "example"), ), }, // Update and re-import { Config: testAccExampleResourceConfig_updated(resourceId), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr(resourceName, "name", "updated"), ), }, { ResourceName: resourceName, ImportState: true, ImportStateId: resourceId, ImportStateVerify: true, ImportStateVerifyIgnore: []string{ "password", "force_delete", }, }, }, }) } ``` -------------------------------- ### Example: Verifying Imported Instance State Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/import-state-testing.md This example verifies that exactly one instance state is returned after import and checks for the presence and expected value of 'id' and 'name' attributes. ```go ImportStateCheck: func(instStates []*terraform.InstanceState) error { if len(instStates) != 1 { return fmt.Errorf("expected 1 instance, got %d", len(instStates)) } is := instStates[0] // Verify expected attributes exist if is.Attributes["id"] == "" { return errors.New("id not set after import") } if is.Attributes["name"] != "expected-name" { return fmt.Errorf("unexpected name: %s", is.Attributes["name"]) } return nil }, ``` -------------------------------- ### Shorthand Version Checks Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/terraform-version-checks.md Examples of using predefined version constants with SkipBelow and RequireAbove functions. ```go tfversion.SkipBelow(tfversion.Version1_0_0) tfversion.RequireAbove(tfversion.Version1_5_0) ``` -------------------------------- ### Example: Complex ID Generation for Databases Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/import-state-testing.md This example shows how to construct a more complex import ID for database resources by combining 'cluster_id' and 'name' attributes, separated by a slash. ```go ImportStateIdFunc: func(s *terraform.State) (string, error) { rs := s.RootModule.Resources["examplecloud_database.test"] cluster := rs.Primary.Attributes["cluster_id"] database := rs.Primary.Attributes["name"] return cluster + "/" + database, nil }, ``` -------------------------------- ### Example Usage of ExpectResourceAction Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/plan-checks.md Demonstrates how to use the ExpectResourceAction function to check for different resource actions like create, update, and delete. ```go plancheck.ExpectResourceAction("examplecloud_resource.test", plancheck.ActionCreate) plancheck.ExpectResourceAction("examplecloud_resource.test", plancheck.ActionUpdate) plancheck.ExpectResourceAction("examplecloud_resource.test", plancheck.ActionDelete) ``` -------------------------------- ### Example Resource Acceptance Test Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/testing-case-and-step.md Demonstrates how to configure and run an acceptance test for a Terraform resource using TestCase and TestStep. ```go func TestExampleResource(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) acctest.PreCheckEnvVars(t, "API_KEY") }, TerraformVersionChecks: []tfversion.TerraformVersionCheck{ tfversion.SkipBelow(tfversion.Version1_0_0), }, ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "examplecloud": providerserver.NewProviderServer(provider.New()), }, CheckDestroy: testAccCheckExampleResourceDestroyed, Steps: []resource.TestStep{ { Config: testAccExampleResourceConfig_basic("example"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet("examplecloud_resource.test", "id"), resource.TestCheckResourceAttr("examplecloud_resource.test", "name", "example"), ), }, { Config: testAccExampleResourceConfig_updated("example-updated"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("examplecloud_resource.test", "name", "example-updated"), ), }, }, }) } ``` -------------------------------- ### Example: Simple Composite ID Generation Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/import-state-testing.md This example demonstrates generating a simple composite import ID by concatenating the 'account_id' attribute with the resource's primary ID. ```go ImportStateIdFunc: func(s *terraform.State) (string, error) { rs := s.RootModule.Resources["examplecloud_resource.test"] return rs.Primary.Attributes["account_id"] + ":" + rs.Primary.ID, nil }, ``` -------------------------------- ### Full Integration Test Configuration Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/environment-variables.md A comprehensive example demonstrating how to run acceptance tests with multiple options enabled, including Terraform version, provider configuration, parallel execution, and working directory persistence. ```bash #!/bin/bash set -e # Run with all options TF_ACC=1 \ TF_ACC_TERRAFORM_VERSION=~> 1.5 \ TF_ACC_PROVIDER_HOST=providers.example.com \ TF_ACC_PROVIDER_NAMESPACE=myorg \ TF_ACC_PERSIST_WORKING_DIR=1 \ go test -v -parallel 4 -run TestAccExampleResource ./... # Cleanup (if not keeping working dir) # rm -rf .terraform.test ``` -------------------------------- ### ComposeTestCheckFunc Example Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/checking-functions.md Composes multiple test check functions into a single function that runs all checks sequentially. If any check fails, remaining checks are skipped and an error is returned. ```go Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet("examplecloud_resource.test", "id"), resource.TestCheckResourceAttr("examplecloud_resource.test", "name", "example"), resource.TestCheckResourceAttr("examplecloud_resource.test", "enabled", "true"), ) ``` -------------------------------- ### Import Test with Custom Verification Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/import-state-testing.md This example demonstrates how to perform custom verification after importing a resource. It uses `ImportStateCheck` to define a function that inspects the imported state and asserts specific attribute values, including nested map attributes like tags. ```go func TestAccExampleResource_ImportCustomCheck(t *testing.T) { resourceName := "examplecloud_resource.test" resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: providerFactories, Steps: []resource.TestStep{ { Config: ` resource "examplecloud_resource" "test" { name = "example" tags = { env = "test" } } `, // Corrected indentation for multiline string }, { ResourceName: resourceName, ImportState: true, ImportStateId: "test-resource-123", ImportStateCheck: func(instStates []*terraform.InstanceState) error { if len(instStates) != 1 { return fmt.Errorf("expected 1 resource, got %d", len(instStates)) } is := instStates[0] // Custom verification logic if is.Attributes["name"] != "example" { return fmt.Errorf("name not imported correctly: %s", is.Attributes["name"]) } // Check tags if is.Attributes["tags.%"] != "1" { return fmt.Errorf("tags not imported") } if is.Attributes["tags.env"] != "test" { return fmt.Errorf("tags not imported correctly") } return nil }, }, }, }) } ``` -------------------------------- ### Specify Terraform Version for Installation Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/environment-variables.md Set TF_ACC_TERRAFORM_VERSION to define the Terraform version to be installed and used for acceptance tests. Supports version constraints. ```bash TF_ACC_TERRAFORM_VERSION=1.5.0 go test -v ``` ```bash TF_ACC_TERRAFORM_VERSION="~> 1.4" go test -v ``` -------------------------------- ### Custom Test Check Function Example Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/state-checks.md Demonstrates how to use state checks within a custom Terraform test check function. Includes checking resource attributes and outputs. ```go Check: func() resource.TestCheckFunc { return func(state *terraform.State) error { tfstate := convertToTFJson(state) stateResource := tfstate.Values.RootModule.Resources["examplecloud_resource.test"] ctx := context.Background() // Check resource attributes check1 := statecheck.ExpectKnownValue(ctx, stateResource, "name", knownvalue.StringExact("example")) check2 := statecheck.ExpectKnownValue(ctx, stateResource, "enabled", knownvalue.Bool(true)) // Check output output := tfstate.Values.Outputs["resource_id"] check3 := statecheck.ExpectKnownOutputValue(ctx, output, knownvalue.NotNull()) return nil } }, ``` -------------------------------- ### Import Test with Composite ID Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/import-state-testing.md This example shows how to import a resource that uses a composite ID. It utilizes `ImportStateIdFunc` to dynamically construct the import ID based on attributes from the Terraform state of the created resource. ```go func TestAccExampleResource_ImportCompositeId(t *testing.T) { resourceName := "examplecloud_database.test" resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: providerFactories, Steps: []resource.TestStep{ // Create resource { Config: ` resource "examplecloud_database" "test" { cluster_id = "cluster-123" name = "testdb" owner = "admin" } `, // Corrected indentation for multiline string Check: resource.TestCheckResourceAttrSet(resourceName, "id"), }, // Import with composite ID { ResourceName: resourceName, ImportState: true, ImportStateIdFunc: func(s *terraform.State) (string, error) { rs := s.RootModule.Resources[resourceName] clusterId := rs.Primary.Attributes["cluster_id"] dbName := rs.Primary.Attributes["name"] return clusterId + "/" + dbName, nil }, ImportStateVerify: true, }, }, }) } ``` -------------------------------- ### RetryContext Example Usage Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/helper-utilities.md Retries a function until it succeeds or a timeout is reached, respecting context cancellation. Use this for retrying operations with a specified timeout and context. ```go err := resource.RetryContext(ctx, 5*time.Minute, func() *resource.RetryError { resp, err := client.GetResource(id) if err != nil { if isTransient(err) { return resource.RetryableError(err) } return resource.NonRetryableError(err) } if resp.Status != "ready" { return resource.RetryableError(fmt.Errorf("resource not ready")) } return nil }) if err != nil { return err } ``` -------------------------------- ### ComposeAggregateTestCheckFunc Example Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/checking-functions.md Composes multiple test check functions into a single function that runs all checks and aggregates all errors. Unlike ComposeTestCheckFunc, it continues running all checks regardless of failures. ```go Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("examplecloud_resource.test", "id"), resource.TestCheckResourceAttr("examplecloud_resource.test", "name", "example"), resource.TestCheckResourceAttr("examplecloud_resource.test", "enabled", "true"), // All checks run; all errors are reported together ) ``` -------------------------------- ### Basic Apply with Checks Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/testing-case-and-step.md Use this snippet for a basic resource apply operation followed by state verification checks. It configures the resource with initial attributes and then asserts the presence and values of specific attributes. ```go resource.TestStep{ Config: ` resource "examplecloud_resource" "test" { name = "example" } `, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet("examplecloud_resource.test", "id"), resource.TestCheckResourceAttr("examplecloud_resource.test", "name", "example"), ), } ``` -------------------------------- ### Basic Test with Configuration File Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/configuration.md Use `ConfigFile` to specify a Terraform configuration file for a test step. Ensure the `providerFactories` are correctly set up. ```go func TestAccExampleResource_Basic(t *testing.T) { resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: providerFactories, Steps: []resource.TestStep{ { ConfigFile: config.TestStepFile("main.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet("examplecloud_resource.test", "id"), ), }, }, }) } ``` -------------------------------- ### NonRetryableError Function Example Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/helper-utilities.md Creates a RetryError indicating that an error is not retryable. Use this for errors that should not be retried, such as authentication failures. ```go if err != nil && isAuthError(err) { return resource.NonRetryableError(fmt.Errorf("authentication failed")) } ``` -------------------------------- ### Test with Mixed Directories and Variables Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/configuration.md Combine `ConfigDirectory` with `ConfigVariables` to leverage existing configuration files while dynamically providing specific variables for the test. ```go func TestAccExampleResource_WithDirAndVars(t *testing.T) { resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: providerFactories, Steps: []resource.TestStep{ { ConfigDirectory: config.TestNameDirectory("resources"), ConfigVariables: config.Variables{ "instance_type": "t3.micro", "availability_zone": "us-east-1a", }, }, }, }) } ``` -------------------------------- ### RetryableError Function Example Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/helper-utilities.md Creates a RetryError indicating that an error is retryable. Use this when an operation fails but might succeed on a subsequent attempt. ```go return resource.RetryableError(fmt.Errorf("resource still initializing")) ``` -------------------------------- ### Static Directory Configuration Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/configuration.md Use StaticDirectory to always use the same directory for test configurations. This is useful when all test steps share the same configuration files. ```go func StaticDirectory(directory string) func(TestStepConfigRequest) string { return func(TestStepConfigRequest) string { return directory } } ``` ```go resource.TestStep{ ConfigDirectory: config.StaticDirectory("testdata/resources"), } ``` -------------------------------- ### Enable and Run All Acceptance Tests Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/environment-variables.md Set the TF_ACC environment variable to 1 to enable acceptance tests and run all tests using `go test -v ./...`. ```bash # Enable tests and run all TF_ACC=1 go test -v ./... # Run specific test TF_ACC=1 go test -run TestAccExampleResource_Basic -v # Run in parallel TF_ACC=1 go test -v -parallel 4 ``` -------------------------------- ### Test Step Based Directory Configuration Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/configuration.md Use TestStepDirectory to create distinct configuration directories for each test step. The generated path is testdata///, allowing for step-specific configurations. ```go func TestStepDirectory(directory string) func(TestStepConfigRequest) string { return func(req TestStepConfigRequest) string { return filepath.Join("testdata", req.TestName, strconv.Itoa(req.StepNumber), directory) } } ``` ```go resource.TestCase{ Steps: []resource.TestStep{ { ConfigDirectory: config.TestStepDirectory("resources"), // Looks for: testdata/TestExampleCloudThing_basic/1/resources/ }, { ConfigDirectory: config.TestStepDirectory("resources"), // Looks for: testdata/TestExampleCloudThing_basic/2/resources/ }, }, } ``` -------------------------------- ### Check Resource Destruction Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/helper-utilities.md Example function to check if a resource has been destroyed. It iterates through the Terraform state, attempts to retrieve each resource, and returns an error if the resource still exists or if a non-NotFound error occurs during retrieval. ```go func testAccCheckExampleResourceDestroyed(state *terraform.State) error { client := testAccProvider.Meta().(*examplecloud.Client) for _, rs := range state.RootModule.Resources { if rs.Type != "examplecloud_resource" { continue } _, err := client.GetResource(rs.Primary.ID) if err == nil { return fmt.Errorf("resource still exists: %s", rs.Primary.ID) } if !isNotFound(err) { return err } } return nil } ``` -------------------------------- ### Running Sweepers with Options Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/environment-variables.md Execute sweepers using `go test -sweep`. Options include specifying regions, running specific sweepers, allowing failures, and enabling debug output with TF_LOG=DEBUG. ```bash # Run all sweepers in region go test -sweep=us-east-1 # Run specific sweepers, allow failures go test -sweep=us-east-1,us-west-2 -sweep-run=examplecloud_resource -sweep-allow-failures # Run with debug output TF_LOG=DEBUG go test -sweep=us-east-1 ``` -------------------------------- ### Test with Configuration Directory Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/configuration.md Use `ConfigDirectory` to point to a directory containing Terraform configuration files for a test step. This is useful for more complex configurations. ```go func TestAccExampleResource_Complex(t *testing.T) { resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: providerFactories, Steps: []resource.TestStep{ { ConfigDirectory: config.TestStepDirectory("resources"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet("examplecloud_resource.test", "id"), ), }, }, }) } ``` -------------------------------- ### Import Testing Configuration Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/README.md Configures a test step to import an existing resource. Set `ImportState` to true, provide the `ImportStateId`, and optionally use `ImportStateVerify` and `ImportStateVerifyIgnore` for verification. ```go { ResourceName: "examplecloud_resource.test", ImportState: true, ImportStateId: "resource-123", ImportStateVerify: true, ImportStateVerifyIgnore: []string{"password"}, } ``` -------------------------------- ### Run Acceptance Tests in Parallel Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/README.md Configure parallel test execution by setting the `-parallel` flag in the `go test` command. ```bash # Run in parallel TF_ACC=1 go test -v -parallel 4 ``` -------------------------------- ### Update Resource Configuration Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/testing-case-and-step.md This snippet demonstrates how to perform an update operation on an existing resource. It applies a new configuration and verifies that the specified attribute has been updated to the new value. ```go resource.TestStep{ Config: ` resource "examplecloud_resource" "test" { name = "updated" } `, Check: resource.TestCheckResourceAttr("examplecloud_resource.test", "name", "updated"), } ``` -------------------------------- ### Configure Custom Provider Host and Namespace Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/environment-variables.md Set TF_ACC_PROVIDER_HOST and TF_ACC_PROVIDER_NAMESPACE to use a private registry or an internal provider. ```bash # Private provider registry TF_ACC=1 \ TF_ACC_PROVIDER_HOST=registry.corp.com \ TF_ACC_PROVIDER_NAMESPACE=mycompany \ go test -v # Internal provider TF_ACC=1 \ TF_ACC_PROVIDER_HOST=providers.internal \ TF_ACC_PROVIDER_NAMESPACE=platform \ go test -v ``` -------------------------------- ### StaticFile Function for Fixed Configuration Paths Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/configuration.md Returns a function that always returns a specified file path. Use this when the configuration file path is the same for all test steps. ```go func StaticFile(file string) func(TestStepConfigRequest) string ``` ```go resource.TestStep{ ConfigFile: config.StaticFile("testdata/resource.tf"), } resource.TestStep{ ConfigDirectory: config.StaticFile("testdata/resources"), } ``` -------------------------------- ### Test Entry Point with Sweeper Functionality Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/testing-case-and-step.md Use `TestMain` as the entry point for test execution to enable sweeper functionality. It parses flags like `-sweep`, `-sweep-allow-failures`, and `-sweep-run`. ```go func TestMain(m interface{ Run() int }) ``` ```go func TestMain(m *testing.M) { resource.TestMain(m) } // Run with: go test -sweep=us-east-1,us-west-2 -sweep-run=examplecloud_resource ``` -------------------------------- ### File-Based Configuration Test Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/README.md Uses a configuration file for the test step, typically located in `testdata`. This pattern is useful for complex configurations that are easier to manage in separate files. ```go resource.TestStep{ ConfigFile: config.TestStepFile("main.tf"), // Looks for: testdata/TestAccExampleResource/1/main.tf Check: resource.TestCheckResourceAttrSet("examplecloud_resource.test", "id"), } ``` -------------------------------- ### Expect Null Output Value Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/plan-checks.md Use this to assert that a root-level output is null in the plan. It requires the output name. ```go func ExpectNullOutputValue(name string) PlanCheck ``` -------------------------------- ### TestStepFile Function for Step-Specific Configuration Paths Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/configuration.md Generates file paths relative to the test name and step number. The path format is `testdata///`. Use this for configurations that vary per step within a test. ```go func TestStepFile(file string) func(TestStepConfigRequest) string ``` ```go resource.TestCase{ Steps: []resource.TestStep{ { ConfigFile: config.TestStepFile("test.tf"), // Looks for: testdata/TestExampleCloudThing_basic/1/test.tf }, { ConfigFile: config.TestStepFile("test.tf"), // Looks for: testdata/TestExampleCloudThing_basic/2/test.tf }, }, } ``` -------------------------------- ### Configure Import TestStep with Command Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/import-state-testing.md Configure a TestStep to test resource import using the `terraform import` command. Set `ImportState` to true and provide `ImportStateId`. `ImportStateVerify` ensures the imported state matches the resource definition, while `ImportStateVerifyIgnore` allows specifying attributes to exclude from verification. ```go resource.TestStep{ ResourceName: "examplecloud_resource.test", ImportState: true, ImportStateId: "resource-123", ImportStateVerify: true, ImportStateVerifyIgnore: []string{"password", "api_key"}, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet("examplecloud_resource.test", "id"), ), } ``` -------------------------------- ### Run Specific Acceptance Test Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/README.md Use the `-run` flag with `go test` to execute a specific acceptance test, identified by its name. ```bash # Run specific test TF_ACC=1 go test -run TestAccExampleResource_Basic -v ``` -------------------------------- ### Configure State Change Waiting Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/helper-utilities.md Use StateChangeConf to configure how the SDK waits for a resource to reach a target state. Specify pending and target states, a refresh function, and timeouts. ```go type StateChangeConf struct { Pending []string Target []string Refresh StateRefreshFunc Timeout time.Duration MinTimeout time.Duration Delay time.Duration NotFoundChecks int ContinuousTargetOccurence int } ``` ```go conf := &resource.StateChangeConf{ Pending: []string{"creating", "updating"}, Target: []string{"active", "ready"}, Refresh: func() (interface{}, string, error) { resp, err := client.GetResource(id) if err != nil { return nil, "", err } return resp, resp.Status, nil }, Timeout: 10 * time.Minute, MinTimeout: 10 * time.Second, } resource, err := conf.WaitForState() ``` -------------------------------- ### Expect Unknown Output Value Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/plan-checks.md Use this to assert that a root-level output is unknown in the plan. It requires the output name. ```go func ExpectUnknownOutputValue(name string) PlanCheck ``` -------------------------------- ### Enable Acceptance Tests Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/README.md Set the TF_ACC environment variable to 1 to enable acceptance tests when running `go test`. ```bash # Enable acceptance tests TF_ACC=1 go test -v ./... ``` -------------------------------- ### Configure Plan Checks in TestStep Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/plan-checks.md Demonstrates how to define plan checks for pre-apply and post-apply stages within a Terraform test step. Ensure necessary imports for plancheck and resource. ```go resource.TestStep{ Config: ` resource "examplecloud_resource" "test" { name = "example" } `, ConfigPlanChecks: resource.ConfigPlanChecks{ PreApply: []plancheck.PlanCheck{ plancheck.ExpectNonEmptyPlan(), }, PostApply: []plancheck.PlanCheck{ plancheck.ExpectEmptyPlan(), }, }, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet("examplecloud_resource.test", "id"), ), } ``` -------------------------------- ### Any Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/terraform-version-checks.md Combines multiple version checks such that if any passes (no error/skip), the test continues. It only fails if all checks fail. ```APIDOC ## Any ### Description Combines multiple version checks such that if any passes (no error/skip), test continues. Only fails if all fail. ### Function Signature ```go func Any(checks ...TerraformVersionCheck) TerraformVersionCheck ``` ### Parameters #### `checks` - Type: `...TerraformVersionCheck` - Description: Variable number of version checks. ### Returns - Type: `TerraformVersionCheck` - Description: Combined version check. ### Example Usage ```go tfversion.Any( tfversion.SkipBelow(version.Must(version.NewVersion("1.0.0"))), tfversion.RequireNot(version.Must(version.NewVersion("1.1.0"))), ) ``` ``` -------------------------------- ### Check Resource Attribute Pair Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/checking-functions.md Use this function to verify that an attribute from one resource matches an attribute from another resource. It takes the resource addresses and attribute paths for both resources as input. ```go func TestCheckResourceAttrPair(nameFirst, keyFirst, nameSecond, keySecond string) TestCheckFunc ``` ```go // Verify that a data source returns the same ID as the resource resource.TestCheckResourceAttrPair( "examplecloud_resource.test", "id", "data.examplecloud_resource.test", "id", ) ``` -------------------------------- ### StaticDirectory Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/configuration.md Returns a function that always returns the supplied directory path. This is useful for setting a fixed configuration directory for all test steps. ```APIDOC ## StaticDirectory ### Description Returns a function that always returns the supplied directory path. ### Signature ```go func StaticDirectory(directory string) func(TestStepConfigRequest) string ``` ### Parameters #### Path Parameters - **directory** (string) - Required - Directory path to use for all steps ### Returns - **TestStepConfigFunc** - Function returning the static directory path ### Example Usage ```go resource.TestStep{ ConfigDirectory: config.StaticDirectory("testdata/resources"), } ``` ``` -------------------------------- ### Import Resource State Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/testing-case-and-step.md Use this snippet to test the import functionality for a resource. It specifies the resource to import, provides a static ID, and enables verification of the imported state, optionally ignoring certain attributes. ```go resource.TestStep{ ResourceName: "examplecloud_resource.test", ImportState: true, ImportStateId: "test-resource-id", ImportStateVerify: true, ImportStateVerifyIgnore: []string{"password"}, } ``` -------------------------------- ### Expect Null Output Value At Path Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/plan-checks.md Use this to assert that a nested output value is null in the plan. It requires the output name and the attribute path within the output. ```go func ExpectNullOutputValueAtPath(name, path string) PlanCheck ``` -------------------------------- ### Expect Unknown Output Value At Path Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/plan-checks.md Use this to assert that a nested output value is unknown in the plan. It requires the output name and the attribute path within the output. ```go func ExpectUnknownOutputValueAtPath(name, path string) PlanCheck ``` -------------------------------- ### Expect Known Output Value Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/plan-checks.md Use this to assert that a root-level output has a specific known value in the plan. It requires the output name and a known value check. ```go plancheck.ExpectKnownOutputValue("instance_id", knownvalue.StringExact("i-1234567890abcdef0")) ``` -------------------------------- ### StaticFile Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/configuration.md Returns a function that always returns the supplied file path. This is useful for setting a fixed configuration file or directory for all test steps. ```APIDOC ## func StaticFile(file string) TestStepConfigFunc ### Description Returns a function that always returns the supplied file path. ### Parameters #### Path Parameters - **file** (string) - Required - File path to use for all steps ### Returns - **TestStepConfigFunc** - Function returning the static file path ### Example Usage ```go resource.TestStep{ ConfigFile: config.StaticFile("testdata/resource.tf"), } resource.TestStep{ ConfigDirectory: config.StaticFile("testdata/resources"), } ``` ``` -------------------------------- ### All Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/terraform-version-checks.md Combines multiple version checks such that all must pass. Returns all errors or skip messages if any check fails. ```APIDOC ## All ### Description Combines multiple version checks such that all must pass (all errors or skip messages are returned). ### Function Signature ```go func All(checks ...TerraformVersionCheck) TerraformVersionCheck ``` ### Parameters #### `checks` - Type: `...TerraformVersionCheck` - Description: Variable number of version checks. ### Returns - Type: `TerraformVersionCheck` - Description: Combined version check. ### Example Usage ```go tfversion.All( tfversion.RequireAbove(version.Must(version.NewVersion("0.15.0"))), tfversion.SkipAbove(version.Must(version.NewVersion("1.4.0"))), ) ``` ``` -------------------------------- ### Configuration Management Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/INDEX.md Functions for managing test configuration files and directories. ```APIDOC ## Configuration Management ### Description Functions to manage test configuration files and directories, including static and relative paths. ### Static Configuration - `StaticFile()`: Uses a configuration file from a fixed path. - `StaticDirectory()`: Uses a configuration directory from a fixed path. ### Test-Relative Configuration - `TestNameFile()`: Uses a configuration file relative to the test name. - `TestNameDirectory()`: Uses a configuration directory relative to the test name. ### Step-Relative Configuration - `TestStepFile()`: Uses a configuration file relative to the current test step. - `TestStepDirectory()`: Uses a configuration directory relative to the current test step. ### Variables - `Variables`: Handles automatic generation of `.auto.tfvars.json` files for passing variables. ### Recommended Structure - Provides guidance on organizing project structure for optimal configuration management. ``` -------------------------------- ### Test Name Based Directory Configuration Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/configuration.md Use TestNameDirectory to organize configurations based on the test name. This function creates paths like testdata//, aiding in isolating configurations for different tests. ```go func TestNameDirectory(directory string) func(TestStepConfigRequest) string { return func(req TestStepConfigRequest) string { return filepath.Join("testdata", req.TestName, directory) } } ``` ```go resource.TestStep{ ConfigDirectory: config.TestNameDirectory("resources"), // Looks for: testdata/TestExampleCloudThing_basic/resources/ } ``` -------------------------------- ### TestNameFile Function for Test-Specific Configuration Paths Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/configuration.md Generates file paths relative to the test name. The path format is `testdata//`. Use this to organize configurations per test case. ```go func TestNameFile(file string) func(TestStepConfigRequest) string ``` ```go resource.TestStep{ ConfigFile: config.TestNameFile("test.tf"), // Looks for: testdata/TestExampleCloudThing_basic/test.tf } resource.TestStep{ ConfigFile: config.TestNameFile("main.tf"), // Looks for: testdata/TestExampleCloudThing_basic/main.tf } ``` -------------------------------- ### Check Module Resource Attribute is Not Set Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/checking-functions.md Confirms that a specific attribute of a resource within a module is not set or does not exist. This is useful for verifying that certain configurations are not applied. ```go func TestCheckModuleNoResourceAttr(mp []string, name, key string) TestCheckFunc ``` -------------------------------- ### Define TestCase Struct Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/testing-case-and-step.md Defines the structure for a complete acceptance test scenario, including pre-checks, provider factories, and test steps. ```go type TestCase struct { IsUnitTest bool PreCheck func() TerraformVersionChecks []tfversion.TerraformVersionCheck ProviderFactories map[string]func() (*schema.Provider, error) ProtoV5ProviderFactories map[string]func() (tfprotov5.ProviderServer, error) ProtoV6ProviderFactories map[string]func() (tfprotov6.ProviderServer, error) Providers map[string]*schema.Provider ExternalProviders map[string]ExternalProvider PreventPostDestroyRefresh bool CheckDestroy TestCheckFunc ErrorCheck ErrorCheckFunc Steps []TestStep IDRefreshName string IDRefreshIgnore []string WorkingDir string AdditionalCLIOptions *AdditionalCLIOptions } ``` -------------------------------- ### Check Output Value Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/checking-functions.md Use this function to assert that a root-level output value exactly matches a specific string. Provide the output name and the expected string value. ```go func TestCheckOutput(name, value string) TestCheckFunc ``` ```go resource.TestCheckOutput("resource_id", "test-resource-123") ``` -------------------------------- ### Check Module Resource Attribute Value Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/checking-functions.md Verifies that a specific attribute of a resource within a module has an expected string value. Specify the module path, resource address, attribute key, and the expected value. ```go func TestCheckModuleResourceAttr(mp []string, name, key, value string) TestCheckFunc ``` ```go resource.TestCheckModuleResourceAttr( []string{"module", "child"}, "examplecloud_resource.test", "name", "example", ) ``` -------------------------------- ### Check Module Resource Attribute Pair Comparison Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/checking-functions.md Compares an attribute from a resource in one module against an attribute from a resource in another module. This is useful for verifying relationships or consistency between different parts of a modular configuration. ```go func TestCheckModuleResourceAttrPair(mpFirst []string, nameFirst, keyFirst string, mpSecond []string, nameSecond, keySecond string) TestCheckFunc ``` -------------------------------- ### Exact Map Size Check Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/known-values.md Use `knownvalue.MapSizeExact()` to verify that a map has a precise number of keys. This is important when the cardinality of a map is a strict requirement. ```go func MapSizeExact(size int) Check ``` -------------------------------- ### Predefined Terraform Version Constants Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/terraform-version-checks.md Available constants for common Terraform versions. Use these for shorthand in version checks. ```go // Standard versions Version1_0_0 *version.Version Version1_1_0 *version.Version Version1_2_0 *version.Version Version1_3_0 *version.Version Version1_4_0 *version.Version Version1_5_0 *version.Version // ... and more ``` -------------------------------- ### Expect Deferred Change Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/plan-checks.md Use this function to assert that a specific resource change is expected to be deferred during the plan. Requires the resource address and the expected deferral reason. ```go func ExpectDeferredChange(resourceAddress string, reason DeferredReason) PlanCheck ``` ```go plancheck.ExpectDeferredChange("examplecloud_resource.test", plancheck.DeferredReasonResourceConfigUnknown) ``` -------------------------------- ### Import TestStep Configuration Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/import-state-testing.md Configuration for a Terraform test step to perform resource import and verification. ```APIDOC ## Import with Command ### Description Defines a test step for importing a resource and verifying its state. ### Fields | Field | Type | Description | |-------|------|-------------| | `ResourceName` | string | Resource address to import (required for import) | | `ImportState` | bool | Enable import testing | | `ImportStateId` | string | Resource ID for `terraform import` command | | `ImportStateIdFunc` | ImportStateIdFunc | Function to generate import ID dynamically | | `ImportStateVerify` | bool | Verify imported state matches resource definition (default: true) | | `ImportStateVerifyIgnore` | []string | Attributes to ignore during verification | | `ImportStateVerifyCount` | int | Number of resources to verify (if unset, verifies all) | | `ImportStateCheck` | ImportStateCheckFunc | Custom function to verify imported state | | `ImportStateConfigExact` | bool | Whether to use exact config without framework modifications | ### Request Example ```go resource.TestStep{ ResourceName: "examplecloud_resource.test", ImportState: true, ImportStateId: "resource-123", ImportStateVerify: true, ImportStateVerifyIgnore: []string{"password", "api_key"}, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet("examplecloud_resource.test", "id"), ), } ``` ``` -------------------------------- ### config Directory Functions Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/exported-functions.md Functions for handling configuration directories within tests. ```APIDOC ## config Directory Functions ### `StaticDirectory(directory string)` Always returns the same directory. ### `TestNameDirectory(directory string)` Returns a test-relative directory. ### `TestStepDirectory(directory string)` Returns a step-relative directory. ``` -------------------------------- ### Expect Known Output Value At Path Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/plan-checks.md Use this to assert that a nested output value has a specific known value in the plan. It requires the output name, the attribute path within the output, and a known value check. ```go func ExpectKnownOutputValueAtPath(name, path string, value knownvalue.Check) PlanCheck ``` -------------------------------- ### Exact List Size Check Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/known-values.md Use `knownvalue.ListSizeExact()` to assert that a list has a specific number of elements. This is helpful when the exact count of items in a list is critical. ```go func ListSizeExact(size int) Check ``` -------------------------------- ### Check Module Resource Attribute is Set Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/checking-functions.md Ensures that a specified attribute of a resource within a module is present and has a value. Use this when the exact value is not important, only its existence. ```go func TestCheckModuleResourceAttrSet(mp []string, name, key string) TestCheckFunc ``` -------------------------------- ### Specify Terraform Binary Path Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/environment-variables.md Use TF_ACC_TERRAFORM_PATH to explicitly set the path to the Terraform executable for acceptance tests. This takes precedence over the Terraform found in the system's PATH. ```bash TF_ACC_TERRAFORM_PATH=/opt/terraform/1.5.0/terraform go test -v ``` ```bash TF_ACC_TERRAFORM_PATH=$(which terraform) go test -v ``` -------------------------------- ### Combine All Terraform Version Checks Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/terraform-version-checks.md Use `All` to combine multiple version checks. All provided checks must pass for the combined check to succeed. This is useful for enforcing a strict set of version requirements. ```go func All(checks ...TerraformVersionCheck) TerraformVersionCheck ``` ```go tfversion.All( tfversion.RequireAbove(version.Must(version.NewVersion("0.15.0"))), tfversion.SkipAbove(version.Must(version.NewVersion("1.4.0"))), ) ``` -------------------------------- ### Helper Utilities Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/INDEX.md A collection of utility functions for common testing tasks like retries and ID generation. ```APIDOC ## Helper Utilities ### Description A collection of utility functions to assist with common testing operations. ### Retry Functions - `Retry()`: Retries a function execution. - `RetryContext()`: Retries a function execution with context. - `RetryableError()`: Defines an error that can be retried. - `NonRetryableError()`: Defines an error that should not be retried. ### ID Generation - `UniqueId()`: Generates a unique identifier. - `PrefixedUniqueId()`: Generates a unique identifier with a prefix. ### State Polling - `StateChangeConf`: Configuration for polling state changes. - `StateRefreshFunc`: Function to refresh state. ### Error Types - `NotFoundError`: Represents a not found error. - `UnexpectedStateError`: Represents an unexpected state error. - `TimeoutError`: Represents a timeout error. ``` -------------------------------- ### config File Functions Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/exported-functions.md Functions for handling configuration files within tests. ```APIDOC ## config File Functions ### `StaticFile(file string)` Always returns the same file. ### `TestNameFile(file string)` Returns a test-relative file. ### `TestStepFile(file string)` Returns a step-relative file. ``` -------------------------------- ### Persist Test Working Directory Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/environment-variables.md Enable TF_ACC_PERSIST_WORKING_DIR by setting it to any value (conventionally "1") to prevent the temporary working directory from being cleaned up after test completion. Useful for debugging. ```bash # Keep working directory for debugging TF_ACC_PERSIST_WORKING_DIR=1 TF_ACC=1 go test -v ``` -------------------------------- ### Match Output with Regex Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/checking-functions.md Use this function to validate that a root-level output value matches a given regular expression pattern. It requires the output name and a compiled regular expression object. ```go func TestMatchOutput(name string, r *regexp.Regexp) TestCheckFunc ``` ```go resource.TestMatchOutput("endpoint", regexp.MustCompile(`https://.*\.example\.com`)) ``` -------------------------------- ### TestStepFile Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/api-reference/configuration.md Returns a function that generates file paths using the test name, step number, and a supplied file. The path is constructed as `testdata///`. ```APIDOC ## func TestStepFile(file string) TestStepConfigFunc ### Description Returns a function that generates file paths using test name, step number, and supplied file. Path is `testdata///`. ### Parameters #### Path Parameters - **file** (string) - Required - Filename within step directory ### Returns - **TestStepConfigFunc** - Function generating step-relative paths ### Example Usage For test `TestExampleCloudThing_basic` with 2 steps: ```go resource.TestCase{ Steps: []resource.TestStep{ { ConfigFile: config.TestStepFile("test.tf"), // Looks for: testdata/TestExampleCloudThing_basic/1/test.tf }, { ConfigFile: config.TestStepFile("test.tf"), // Looks for: testdata/TestExampleCloudThing_basic/2/test.tf }, }, } ``` File structure: ``` testdata/ TestExampleCloudThing_basic/ 1/ test.tf 2/ test.tf ``` ``` -------------------------------- ### Provider Factories for SDKv2 Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/README.md Use this map to define provider factories when integrating with SDKv2. It maps provider names to functions that return a schema.Provider. ```go providerFactories := map[string]func() (*schema.Provider, error){ "examplecloud": func() (*schema.Provider, error) { return provider.New(), nil }, } ``` -------------------------------- ### State Check Interfaces Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/INDEX.md Interfaces for verifying the state of resources and outputs after apply. ```APIDOC ## State Check Interfaces ### Description Provides interfaces for verifying the state of resources and outputs after a Terraform apply. ### Identity Checks - `ExpectIdentity()`: Checks the identity of a resource. - `ExpectIdentityValue()`: Checks the identity value of a resource attribute. ### Attribute Checks - `ExpectKnownValue()`: Asserts that a resource attribute has a known value. - `ExpectSensitiveValue()`: Asserts that a resource attribute is sensitive. ### Output Checks - `ExpectKnownOutputValue()`: Asserts that an output has a known value. - `ExpectKnownOutputValueAtPath()`: Asserts that an output has a known value at a specific path. ### Comparison Checks - `ExpectIdentityValueMatches()`: Checks if a resource attribute's identity value matches a given value. - `ExpectIdentityValueMatchesAtPath()`: Checks if a resource attribute's identity value at a specific path matches a given value. ``` -------------------------------- ### TestCase Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/types.md Defines an acceptance test scenario with configuration, providers, and test steps. It allows for detailed configuration of test execution, including version checks, provider factories, and custom verification functions. ```APIDOC ## TestCase ### Description Defines an acceptance test scenario with configuration, providers, and test steps. ### Fields - **IsUnitTest** (bool) - Run regardless of TF_ACC - **PreCheck** (func()) - Pre-test validation - **TerraformVersionChecks** ([]tfversion.TerraformVersionCheck) - Version requirements - **ProviderFactories** (map[string]func() (*schema.Provider, error)) - SDKv2 providers - **ProtoV5ProviderFactories** (map[string]func() (tfprotov5.ProviderServer, error)) - Protocol v5 providers - **ProtoV6ProviderFactories** (map[string]func() (tfprotov6.ProviderServer, error)) - Protocol v6 providers - **Providers** (map[string]*schema.Provider) - **Deprecated**: Direct providers - **ExternalProviders** (map[string]ExternalProvider) - Registry-downloaded providers - **PreventPostDestroyRefresh** (bool) - Skip post-destroy refresh - **CheckDestroy** (TestCheckFunc) - Post-destroy verification - **ErrorCheck** (ErrorCheckFunc) - Custom error handling - **Steps** ([]TestStep) - Test steps (required) - **IDRefreshName** (string) - Resource for ID-only refresh - **IDRefreshIgnore** ([]string) - Attributes to ignore in refresh - **WorkingDir** (string) - Base directory for test files - **AdditionalCLIOptions** (*AdditionalCLIOptions) - CLI options ``` -------------------------------- ### Run Sweepers Source: https://github.com/hashicorp/terraform-plugin-testing/blob/main/_autodocs/README.md Execute sweepers to clean up resources by specifying the cloud provider region and the resource to run. ```bash # Run sweepers go test -sweep=us-east-1 -sweep-run=examplecloud_resource ```