-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Acceptance testing: Ability to prevent a resource being deleted at the end of a TestCase
#85
Comments
Implementation ProposalsThis implementation should likely reach out to the I would also recommend that this implementation accept a list of resource addresses, similar to the Given the current setup of the testing framework, which is struct type-based, I would encourage we follow the existing pattern of adding fields rather than introduce a separate code paradigm for this feature. In a future major version of the testing framework, we can remove the slippery slope of forever expanding State Removal TestCase FieldProvider implementation example: resource.TestCase{
// ... other fields ...
Steps: []resource.TestStep{/* ... */},
RemoveStateBeforeDestroy: []string{/* resource address strings */},
} The testing framework would inspect this State Removal TestStep Field and "Type"Provider implementation example: resource.TestCase{
// ... other fields ...
Steps: []resource.TestStep{
// ... other steps ...
{
RemoveState: []string{/* resource address strings */},
},
// ... potentially other steps ...
}
} The testing framework would execute state removal commands at the time of encountering this type of This In this scenario, the following validation should be performed:
State Removal on Destroy TestStep FieldProvider implementation example: resource.TestCase{
// ... other fields ...
Steps: []resource.TestStep{
// ... potentially other steps ...
{
Config: "...",
RemoveStateOnDestroy: []string{/* resource address strings */},
},
// ... potentially other steps ...
}
} This would combine ideas from the first two proposals, but make it so the testing framework caches the state removals so they are always executed on before destroy, even on step failures. This may be difficult for provider developers to reason about though, similar to the Generic Terraform Command TestStep FieldProvider implementation example: resource.TestCase{
// ... other fields ...
Steps: []resource.TestStep{
// ... other steps ...
{
RunCommand: func(ctx context.Context, tf *tfexec.Terraform) error {
return tf.StateRm(ctx, "resource address")
},
},
// ... potentially other steps ...
}
} Another option would be to take the
Providing a limited interface to |
With the introduction of the terraform-plugin-testing module (migration guide), we are transferring feature requests relating to the |
hey guys 👋 I have one recent use-case with testing resource logic, which requires to import existing resource to the acc test flow, then I'm trying to modify it and checking the error message. Due to backend logic I can't create such resource type directly from terraform, but as this resources existing in the system, potentially user may be able to import this resource to the terraform and then try to modify it. Please take a look at this test https://github.com/Twingate/terraform-provider-twingate/pull/286/files#diff-520bbd3087681ff4b701d292654e17eb48c163fd43a3cf1f87994fcef3614817 |
Bubbling up this info from the recent closed PR:
|
Hi folks 👋 To close the loop here, Terraform 1.7 and later do include the ability to unmanage resources via the As a quick example: []resource.TestStep{
{
Config: `
resource "examplecloud_thing" "test" {}
`,
},
// ... potentially other TestStep ...
{
Config: `
removed {
from = examplecloud_thing.test
lifecycle {
destroy = false
}
}
`,
},
} This will remove the state for the resource, meaning that the implicit destroy ran at the end of the test steps will no longer try to destroy that resource. If you have your acceptance testing setup to run across many Terraform versions, there is support for Terraform version checks, such as Hope this helps! |
SDK version
Use-cases
Acceptance tests for hashicorp/terraform-provider-aws#26274 need to manipulate an active AWS Direct Connect connection. Activating a newly created Direct Connect connection requires manual intervention at a physical location, so creating the
aws_dx_connection
and waiting for it to become active in aTestStep
is not feasible.Using the
TestStep.ImportStatePersist
flag with an existing active connection enables the manipulation of that connection to be tested via the acceptance testing framework, but at the end of theTestCase
all resources in the Terraform state created during the test are destroyed and destroying the active connection is not at all desirable given the overhead in getting the connection into the active state.Attempted Solutions
Each
TestStep.Check
function is passed a*terraform.State
object, so I tried deleting the resource from this object. However this in-memory state is never persisted and is local to each individualTestStep
.Proposal
Add a new
TestStep
field that indicates to the acceptance testing framework that a resource (or list of resources) is not to be deleted at the end of theTestCase
.References
Upstream Terraform CLI issue for configuration language support of a similar facility: hashicorp/terraform#3874.
The text was updated successfully, but these errors were encountered: