Skip to content
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

Consider introducing statecheck support for Import test mode #365

Open
austinvalle opened this issue Aug 8, 2024 · 0 comments
Open

Consider introducing statecheck support for Import test mode #365

austinvalle opened this issue Aug 8, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@austinvalle
Copy link
Member

terraform-plugin-testing version

v1.9.0

Use cases

terraform-plugin-testing currently supports a new method of asserting values in Terraform state during Config mode with the statecheck package and the (TestStep).ConfigStateChecks field.

The Import mode for testing also has the (TestStep).ImportStateCheck field for performing state checks after, see:

if step.ImportStateCheck != nil {
logging.HelperResourceTrace(ctx, "Using TestStep ImportStateCheck")
var states []*terraform.InstanceState
for address, r := range importState.RootModule().Resources {
if strings.HasPrefix(address, "data.") {
continue
}
if r.Primary == nil {
continue
}
is := r.Primary.DeepCopy() //nolint:staticcheck // legacy usage
is.Ephemeral.Type = r.Type // otherwise the check function cannot see the type
states = append(states, is)
}
logging.HelperResourceDebug(ctx, "Calling TestStep ImportStateCheck")
if err := step.ImportStateCheck(states); err != nil {
t.Fatal(err)
}
logging.HelperResourceDebug(ctx, "Called TestStep ImportStateCheck")
}

Proposal

We could introduce a similar state check implementation to ConfigStateChecks, with a new field (TestStep).ImportStateChecks. This implementation should be equivalent to the Config mode, since they both use terraform show to grab the JSON state representation.

We could also consider adjusting these tests and our documentation to use the import block, where we would then switch to using the plancheck package for checking values.

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant