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
Terraform test execution doesn't handle prevent_destroy=true
#34960
Comments
Hi @daveS2, thanks for filing this. The Potentially, you could introduce a variable into your module that defaults to true and you can override it within your tests?
I appreciate changing the configuration to support the tests isn't always the best solution, but it might work for you here? |
Thank you for your response, this would work, but I am not sure you can pass a variable into a lifecycle block? resource "google_kms_crypto_key" "key" {
name = "resource-name"
key_ring = "keyring"
rotation_period = "10000000s"
lifecycle {
prevent_destroy = var.prevent_destroy
}
}
variable "prevent_destroy" {
default = true
} And then run │ Error: Variables not allowed
│
│ on demo.tf line 11, in resource "google_kms_crypto_key" "key":
│ 11: prevent_destroy = var.prevent_destroy
│
│ Variables may not be used here.
╵
╷
│ Error: Unsuitable value type
│
│ on demo.tf line 11, in resource "google_kms_crypto_key" "key":
│ 11: prevent_destroy = var.prevent_destroy
│
│ Unsuitable value: value must be known |
Apologies, I didn't know that you couldn't use variables for this. Unfortunately, I can't think of a way to handle this within the current capabilities of the testing framework. I'll retag this as an enhancement request. I'm not sure the best way to handle this currently. Potentially, we could make the testing framework ignore the Sorry for the missing functionality! |
prevent_destroy=true
and override appears to not workprevent_destroy=true
Terraform Version
Terraform Configuration Files
Terraform conifg:
tftest.hcl file:
Debug Output
https://gist.github.com/daveS2/fd251cc2cb61af3c8df0f3966aadd253
Expected Behavior
The prevent destroy should be handled by either expect failures:
Which doesn't work or it should overridable:
Actual Behavior
The tests always fail
Steps to Reproduce
Additional Context
For resources where we want destroy protection, terraform mocks always attempt to destroy but we cannot capture the error thrown or override the value
References
No response
The text was updated successfully, but these errors were encountered: