hashicorp / terraform

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
https://www.terraform.io
Other
42.8k stars 9.56k forks source link

Feature: more comprehensive assertions, such as resource recreation (or lack thereof) #34524

Open bgshacklett opened 10 months ago

bgshacklett commented 10 months ago

Terraform Version

zsh ❯ terraform version
Terraform v1.6.2
on darwin_arm64
+ provider registry.terraform.io/hashicorp/aws v5.31.0
+ provider registry.terraform.io/hashicorp/random v3.6.0

Use Cases

I'm currently updating an EBS module to supports snapshots being specified. I'd like to assert that the volume is recreated in such circumstances.

Attempted Solutions

I'm currently relying on asserting that the snapshot id is set and the knowledge that this value is immutable.

Proposal

Without getting into exact implementation details, in my particular use case, a lifecycle property might be helpful as part of the assertion toolkit. For example:

  assert {
    condition     = aws_ebs_volume.foo.lifecycle.requires_recreation == true
    error_message = "Expected EBS volume to be recreated"
  }

Alternatively, further types of assertion blocks could be used:

  assert_lifecycle {
    resource      = aws_ebs_volume.foo
    condition     = requires_recreation == true
    error_message = "Expected EBS volume to be recreated"
  }

References

No response

crw commented 10 months ago

Thanks for this feature request! If you are viewing this issue and would like to indicate your interest, please use the 👍 reaction on the issue description to upvote this issue. We also welcome additional use case descriptions. Thanks again!