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
ImportStateCheck func receives states other than the imported resource #1060
Comments
To help it stand out from the description above: I found this very similar issue (#531) that was closed in 2020. |
The tests I've experienced failures with have passed in the the automated tests on PRs in the terraform-provider-google repo (link to tests on the relevant PR here), which is interesting |
hey 👋 we are facing the same problem in our Terraform provider, please see: https://github.com/aiven/terraform-provider-aiven/actions/runs/3386997636/jobs/5627140403#step:6:60 there are, indeed, multiple states passed to the |
Hi @Serpentiel 👋 Can you confirm if this is only an issue when using Terraform 1.3 and later? |
Reference: #1060 The `TestStep` type `ImportStateCheck` functionality is for verifying two specific scenarios over `ImportStateVerify`: - Resources which create multiple resources during import (an implementation detail which is an legacy anti-pattern that should no longer be present in resources). - Resources where importing may cause attributes to have syntactically different but semantically/functionally equivalent values that requires special logic to check. Terraform 1.3 and later can include data source states when importing resources. Rather than forcing provider developers to account for this Terraform version-specific behavior, the `ImportStateCheck` logic will now only receive managed resource states to match the intended usage. Previously with Terraform 1.2.9 and earlier: ``` --- PASS: TestTest_TestStep_ImportStateCheck_SkipDataSourceState (1.58s) ``` Previously with Terraform 1.3.4: ``` --- FAIL: TestTest_TestStep_ImportStateCheck_SkipDataSourceState (0.63s) /Users/bflad/src/github.com/hashicorp/terraform-plugin-sdk/helper/resource/testing_new_import_state_test.go:16: expected 1 state, got: 2 ``` Now with Terraform 1.3.4: ``` --- PASS: TestTest_TestStep_ImportStateCheck_SkipDataSourceState (0.91s) ```
I have submitted #1089 which will strip data source states (seemingly present after import with Terraform 1.3 and later) from |
hey, thank you for your reply! 👋 I can confirm that this issue appeared in recent releases of the Terraform |
…ck (#1089) * helper/resource: Skip data source states with TestStep.ImportStateCheck Reference: #1060 The `TestStep` type `ImportStateCheck` functionality is for verifying two specific scenarios over `ImportStateVerify`: - Resources which create multiple resources during import (an implementation detail which is an legacy anti-pattern that should no longer be present in resources). - Resources where importing may cause attributes to have syntactically different but semantically/functionally equivalent values that requires special logic to check. Terraform 1.3 and later can include data source states when importing resources. Rather than forcing provider developers to account for this Terraform version-specific behavior, the `ImportStateCheck` logic will now only receive managed resource states to match the intended usage. Previously with Terraform 1.2.9 and earlier: ``` --- PASS: TestTest_TestStep_ImportStateCheck_SkipDataSourceState (1.58s) ``` Previously with Terraform 1.3.4: ``` --- FAIL: TestTest_TestStep_ImportStateCheck_SkipDataSourceState (0.63s) /Users/bflad/src/github.com/hashicorp/terraform-plugin-sdk/helper/resource/testing_new_import_state_test.go:16: expected 1 state, got: 2 ``` Now with Terraform 1.3.4: ``` --- PASS: TestTest_TestStep_ImportStateCheck_SkipDataSourceState (0.91s) ``` * Update CHANGELOG for #1089
Thanks for addressing this! In my case I must have been using a newer version of TF locally versus the version used in terraform-provider-google's automated tests. I'll revisit the affected tests and the possibility of using |
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. |
SDK version
Relevant provider source code
Terraform Configuration Files
Debug Output
Expected Behavior
As 1 resource is being imported I'd expect the argument passed to the
ImportStateCheck
func to contain state for thegoogle_privateca_certificate_template_iam_policy.foo
resource only. Instead, there is state for both thegoogle_privateca_certificate_template_iam_policy.foo
resource and data.google_iam_policy.foo data source.Actual Behavior
The test fails and in the output is:
The file line being referred to is here in the google provider.
👉 Click to expand and see the 2 items in the state array above
Steps to Reproduce
make testacc TEST=./google TESTARGS="-run=^TestAccComputeSubnetworkIamPolicyGenerated_withCondition$"
GOOGLE_PROJECT=<project ID>
GOOGLE_REGION=us-central1
GOOGLE_ZONE=us-central1-a
GOOGLE_CREDENTIALS=<path to a .json key file for a service account>
- this is the identity use by TerraformGOOGLE_SERVICE_ACCOUNT=<email of the service account above>
References
The text was updated successfully, but these errors were encountered: