-
Notifications
You must be signed in to change notification settings - Fork 232
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
Allow running Check tests on imported resources #717
Comments
Thanks so much for filing this, @greentruff and this is a great idea! Apologies for the long delay in responding. I believe our preference here would be something as you mention in your proposal, a new resource.TestCase{
// ... other fields omitted for brevity ...
Steps: []resource.TestStep{
// Importing TestStep
{
ImportState: true,
ImportStateId: /* required if first TestStep */,
ImportStateVerify: true,
Config: /* required if first TestStep */,
ImportStatePersist: true, // <-- New flag to trigger "keeping" the imported state
},
// Checking TestStep
{
Config: /* ... */,
Check: /* ... */,
},
},
} Naming suggestions are welcome, but I think aligning with the other One detail we do need to capture in provider defined implementations is that if there is no prior state, then the Thanks again! |
Hi @bflad! Can confirm a solution like this would also be beneficial for our use case in |
…unNewTest and when called at this point will overwrite the contents of the .terraform directory with the current version of the provider (#717)
…'re not persisting the state generated by the import (#717)
…port test works when ImportStatePersist is false (#717)
#1052) * Use ImportStatePersist to preserve state generated by import operation (#717) * Removing additional call to Init as this has already been called in runNewTest and when called at this point will overwrite the contents of the .terraform directory with the current version of the provider (#717) * Adding CHANGELOG entry (#717) * Adding test coverage (#717) * Linting (#717) * Appears that init needs to be run within testStepNewImportState if we're not persisting the state generated by the import (#717) * Fixing test and adding a couple of additional tests to verify that import test works when ImportStatePersist is false (#717) * Linting (#717)
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
I checked 2.4.4 and the behavior for imported tests is identical, state is not modified.
Use-cases
The terraform plugin for datadog supports modifying certain properties of default rules. Default rules cannot be created by users and are instead a special resource which must be imported before being modified. See documentation the documentation here.
Implementation of the resource is here
We would like to implement tests which check that the fields are being modified correctly.
Attempted Solutions
The existing tests misused the test framework and use both
ImportState: True
andCheck
. TheCheck
s are ignored in this case, testing withImportStateCheck
the state is right after import and does not take into account other changes on top of it. It is also not possible to split the check into multiple steps asImportState
will revert back to the previous state after an import step.Proposal
Add a flag to keep state after an import step such as
ImportPersistState: True
which returns the updated state so that following steps can modify it.References
The text was updated successfully, but these errors were encountered: