terraform-plugin-sdk
terraform-plugin-sdk copied to clipboard
SDK 2.1.0 does not taint resource between TestSteps using TestStep.Taint
SDK version
2.1.0
Relevant provider source code
Main point here is Taint in Steps 2 and 3
Steps: []resource.TestStep{
// Step 1
resource.TestStep{
Config: configTextVM,
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckVcdVAppVmExists(netVappName, netVmName1, "vcd_vapp_vm.test-vm", &vapp, &vm),
resource.TestCheckResourceAttr("vcd_vapp_vm.test-vm", "name", netVmName1),
resource.TestCheckResourceAttr("vcd_vapp_vm.test-vm", "network.#", "0"),
....
),
},
// Step 2 - join org domain must fail
resource.TestStep{
Taint: []string{"vcd_vapp_vm.test-vm"},
Config: configTextVMStep1,
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckVcdVAppVmExists(netVappName, netVmName1, "vcd_vapp_vm.test-vm", &vapp, &vm),
resource.TestCheckResourceAttr("vcd_vapp_vm.test-vm", "name", netVmName1),
resource.TestCheckResourceAttr("vcd_vapp_vm.test-vm", "network.#", "0"),
...
),
},
// Step 3 - join org domain enabled
resource.TestStep{
Taint: []string{"vcd_vapp_vm.test-vm"},
Config: configTextVMStep2,
// Our testing suite does not have Windows OS to actually try domain join so the point of this test is
// to prove that values are actually set and try to be applied on vCD.
ExpectError: regexp.MustCompile(`Join Domain is not supported for OS type .*`),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckVcdVAppVmExists(netVappName, netVmName1, "vcd_vapp_vm.test-vm", &vapp, &vm),
resource.TestCheckResourceAttr("vcd_vapp_vm.test-vm", "name", netVmName1),
resource.TestCheckResourceAttr("vcd_vapp_vm.test-vm", "network.#", "0"),
...
),
},
Terraform Configuration Files
NO HCL because it is an issue in testing framework and not bound to specific HCL
Debug Output
Single line in log does log that resource will be tainted. 2020/10/27 18:13:27 [WARN] Test: Explicitly tainting resource "vcd_vapp_vm.test-vm"
Expected Behavior
Resource should have been re-created between Step 1, Step 2 and Step 3 (because Step 2 and 3 have Taint defined)
Actual Behavior
The resource was not recreated between steps and instead "update" happened in Steps 2 and 3
Steps to Reproduce
This is not related to particular provider
TF_ACC=1 go test -v .
References
Some quick research into this, it appears that the underlying logic behind Taint was never migrated to call the terraform taint command via terraform-exec when the rest of the testing framework was migrated to actual Terraform commands. This can be rectified by passing the terraform-exec bits into the testStepTaint() function in helper/resource/testing_config.go and replacing the rs.Taint() line with a (*tfexec.Terraform).Taint() call:
https://github.com/hashicorp/terraform-plugin-sdk/blob/2f7133b9729bf59bd8a59e006f15e4f845556284/helper/resource/testing_config.go#L29
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.