Skip to content

terraform test: support failure assertions for lifecycle errors #37960

@edgetools

Description

@edgetools

Terraform Version

> terraform version
Terraform v1.14.0
on darwin_arm64

Use Cases

Currently, terraform test supports assertions for failure conditions using expect_failures.

However, as indicated by the documentation and other similar issues, this feature is only used to test custom conditions.

I have a use case where I am attempting to do opaque-box testing using terraform, meaning I am running a module and then using a "loader" module to verify the output (similar to how the docs describe).

Yet one of the core requirements of my implementation is that prevent_destroy is used to alleviate a deletion risk associated with a specific provider.

Currently, I cannot use expect_failures to assert on a test that attempts to destroy a resource being blocked by terraform.

This is a problem because my tests are designed to maintain the contracts of the terraform module. While I am not worried about terraform itself having a bug in the prevent_destroy feature, I am worried about other contributors to the module I'm using accidentally removing the prevent_destroy lifecycle block, leading to a deletion risk.

Attempted Solutions

Attempted to use expect_failures, but it only works with custom conditions.

Proposal

I propose that the expect_failures feature is either enhanced, or an additional failure assertion is added, which allows for asserting on lifecycle failures or errors generated during a terraform run.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions