-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Open
Labels
Description
Terraform Version
Terraform v1.7.3Use Cases
Hello,
We would like to expect_failure from a local module call done in a run block with terraform test. You can find some context about our issue down below.
The issue
It seems that resources, when placed inside a local module, are not handled by the expect_failures of the run block. Either we missed something and that is possible, either that would be a nice thing to have to be able to test our module with the integration of its own local modules.
The terraform test output
run "check_precondition_ssm_parameter_encryption"... fail
╷
│ Error: Invalid `expect_failures` reference
│
│ on tests/main.tftest.hcl line 22, in run "check_precondition_ssm_parameter_encryption":
│ 22: module.workshop_participant_users.aws_ssm_parameter.example,
│
│ You cannot expect failures from module.workshop_participant_users.aws_ssm_parameter. You can only expect failures from checkable objects such as input variables, output values,
│ check blocks, managed resources and data sources.Files content
# file : tests/main.tftest.hcl
run "check_precondition_ssm_parameter_encryption" {
command = plan
# [...]
expect_failures = [
module.workshop_participant_users.aws_ssm_parameter.example,
]
}# file : main.tf
module "workshop_users" {
source = "./modules/users"
kms_key_id = var.create_kms_key ? try(resource.aws_kms_key.backend[0].arn, "") : ""
}
# file : modules/users/main.tf
resource "aws_ssm_parameter" "example" {
# [...]
key_id = var.kms_key_id
lifecycle {
precondition {
condition = var.kms_key_id != ""
error_message = "A key must be created to encrypt the ssm parameter."
}
}
}Any ideas on that ?
Attempted Solutions
We have tried with the expecting failure on the whole module scope as well as for other resources inside the local module.
Proposal
No response
References
We are not sure whether or not it is also the case for the registry modules as well as the local ones tested here.
Manuelraa, fpaterour-ippon, chris-peterson and cpaloia