My code is as below, how can I only rm state instead of destroy resource, so I can import this resource again.
func TestAccProject_importBasic(t *testing.T) {
resourceName := "lxd_project.project0"
resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccProject_basic("project0"),
},
{
ResourceName: resourceName,
ImportStateId: "project0",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIdentifierAttribute: "name",
},
},
})
}
bflad
May 30, 2024, 8:31pm
2
Hi @shufanhao Thank you for raising this topic.
While the acceptance testing library could introduce a specific enhancement for this type of behavior (e.g. Acceptance testing: Ability to prevent a resource being deleted at the end of a `TestCase` · Issue #85 · hashicorp/terraform-plugin-testing · GitHub ), any testing can immediately utilize any available Terraform configuration capabilities. In this case, Terraform 1.7 and later support the removed
configuration block for this purpose, rather than the previously required running of the terraform state rm
command.
In your case, you should be able to add a final TestStep
with a Config
that does not include the resource
block of the resource you wish to preserve, but does include the removed
block with destroy = false
for that resource instead.
Please give that a try and let us know if that does not work as expected.
system
Closed
November 26, 2024, 8:31pm
3
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.